Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key option is not correctly forwarded in builder.getAll #2973

Open
IqualityHerre opened this issue Feb 5, 2024 · 2 comments
Open

Key option is not correctly forwarded in builder.getAll #2973

IqualityHerre opened this issue Feb 5, 2024 · 2 comments

Comments

@IqualityHerre
Copy link

IqualityHerre commented Feb 5, 2024

Describe the bug
Here: https://github.com/BuilderIO/builder/blob/main/packages/core/src/builder.class.ts#L2736

The or operator || binds stronger than the tertiary operator ?.

The code seems to intended as:

options.key || (Builder.isBrowser ? `${modelName}:${hash(omit(options, 'initialContent', 'req', 'res'))}` : undefined),

However as || binds stronger it's actually

(options.key || Builder.isBrowser) ? `${modelName}:${hash(omit(options, 'initialContent', 'req', 'res'))}`  : undefined

Meaning that the options.key value is always ignored. Inside the browser the modelName followed by a hash is passed and outside the browser undefined is always passed (unless a key option is provided in which case it's still ignored but the modelName followed by a hash is used).

To Reproduce
Steps to reproduce the behavior:

  1. Call builder.getAll and provide a key option.
  2. Either via breakpoints, network inspection or any other method observe that the provided key value is not used and the modelname followed by a hash is used instead.

Expected behavior
If options.key is provided then it's used.

This explicitly causes issues when doing multiple requests on the same modelName where requests after the first return promises that never fulfill.

@mrkoreye
Copy link
Collaborator

mrkoreye commented Apr 9, 2024

@IqualityHerre thanks for the detailed report! We will let you know when we ship a fix for this one

@mrkoreye
Copy link
Collaborator

mrkoreye commented Apr 9, 2024

Permalink to code:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants