-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
In onblur handler: state_unsafe_mutation Updating state inside a derived or logic block expression is forbidden [svelte 5 issue] #13684
Comments
I'm getting something similar when using the class The I'm having a difficult time creating a minimal repro per usual with Bits shenanigans but I know it was working before 268: |
After digging into this, I found that it's is actually unrelated to that PR. Yes that PR surfaces the issue, but the actual issue is that when we remove the DOM elements, it triggers a synchronous blur event to fire and that happens inside a phase where the active reaction is still the block effect. I'll put up a fix for this. This is annoying as Chrome is the only browser that incorrectly does this, see: https://chromestatus.com/feature/5128696823545856 |
Fixed with #13694 |
Thanks for the super fast fix @trueadm ! The fix was effective in a few scenarios, both in my codebase and the attached repl. Unfortunately, I'm still seeing the issue in another scenario in my codebase. Briefly, a I'll try to create a concise repro. In the mean time, here's the stack trace, in case it offers a useful hint.
|
@kyle-leonhard Looks like Svelte is moving the DOM element using I tried replicating it with a |
I observe a similar issue but with |
This was partially fixed with #13719. There is no error anymore. However the UI doesn't update when state changes during an out transition: REPL. I guess this might be intended, since at this point all the render effects have already been cleaned up. Would just like to confirm that this works as expected. It might feel weird from a user's perspective. |
I poked at my code a little. afaict, the error is triggered by an Maybe the code itself would be helpful! The row element is defined here (0) and the onblur handler is bound to the tr element here (1). The issue seems to impact Chrome and Chromium but not Safari. One more interesting thing that may or may not be helpful. You mentioned If there's useful debugging I can add, I'm happy to do so. |
It is by design: #12138 (comment) |
Ah, maybe Update: I can replicate it now |
Thanks @trueadm, appreciate it! I'll give it a shot when the next release hits. |
My issue is addressed! Thanks again |
Describe the bug
A
state_unsafe_mutation
error is triggered when anonblur
handler changes astore
value used in a$derived
call.I'm not really sure what the absolute minimal example is or the cause, I'm kind of a svelte newbie. I reproduced the error in a more contrived way in a repl attached.
This is triggered when upgrading from 5.0.0-next.267 to 5.0.0-next.269. I'm fairly sure it's triggered by #13625
Reproduction
Hover and then click one of the buttons in the repl
App.svelte:
Component2.svelte:
Logs
System Info
System: OS: macOS 15.0.1 CPU: (16) arm64 Apple M3 Max Memory: 16.74 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.9.0 - /opt/homebrew/bin/node npm: 10.8.3 - /opt/homebrew/bin/npm pnpm: 9.12.2 - /opt/homebrew/bin/pnpm Browsers: Chrome: 130.0.6723.59 Safari: 18.0.1 npmPackages: svelte: 5.0.0-next.269 => 5.0.0-next.269
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: