-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: allow state/derived/props to be explicitly exported from components #10523
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
This reverts commit dab0a43.
🦋 Changeset detectedLatest commit: 6104318 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 |
Will the exported state be reactive in this case though? That's usually how I see people try to do this and I think it could cause confusion if they were allowed to do it and then it didn't work |
Yes, it will — though if you try and mutate it from outside the component Svelte will yell at you (#10464) |
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 isn't working correctly yet.
- The REPL in Signal is exposed when creating $derived value accessor #10293 returns the signal as-is, not a getter of it (preview playground link)
- The REPL in Error when creating an accessor for an prop #10311 is broken,
$.get
of the prop is not called in the right places (preview playground link). I'm still unsure if the use case "create a getter/setter from a prop" is a thing we should allow.
should be all set now |
'invalid-state-export': () => `Cannot export state from a module if it is reassigned`, | ||
'invalid-derived-export': () => `Cannot export derived state from a module`, |
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.
Code looks good now, though I slightly prefered the changed error messages because they gave you instructions on how to resolve the error. Thoughts?
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.
merged the changes from both
I think it's fine to
export
state/derived/props from components, which means reverting #10430.Note that
export let
is still forbidden in runes mode, since it's much more likely to be unintentional than not. To export state, you must do it in two parts:We could potentially allow
export let x = $state(...)
in future, once we go runes-only.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint