-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: add compiler error for each block mutations in runes mode #10428
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: 9f6bf0d 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 |
binding.kind === 'legacy_reactive_import') && | ||
binding.mutated)) | ||
// Bail-out if we reference anything from the EachBlock (for now) that mutates. | ||
(binding.kind === 'each' && |
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.
I vaguely remember that Rich wanted this kind of mutation to the each entry directly to be disallowed in runes mode - but I'm not sure if this was more due to the fact that this wasn't possible to achieve correctly before we added the proxy, so may be ok now. @Rich-Harris do you remember?
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.
Ah yeah. Well we can go that route if needed instead.
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.
Changed the PR to reflect that instead.
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.
I meant this in the sense of "back then we may have taken the stance that this should be disallowed, but now that we use proxies that might have changed, so your change is correct" and wanted to double-check with Rich because he might remember more. Let's wait on him to see whether or not this should be a compiler error or if this should work (personally I see no reason why it shouldn't work).
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.
We can always revert that commits lol
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.
I think it should be disallowed, because otherwise things like this break down:
-{#each numbers as n}
+{#each numbers.filter((n) => n % 2 === 0) as n}
<button onclick={() => n += 1}>{n}</button>
{/each}
It's better to enforce consistency (e.g. 'you have to do numbers[i] += 1
') than to have something that is superficially more convenient, but which is pretty confusing on the face of it (it's basically like reassigning a function parameter, and yet it somehow works?) and which requires you to understand non-obvious properties of the system before you can wield it successfully.
It doesn't work in Svelte 4, FWIW, so we should disallow it regardless of runes mode. I think it would be better to do this work in AssignmentExpression
and UpdateExpression
validation visitors — lemme push up some code real quick
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.
lol ok ignore the svelte 4 comment, i was doing onclick
instead of on:click
🤦
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.
though that said, this is a useful demo of 'works until it doesn't'
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.
Hey @Rich-Harris what exactly doesn’t work in this demo/examples?
Fixes #9400