Gotcha with ReactiveSet/Map iterators
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start at packages/map/src/index.ts lines 49-55 and compare the ReactiveSet/Map iterator methods with the linked SvelteSet and Map implementations. Use the StackBlitz reproduction to verify that calling values(), keys(), or items() without consuming the iterator registers tracking; done means changes trigger the asynchronous effect as intended.
Written by the indexing model from the issue text.
Description
Describe the bug
Using .keys(), .values() or .items() on a ReactiveSet or ReactiveMap is meant to track all keys/values for changes. However, if the iterators are not consumed, then no tracking is registered.
This comes up when trying to declare dependencies of an asynchronous effect beforehand.
createEffect(() => {
// Track set for changes
void set.values();
setTimeout(() => /* Use set contents... */);
});
Though the intention was to track the full content of the set, the above effect is not actually triggered by changes to the set.
The reason this happens is that the methods are implemented as generators like so:
The beginning of the method is not run until .next() is called for the first time.
I think the methods should not be generators themselves, rather just return super.values(). That would probably be more performant as well. SvelteSet & Map are implemented like this.
Happy to to write a PR if there is agreement.
Minimal Reproduction Link
https://stackblitz.com/edit/github-r2lfqdu4?file=src%2FApp.tsx
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 165
- Avg merge
- 12h 35m
- Merged PRs (30d)
- 14
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs-community/solid-primitives
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
solidjs-community/solid-primitives#1082 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
solidjs-community/solid-primitives#1059 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
solidjs-community/solid-primitives#1055 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
solidjs-community/solid-primitives#894 ·
Maintainers usually reply within 1 day
-
help wanted
Difficulty 3/5 1-2 days Newbie friendliness 48/100
solidjs-community/solid-primitives#806 · 1 comment · 2 reactions ·
Maintainers usually reply within 1 day
All issues in solidjs-community/solid-primitives
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
farion1231/cc-switch#8829 ·
Maintainers usually reply within 1 day
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutoverOpendoc-audit enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100