-
Notifications
You must be signed in to change notification settings - Fork 2.1k
PR: UppyContextProvider.svelte generates https://svelte.dev/e/state_referenced_locally warning #6141
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
…() when dealing with $props() value since it's reactive, to avoid https://svelte.dev/e/state_referenced_locally warning.
🦋 Changeset detectedLatest commit: 39c347b 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 |
Murderlon
left a comment
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.
Thanks for making a PR immediately. Did you run yarn build && yarn workspace example-sveltekit dev to confirm yourself it works as expected?
Co-authored-by: Merlijn Vos <merlijn@soverin.net>
Yes, now I did that, and I found that the warning was transferred down to line 43: setContext(UppyContextKey, contextValue)So I fixed it now and tested it as you described, and it works well :) |
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.
Pull request overview
This PR attempts to fix a Svelte 5 state_referenced_locally warning in UppyContextProvider.svelte by wrapping the uppy prop value in an IIFE when assigning it to the reactive $state object.
Changes:
- Modified how the
uppyprop is assigned within the$stateobject using an IIFE pattern - Added changeset documenting the fix
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/@uppy/svelte/src/lib/components/headless/UppyContextProvider.svelte | Modified uppy assignment in $state object to use IIFE pattern |
| .changeset/nice-jeans-sniff.md | Added changeset documenting the fix for capturing initial value of uppy |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Create a single reactive context object | ||
| const contextValue: UppyContext = $state({ | ||
| uppy, | ||
| uppy: (() => uppy)(), |
Copilot
AI
Jan 15, 2026
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.
The IIFE pattern (() => uppy)() is functionally equivalent to just uppy - it still captures only the initial value and doesn't maintain reactivity. To properly track changes to the uppy prop from $props(), you should use $derived(uppy) instead: uppy: $derived(uppy). This will ensure the contextValue.uppy updates when the prop changes.
| uppy: (() => uppy)(), | |
| uppy: $derived(uppy), |
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.
$derived() can't be used this way, and yes this works as before but without the warning
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'm worried Copilot is correct and the only reason you didn't get a warning anymore is because the build linter no longer matches on this code usage, which wouldn't mean this is actually fixed.
I would find it very odd if using a IIFE like this inside state is a Svelte best practice.
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.
Hmm, I had a thought about it again, and as you say even if I get rid of the warning, technically the issue is still there...
So I tried another method: separating status and progress props so they can be declared as $state()'s, and then instead used getters/setters to get the reactive values (and I didn't give the uppy prop a setter, since it is read-only).
Honestly experimenting a lot here, I think these warnings are a bit vaguely explained in the svelte docs.
Let me know what you think about it 👍🏻
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 tried reproducing this error on the main branch and I can't get it to show up? Do you have a reproducible example?
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update UppyContextProvider.svelte: : use $derived() instead of $state() when dealing with $props() value since it's reactive, to avoid https://svelte.dev/e/state_referenced_locally warning.
Issue: #6140