-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: legacy mode: use coarse reactivity in the block's expressions #16073
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: efb3b6a 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 |
|
Looks like I fixed everything. I didn't recreate this behavior - I'm sure it was a non-fixable bug. |
I was wondering about whether we could use the existing I like that approach because it gives us granular information about expressions — we can distinguish between whether an expression has state, a call, an assignment, or (on the A couple of tests are failing on that branch, but they relate to something that's also buggy on this branch. If you have something like this... <script>
let n = 0;
</script>
<p>n: {n}</p>
{#key n = 0}
<p>n = 0: {n = 0}</p>
{/key}
<p>n: {n}</p>
<button on:click={() => {
n += 1;
console.log({ n });
}}>increment</button> ...then you get a whole bunch of different behaviours: In 4, we execute everything top-down and clone context every time we enter a fragment, which means that the key block mutates a local copy of In 5, we end up not tracking In this PR and the other PR, we do track If we get rid of the <p>n: {n}</p>
<p>n = 0: {n = 0}</p>
<p>n: {n}</p> ...the behaviour of 4 stays the same, but this time the assignment expression gets caught up in a template effect where Which brings me to the failing test on #16100, which is one of the ones added here. The reality is that it's broken in both cases, because in both cases we're reassigning the actual value rather than a local copy (if you add a line to the So the question I'm trying to figure out is whether this discrepancy matters, and how far we should strive to be bug-compatible with Svelte 4. Even though 4 didn't prevent assignments-in-template, it's always been an extremely silly thing to do, and so my inclination is to not worry too much about it. |
Oh, I missed it. Though, seems it allows calls and member access while disallowing simple expressions like About the examples: in Svelte 4, only I believe we shouldn't replicate Svelte 4 behavior up to all nuances (there are a bunch of buggy edge cases), but rather replicate the behavior people would expect from Svelte 4, unless is stated in RFC. In particular, I'm sure people wouldn't expect the I'm surprised that, despite this being quite a big discrepancy of reactivity behavior, only a few users are affected.
Sounds great, I didn't like that here I had to filter unrelated references, or |
Talking about the test block-expression-assign, in particular {#key 1}
{@const x = (h = 0)}
{x, ''}
{/key}
{#if 1}
{@const x = (i = 0)}
{x, ''}
{/if} As #8404 was fixed in Svelte 5, you cannot have |
Fixes #14351
The block's expressions
{#if someFn()}
are deeply tracked in legacy mode, which is not how Svelte 4 reactivity works.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