-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
First rendering when dispatch in reactivity expression #5405
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
Comments
Duplicate of #4470. |
In other words, this issue is about how to postpone dispatching an event containing the initial value from the Child2 component until its parent component has mounted. Thanks for the To clarify, for future readers, the 3rd REPL as is isn't actually "everything working" in the same way that the 2nd REPL is. To have it dispatch an event for both the initial value and any changes from that initial value, you would need to have a reactive onMount(handleOptionChange)
$: { handleOptionChange(); option } But that has 2 downsides that I can see:
So, it seems like the It's hard to believe this is really the intended behavior. It just seems unintuitive and easy to forget that this is needed. Will re-read #4470 to try figure out why the current behavior might be desired/intended, but so far, I can't understand why this behavior would be desirable. |
Uh oh!
There was an error while loading. Please reload this page.
If we use
dispatch
in a reactive expression, when the component is first rendered, thedispatch
event will not be handled. But if you do the same withonMount
, it will work. I fixed it withawait tick()
beforedispatch
in reactivity expression. But I don't understand the bug is this or not.What do you think of it? I didn't find anything like this in the documentation.
REPL reproduced bug with reactive expression: https://svelte.dev/repl/1055153bb575466cbcd91f38af019d1c?version=3.25.1
REPL solution with await tick: https://svelte.dev/repl/2864c5f152b14e6988328045b61f72ac?version=3.25.1
REPL everything is works with onMount: https://svelte.dev/repl/33c316946a0e4f97bbc899af151c6407?version=3.25.1
The text was updated successfully, but these errors were encountered: