Skip to content

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

@Tichss

Description

@Tichss

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy