-
-
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
Conversation
🦋 Changeset detectedLatest commit: a8a5b70 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} |
|
@dummdidumm Ah, dang. Good catch. I'll add a sample to cover that and fix it up |
|
I just pushed the test with a fix, should hopefully be all good now (don't know if anyone of you wants to test this again on their own setup with my tweak) |
|
I'll try it out |
|
Ran it through my app where I caught some of the other nuances and all looks good! |
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.
Great work, thank you!
|
While it does fix the issue I reported, it seems to introduce a new one: If you play with the same REPL in this version and v5.41.1, you'll notice that the big logo is briefly mounted when moving from the Home route to the medium or small one. I add the links to REPL's: I can help with explanations on how the router works, if it helps. Thanks. |
|
Hello, @hmnd. First and foremost: Thank you for contributing a fix for this problem. You're the man. Second: Maybe you're correct, but it is baffling. You see, my router works with The router works like this:
The code is here: RouterEngine.svelte.ts. It is a rather small code snippet. At this point, the contents in the If Maybe this PR is not introducing this problem, as you're noticing it happening in previous versions, but this PR seems to be evidencing a problem: A value that is clearly not Let me know if I can be of assistance. |
|
Is Might be because of the breaking change introduced by the async stuff (implemented in #15844 5.36.0):
|
|
Hello, @PatrickG. Interesting. I don't know. I have had this code like this for some time. Maybe you're right and now with this "more correct" Svelte behavior the problem lies in the use of the "convenience bindable I'll push a minor version of the router and test. EDIT: Oh, but BTW, this is why the code uses |
|
@webJose can confirm the undefined didn't happen prior to 5.36 when the async stuff was introduced |
|
Thanks, @hmnd for double checking. You guys are solid. 👍 I'm about to roll a minor version that will use the router's derived data directly when rendering the children. Still, I think there's a bug here around |
Yes, IMO this breaking change needs to be reverted. There are other issues with it, like #16648 |
|
@PatrickG you mean the async change? Or this PR? |
|
The breaking change that the async stuff introduced. Not this PR |
|
@PatrickG your assertion was spot on: With @wjfe/n-savant v0.13.0 which I rolled just now, the problem goes away. I think we're 100% correct in saying that this is not a problem with this PR, and that the problem is around FYI, I had to force v0.13.0 in the REPL to test, so I leave a convenience link here of my REPL with the version forcefully stated: REPL |
|
Also just fyi @webJose v5.41.1 was released before this pr was merged, so it doesn't include these changes yet :) |
|
Trying to parse the last few comments but just to be clear: do we need to revert this, or is the mentioned bug unrelated? (FWIW I can't tell what's supposed to be happening in the repros in #16930 (comment), they seem to behave identically to me?). I'll block #16992 until we resolve this |
tl;drThis PR looks good. None of us seem to have a problem with it. The found evidence leads us to strongly believe that, at least in my example, Rich-sama! Hello! I'm never tired to cheerfully greet the creator of Svelte, which brought joy to front-end development. Kidding aside: This PR fixes #16775, a bug I reported about a weird behavior when using Being the ignorant that I am regarding Svelte internals, I reported this new behavior but @hmnd pointed out that Long story short, the code for my ... // ETC. Previous things not important here.
// Effect that synchronizes the params property with the calculated params.
$effect.pre(() => {
params = router.routeStatus[key]?.routeParams; // <---------- params is synched using $effect.pre
});
</script>
{#if (router.routeStatus[key]?.match ?? (!and && !path))}
{@render children?.(params, router.state, router.routeStatus)} // <!-- <-------- params is used to render children -->
{/if}Look at the second-to-last line: I rolled out v0.13.0 of my router exchanging ConclusionThe problem was not in this PR. As per the evidence, the problem is that since some version ago, |
|
great — thanks for the clarification! will cut the release |
Fixes #16850, fixes #16775, fixes #16795, fixes #16982
#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 testand lint the project withpnpm lint