fix: don't assume boundary exists during increment/decrement#18289
Merged
Conversation
Follow-up to #18273 (not merged yet hence no changeset here): We can run into a null-pointer when wanting to increment/decrement inside an effect root that is outside a the component tree. Similarly, if not using the component logic to unset context at the right time we gotta do it "manually" inside `save`.
Contributor
|
…-effect-root/main.svelte Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
|
Member
Rich-Harris
reviewed
May 26, 2026
Comment on lines
+162
to
+170
| // If there's a boundary, the surrounding system will call unset_context at the appropriate time | ||
| if (!active.b) { | ||
| // If this is the last in a chain of async operations, the context would stay around | ||
| // until the next async operation happens, which can result in weird/buggy behavior | ||
| // because other sync work might suddenly be associated with an async batch. | ||
| queue_micro_task(() => { | ||
| if (batch === current_batch) unset_context(); | ||
| }); | ||
| } |
Member
There was a problem hiding this comment.
pretty sure we need to always unset a microtask after restoring. will add a test to confirm this
Suggested change
| // If there's a boundary, the surrounding system will call unset_context at the appropriate time | |
| if (!active.b) { | |
| // If this is the last in a chain of async operations, the context would stay around | |
| // until the next async operation happens, which can result in weird/buggy behavior | |
| // because other sync work might suddenly be associated with an async batch. | |
| queue_micro_task(() => { | |
| if (batch === current_batch) unset_context(); | |
| }); | |
| } | |
| queue_micro_task(unset_context); |
dummdidumm
commented
May 26, 2026
This is the fix in #18289 (comment), but saves us creating a bunch of microtasks
Rich-Harris
approved these changes
May 26, 2026
Member
|
Oops, I wrote #18295 (comment) into the wrong PR. We need to revert this |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #18273 (not merged yet hence no changeset here): We can run into a null-pointer when wanting to increment/decrement inside an effect root that is outside a the component tree. Similarly, if not using the component logic to unset context at the right time we gotta do it "manually" inside
save.