Skip to content
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

fix: add compiler error for each block mutations in runes mode #10428

Merged
merged 7 commits into from
Feb 8, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Feb 8, 2024

Fixes #9400

Copy link

changeset-bot bot commented Feb 8, 2024

🦋 Changeset detected

Latest commit: 9f6bf0d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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' &&
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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).

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Member

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 🤦

Copy link
Member

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'

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?

@trueadm trueadm changed the title fix: improve code generation for mutation to each block reference fix: add compiler error around each block mutations in runes mode Feb 8, 2024
@trueadm trueadm changed the title fix: add compiler error around each block mutations in runes mode fix: add compiler error for each block mutations in runes mode Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svelte 5: Error: x is not defined
4 participants