svelte
svelte copied to clipboard
Binding to store on select element doesn't work with on:input event.
Describe the bug
In the event listener of input event of select which bind to store value, if the value of the same store but different property was changed, the bind itself doesn't work at all.
- Create a store with object: i.e.
const s = writable({a:0, b: 0})
- Create a
<select>
element withbind:value={$s.a}
andon:input={()=>$s.b++}
. - Change select element's value. It won't change the
$s.a
Reproduction
https://svelte.dev/repl/6520010283474705a76372d5a2569e16?version=3.49.0
Logs
No response
System Info
System:
OS: macOS 12.5
CPU: (20) arm64 Apple M1 Ultra
Memory: 46.50 GB / 128.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn
npm: 8.9.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
Browsers:
Chrome: 103.0.5060.134
Safari: 15.6
Severity
annoyance
Everything seems to be switching between "Alice" and "Bob" correctly for me when I select options in the first dropdown in your REPL. What are you doing and what are you seeing?
This is what I'm seeing. The top most one, the value doesn't change with menu selection.
Forgot to report that this is latest Chrome on iOS and Safari is same result. So is Mac Chrome.
https://youtu.be/KK4RCyVaOco
It works well on Mac Firefox.
Good:
- Mac Firefox (104.0b6)
Bad:
- Mac Safari (15.6)
- Mac Chrome (103.0.5060.134)
- iOS Safari
- iOS Chrome
I checked this issue and I found 1 thing.
I created minimum REPL by vanilla JS. https://codepen.io/baseballyama/pen/rNJOwGX
I think the reson is that Google Chrome on mac hundles input event before change event. AFAIK, browser doesn't have garantee of event firering order. so I'm not sure what we can do for this.
would it be possible to check OS and adjust behavior accordingly in svelte? or force event firing order in some way? or is that not something we can do?
Tested on MacOS + Chromium 114.0.5735.198 AND MacOS + Safari 16:
on:input
: Does not work as expected - Apparently the <select>
WITH on:input
has issues updating the component state.
on:change
: Works as expected.