Key option is not correctly forwarded in builder.getAll
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 1.2k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 17
Description
**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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at packages/core/src/builder.class.ts around line 2736 and trace builder.getAll's handling of the key option. Reproduce the call with a provided key, using breakpoints or network inspection, and verify that the provided key is forwarded and repeated requests for the same modelName can fulfill normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100