-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: guard contents updated before the guard itself #16930
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 140ee11 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 |
b16146d
to
ac85e4a
Compare
|
It seems like this fixes the issue described here - but only for its first occurrence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what the tests are supposed to test? Most (haven't checked all but the first 4 do) also pass on main, and some of them have if conditions that are never true.
I think we should reduce this only to the ones that pass with this PR but fail on main.
The tests I committed were falling (multi-nested was failing against that pr), but I didn't look too closely at the tests commit I cherry picked from the previous PR. I'll clean those up and take a stab at @PatrickG's issue today. |
It looks like sorting eager effects by depth does fix this issue, so that may be necessary after all. |
e901976
to
d8e7cbc
Compare
@dummdidumm all cleaned up. I've also switched to sorting the effects by depth to account for @PatrickG's repro in #16775 (see the |
It seems it still doesn't fix the main issue within #16775 though, hmm... |
It doesn't seem like sorting the effects by depth fixes the issue. Clicking the button three times still logs "one" - same as with the simple reverse. |
@PatrickG yeah, I noticed... I'll look into it further tomorrow! |
@dummdidumm to be honest, as much as I'd love to fix this myself, I'm kind of at a loss on how to retain the changes in #16631 while fixing all the issues it has introduced. I'm sadly not knowledgeable enough on Svelte's internals to figure this out. I think trying to sort the effects here is just fixing a symptom downstream of the issue rather than the issue itself, as visible by the playgrounds in #16775. But what I can tell is that #16631 introduced some really nasty side effects. It may be a good idea to either prioritize fixing it or revert it until a fix can be found. The couple of tests in this pr and the playground in #16775 are good ways to reproduce the bugs here. If there's any other way I could assist figuring this out, do let me know! |
d8e7cbc
to
dd48c59
Compare
Never mind! I think I've got it. Eager effects were still executing after being destroyed, in addition to executing out of order. |
dd48c59
to
140ee11
Compare
@PatrickG I believe I've now got the fix to your issue nailed down too. I've also ensured the guard-else-effect test based on your repl tests clicking multiple times so we don't get a false positive. |
Very nice 👍 |
Great job with the fix! We are struggling from a similar issue, but unfortunately not able to reporduce it so far. Hopefully that is it :) In our code this sometimes throws {#if someSnippet}
<div in:scale>
{@render someSnippet()}
</div>
{/if} |
Fixes #16850, #16775, possibly #16795
#16631 introduced a bug that results in the effects within guards being evaluated before the guards themselves. I believe iterating the effects in reverse fixes the issue without any further regressions. An alternative approach could be to actually sort effects by depth before updating, but I suspect that would have a greater performance penalty.
Although all tests pass, sorry if I'm missing something obvious! I've never touched the Svelte internals until now :).
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