-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: don't hoist snippets with bind:group
#15040
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f380b34 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 |
preview: https://svelte-dev-git-preview-svelte-15040-svelte.vercel.app/ this is an automated message |
|
@@ -391,7 +391,7 @@ function open(parser) { | |||
parameters: function_expression.params, | |||
body: create_fragment(), | |||
metadata: { | |||
can_hoist: false, | |||
can_hoist: undefined, |
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.
This doesn't feel right, it should always be a boolean or if there's another state it should be an enum.
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 can make it an enum but it doesn't change the sense: undefined it's basically "don't know yet" because if the first visitor that sets can_hoist
is the bind:group
one we don't want to override it within the snippet. In the end it will always be set by the snippet visitor and the fact that it's a falsy value allow us to default it to false without having to discriminate further.
Yeah we need to disallow I'm not sure if it is a breaking change, is there any situation where it did work correctly before? |
I don't think it's a breaking because it was an error before so nobody could've used this syntax right? I think we should ban the usage too. |
Oh no wait, it's not a breaking for exporting but it is for passing props...but i would say if it's broken we should fix it regardless. I don't think many people were using this anyway...maybe we can add a special changeset to this? |
Not sure I follow what you mean by the last two posts. It's not breaking if |
Closes #15037
This is a bit of weird one...the point is that the snippet was technically not accessing anything from the instance so it was hoisted but it was using
bind:group
so it needed thebinding_group
...i tried to think it it make sense to export a snippet with a bind group but i don't think it does (especially since we specify in the docs that forbind:group
to work inputs needs to be in the same component) and i don't even think we could do it because even if we would accept thebinding_group
as an argument for the snippet a component that renders that snippet should know that it needs abinding_group
in some way and i don't think it's doable.However while trying to come up with various situations where the snippet could've been exported i noticed that we can technically "kinda" export snippets by passing them as prop. So a user could do something like this
App.svelte
Component.svelte
this is a bit weird because now
App
has thebinding_group
array but thestate
is insideComponent
. So i was wondering...should we disallowbind:group
in snippets all togheter? Technically we can't do it now since it would be a breaking change but i wonder if we should do something about this weirdness.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