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

Incorrect data update detection in +page.svelte #8548

Closed
sinbino opened this issue Jan 16, 2023 · 1 comment
Closed

Incorrect data update detection in +page.svelte #8548

sinbino opened this issue Jan 16, 2023 · 1 comment

Comments

@sinbino
Copy link

sinbino commented Jan 16, 2023

Describe the bug

https://github.com/sinbino/issue-sveltekit-reactive
See repository above

in src/routes/+page.svelte

<script lang="ts">
  import type { PageData } from "./$types"
  import Select from "./Select.svelte"

  export let data: PageData
  $: console.log('change data', JSON.stringify(data))

  // valueA PATTERN
  // When valueA is changed, a change in data is detected (UNEXPECTED BEHAVIOR)
  let valueA: number
  $: { valueA = data.value }

  // valueB PATTERN
  // If valueB is changed, the change in data is not detected (EXPECTED BEHAVIOR)
  let valueB: number
  const setValueB = (v: number) => { valueB = v }
  $: { setValueB(data.value) }
</script>

<!-- valueA PATTERN -->
<Select bind:value={valueA}></Select><br>
valueA={JSON.stringify(valueA)}<br>

<!-- valueB PATTERN -->
<Select bind:value={valueB}></Select><br>
valueB={JSON.stringify(valueB)}<br>

When valueA is updated by the Select component, for some reason the update of data is detected.
This is a strange behavior because data is not actually updated at this time.

The code for valueB should be equivalent to the code for valueA.
However, if valueB is updated by the Select component, the update of data is not detected.
This is the expected behavior.

Why does this happen?

Reproduction

https://github.com/sinbino/issue-sveltekit-reactive

Logs

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (10) x64 Intel(R) Core(TM) i5-10600 CPU @ 3.30GHz
    Memory: 5.52 GB / 9.90 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.12.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.1 
    @sveltejs/kit: ^1.0.0 => 1.1.1 
    svelte: ^3.54.0 => 3.55.1 
    vite: ^4.0.0 => 4.0.4

Severity

annoyance

Additional Information

No response

@gtm-nayan
Copy link
Contributor

Duplicate of sveltejs/svelte#7704

Also see sveltejs/svelte#7416 (comment)

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

2 participants