Reset current component after call to flush() #5077
Closed
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.
Fixes #4899
This is a version of #4909 that fixes fewer problems—it doesn't fix the behaviour of onMount or onAfterUpdate, but only fixes the bug that the current component is set in to some completely random component in (non-Svelte) event handlers and tasks.
Since this is a rather pressing issue for my library (the only workaround is really awful), and #4909 appears blocked waiting to fully understand the consequences, I figured I would make a PR that fixes the most pressing aspect of the bug while having fewer consequences. If there is worry about side-effects of #4909, this one could first be accepted into a bug-fix release to be potentially replaced with #4909 in a more major release.
The only place where this PR resets the current component is after
flush()
is called from aPromise.resolve().then(...)
inscheduler.ts
, so only when called from the microtask queue, not from other Svelte code. In seemingly every other location (eg. await_block.ts), Svelte is resetting the current component at the end of a microtask, so this seems like a clear oversight.Thank you so much for maintaining this great library! If there is anything I can do to help the process along, please don't hesitate to ask.