-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: preserve dirty status of deferred effects #16487
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
Conversation
🦋 Changeset detectedLatest commit: 51f24a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
mini-cleanup post #16487 - we don't need to do the work of scheduling an effect that's already dirty which means it already scheduled its root effect to run
mini-cleanup post #16487 - we don't need to do the work of scheduling an effect that's already dirty which means it already scheduled its root effect to run
I'm going to post this here because, in decades of trying to break javascript and write the worst stuff ever, I have never, ever seen this error...
...and I suspect it's related to this issue/set of commits. I'm not saying Svelte is at all to blame. I'm just trying to debug what is probably really bad state management in our (my company's) code. It looks like stuff is being recursively spread into a function, until such time as the limit is reached. I can't share the code that causes this, but if you like I can try to come up with a minimal repro. LMK, and thanks for all your work! |
Sounds like a |
Ok, I'll check our code first for that. Thanks. |
Ironically, the part of #16482 that fixed the infinite loop bug in #16403 introduced an even worse infinite loop that made remote functions unusable. I have learned, for the 19th or so time, that it is absolutely not safe to
mark_reactions
when triggering a batch re-run.It turns out we (which in this case is the royal 'we') were doing something rather silly: we were queueing all leaf effects when traversing the tree, not just the
DIRTY
/MAYBE_DIRTY
ones. In the common case that's fine, because they get flushed immediately and they get filtered withis_dirty
, but if the effects are deferred (because async work is happening) then on the next run they are all markedDIRTY
and re-executed.This PR makes everything somewhat more efficient. Firstly, it only queues effects that are not
CLEAN
. (We can't use anis_dirty
check during traversal, because that can cause deriveds to be re-evaluated with inconsistent data.) Secondly, it notes whether they wereDIRTY
orMAYBE_DIRTY
at the time of deferral, and restores that status to prevent unnecessary re-runs ofMAYBE_DIRTY
effects.I wasn't able to whittle the remote functions infinite loop thing down to a test case, but I verified the fix locally which will have to do for now as it's 1am and I'm supposed to be demoing this stuff on YouTube tomorrow.
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint