You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Renders of a variable bound to an input element of type="number" will not update if the variable is changed within a reactive statement that is triggered by the input
#4631
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.
Describe the bug
The title is a hell of a mouthful.
I'm still not certain I've actually pinpointed the odd behavior, but this is as close as I could get.
To elaborate on the title, if an <input> element with type="number" triggers a reactive statement via a bound variable, changing the bound variable in the reactive statement will not perform any updates to places which rely on that variable.
That means, in the following example the reactive statement will trigger when myNum changes (due to the console.log). However, if it was triggered by typing in the <input> element, renders using myNum will be unaffected. If other variables are changed, those will work fine, but ones with myNum will be ignored.
Triggering the reactive statement some other way (like having a button increment myNum) will result in myNum changing to 500.
Expected behavior
like type="text", type="number" should allow myNum's change in value to affect renders.
Information about your Svelte project:
Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10)
Windows & OSX, REPL, Rollup, Chrome 80, Svelte v3.2
Severity
Medium. Creating restrictive user inputs is useful. With React it's the default way to make inputs. With svelte it's a bit more difficult and may require a bit of twisting.
The text was updated successfully, but these errors were encountered:
The difference in behavior between number and text is presumably related to the input_updating guard in the code generated for number but I haven't dug into it any more deeply than that.
Describe the bug
The title is a hell of a mouthful.
I'm still not certain I've actually pinpointed the odd behavior, but this is as close as I could get.
To elaborate on the title, if an
<input>
element withtype="number"
triggers a reactive statement via a bound variable, changing the bound variable in the reactive statement will not perform any updates to places which rely on that variable.That means, in the following example the reactive statement will trigger when
myNum
changes (due to theconsole.log
). However, if it was triggered by typing in the<input>
element, renders usingmyNum
will be unaffected. If other variables are changed, those will work fine, but ones withmyNum
will be ignored.Triggering the reactive statement some other way (like having a button increment
myNum
) will result inmyNum
changing to 500.As an aside, @pngwn found a fix (not for the bug, but to get this REPL working). Using
tick
beforemyNum = 500
allows an update cycle and it should work as it does withtype="text"
:https://svelte.dev/repl/dca7070e064f4d9da9f49d4133056a76?version=3.20.1
To Reproduce
The previous example in a REPL:
https://svelte.dev/repl/2fb57570c5dd48a580619d13246a53e1?version=3.20.1
Change the type from
"number"
to"text"
to see how its behavior changes.For an actual use-case (and for how I ran into this), this REPL on restrictive/controlled inputs may help:
https://svelte.dev/repl/8019ec1168fe4fb99e2a2cd44545f70b?version=3.20.1
Expected behavior
like
type="text"
,type="number"
should allowmyNum
's change in value to affect renders.Information about your Svelte project:
Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10)
Windows & OSX, REPL, Rollup, Chrome 80, Svelte v3.2
Severity
Medium. Creating restrictive user inputs is useful. With React it's the default way to make inputs. With svelte it's a bit more difficult and may require a bit of twisting.
The text was updated successfully, but these errors were encountered: