Skip to content

Svelte 5: can't link reactivity from $props() #14536

Closed
@noslouch

Description

@noslouch

Describe the bug

This is most apparent when implementing pagination, but when trying to use deeply nested reactivity with page data objects in a svelte kit route (e.g. $state(data.foo)), it breaks the connection to $props().

Accessing directly with dot notation stays in sync with $props(), but does not have reactive state (as expected). The only way to stay in sync with $props() and get reactive state is to use component context to create local reactive state.

Reproduction

Here's a stack blitz with sveltekit repro. I can only get the expected reactivity by creating $state() in a component based on local primitive values.

https://stackblitz.com/edit/svelte-rune-page-data-bug?file=src%2Froutes%2F%2Bpage.server.ts,src%2Froutes%2F%2Bpage.svelte,src%2Flib%2Fbullet.svelte

And here's a svelte repro that shows similar behavior, but since the parent App.svelte component can create $state() and pass it into the component, the issue is not as apparent.

https://svelte.dev/playground/6fe00097a3104b11b9922df28b668598?version=5.1.3

Logs

No response

System Info

System:
    OS: macOS 14.7
    CPU: (10) arm64 Apple M1 Pro
    Memory: 83.23 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.1.0 - ~/.nvm/versions/node/v22.1.0/bin/node
    npm: 10.8.3 - ~/.nvm/versions/node/v22.1.0/bin/npm
    bun: 1.1.15 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 129.1.70.126
    Chrome: 130.0.6723.70
    Chrome Canary: 132.0.6803.0
    Safari: 18.0.1
  npmPackages:
    @sveltejs/adapter-node: ^5.2.8 => 5.2.8 
    @sveltejs/kit: ^2.0.0 => 2.7.2 
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.0 
    svelte: ^5.0.0 => 5.1.0 
    vite: ^5.0.3 => 5.4.10

Severity

serious, but I can work around it

Additional Information

No response

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