Skip to content
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

Using spread syntax '{...rest }' with props doesnt work correctly! #15237

Open
Tichss opened this issue Feb 7, 2025 · 4 comments
Open

Using spread syntax '{...rest }' with props doesnt work correctly! #15237

Tichss opened this issue Feb 7, 2025 · 4 comments

Comments

@Tichss
Copy link

Tichss commented Feb 7, 2025

Describe the bug

There is a simple example:

<script lang="ts">
    let value = $state();
</script>

<div>Value: {value}</div>
<div>Typeof value: {typeof value}</div>

<input {value} oninput={(e) => (value = e.target.value)} type="text" />
<input {value} oninput={(e) => (value = e.target.value)} type="text" {...{}} /> <!-- {...{}} diff -->

<button onclick={() => (value = '')}>empty string</button>
<button onclick={() => (value = undefined)}>undefined</button>
<button onclick={() => (value = null)}>null</button>

The 2 inputs differ only in the spread operator.
In theory, should both be the same? not?

However, there are a few interesting things when updating the value:

  • set to empty string : both input updated correctly ✔
  • set to undefined : 1. input get value as empty string ✔, 2. input value dont updated ❌
  • set to null : same as undefined ❌

try it here:
https://svelte.dev/playground/7a327186482347e688080339ea4a23a9?version=5.19.9

Reproduction

https://svelte.dev/playground/7a327186482347e688080339ea4a23a9?version=5.19.9

Logs

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 3.41 GB / 15.87 GB
  Binaries:
    Node: 20.11.1 - C:\Program Files\nodejs\node.EXE     
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD        
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355

Severity

annoyance

@paoloricciuti
Copy link
Member

Sorry but I'm not seeing this behavior in your repl...the input stays empty with all three buttons.

@Tichss
Copy link
Author

Tichss commented Feb 7, 2025

try to update any input with same value.

eg:
type to input 1 or 2: asd
press button empty string ✔
type to input 1 or 2: asd
press button empty undefined ❌

@paoloricciuti
Copy link
Member

Oh gotcha... thanks

@Tichss Tichss changed the title Using spread syntax '{...rest }' with props dont work correctly! Using spread syntax '{...rest }' with props doesnt work correctly! Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants