sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.44k stars 1.89k forks source link

Layout data based on store don't update on store update #10019

Closed afonsolopez closed 1 year ago

afonsolopez commented 1 year ago

Describe the bug

I have this page layout, where I want to store in a sidebar, updated data about my user credentials (from a API that I update and store in a SvelteKit Store).

//+layout.svelte
<script lang="ts">

    export let data;
    $: currentToken = data

</script>

    <p>{currentToken.refresh_token}</p>

    <slot />

The problem is, no matter what I do the data from the sidebar doesn't update, in the other hand at any other page it updates.

I tried several things like calling the store trough reactive variables, but nothing seems to work...

Reproduction

I've just started a new SvelteKit project and added a few libraries:

{
  "name": "test-1",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "vite dev",
    "build": "vite build",
    "preview": "vite preview",
    "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
    "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
  },
  "devDependencies": {
    "@sveltejs/kit": "^1.5.0",
    "@tailwindcss/forms": "^0.5.3",
    "autoprefixer": "^10.4.14",
    "postcss": "^8.4.23",
    "postcss-load-config": "^4.0.1",
    "svelte": "^3.54.0",
    "svelte-check": "^3.0.1",
    "svelte-preprocess": "^5.0.3",
    "tailwindcss": "^3.3.1",
    "tslib": "^2.4.1",
    "typescript": "^5.0.0",
    "vite": "^4.3.0"
  },
  "type": "module",
  "dependencies": {
  }
}

Logs

No response

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M2
    Memory: 109.08 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.0.0 - /usr/local/bin/node
    npm: 9.6.4 - /usr/local/bin/npm
  Browsers:
    Safari: 16.4
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.1 
    @sveltejs/kit: ^1.5.0 => 1.16.3 
    svelte: ^3.54.0 => 3.59.1 
    vite: ^4.3.0 => 4.3.5

Severity

annoyance

Additional Information

No response

Conduitry commented 1 year ago

Please follow the directions given in the issue template for what constitutes a reproduction.

A link to a repository, or a fork of https://node.new/sveltekit, that reproduces the issue. Reproductions must be short, self-contained and correct and must not contain files or code that aren't relevant to the issue — please do NOT just paste a link to your project. Explaining how to reproduce is generally not enough. It pushes the burden of creating a reproduction project onto a small set of volunteer maintainers and isn't scalable. If no reproduction is provided, the issue will be closed.

dimfeld commented 1 year ago

Just a guess but you might want $page.data instead of the data prop on the layout, since the layout's data prop won't have data from a subroute's load function. Hard to tell without a full example though.

afonsolopez commented 1 year ago

Just a guess but you might want $page.data instead of the data prop on the layout, since the layout's data prop won't have data from a subroute's load function. Hard to tell without a full example though.

Thanks man! it worked! 🥳