Skip to content

Layout data lost on +error.svelte #14387

@ReindDooyeweerd

Description

@ReindDooyeweerd

Describe the bug

I noticed something yesterday after upgrading on of my SvelteKit projects from 2.37.0 to 2.37.1.

I created a repo that reproduces the issue as described below, repo can be found here: https://github.com/ReindDooyeweerd/sveltekitbug

The issue:
In my +layout.server.ts i normally fetch some data that is used throughout the whole website like menu data etc, this works great.

In the repo posted above i created a [slug] with a +page.server.ts which also fetches some data so https://localhost:5173/ shows the data fetched in the layout and https://localhost:5173/a shows both the data from +layout.server.ts and +page.server.ts => https://share.cleanshot.com/FV2B0qQYx2nNRLFS7mfQ

So far so good. Then i created a [slug_2] inside [slug], added a fetch also BUT i make sure that doesn't return any data and throw a 404. So https://localhost:5173/a/b should end up on +error.svelte

if (!fetchedPageData || Object.keys(fetchedPageData).length === 0) {
  error(404, 'Page not found');
}

This renders the +error.svelte but now the weird stuff happens since 2.37.1, the layout data becomes empty also: https://share.cleanshot.com/fx5VwqlRWJ67cLlKMKmz

While on version 2.37.0 with the exact same code i get this: https://share.cleanshot.com/x5bFFgz84gTjNJxVxjpR

Reproduction

  1. Clone https://github.com/ReindDooyeweerd/sveltekitbug
  2. npm install && npm run dev
  3. visit https://localhost:5173 => layout data in pre tags
  4. visit https://localhost:5173/a => layout data + page data in pre tags
  5. visit https://localhost:5173/a/b => fetch is empty, +error.svelte is rendered and both pre tags are empty
  6. change sveltekit version to 2.37.0 in package.json and start from 2 and on 5. you will see that the layout data is still available while pagedata is empty as expected

Version of the repo on stackblitz: https://stackblitz.com/~/github.com/ReindDooyeweerd/sveltekitbug

Logs

Nothing in the browser console or terminal

System Info

System:
    OS: macOS 15.6.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 641.34 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.0 - ~/.nvm/versions/node/v22.17.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.17.0/bin/npm
  Browsers:
    Chrome: 140.0.7339.80
    Safari: 18.6
  npmPackages:
    @sveltejs/adapter-auto: ^6.1.0 => 6.1.0 
    @sveltejs/kit: ^2.37.0 => 2.37.1 
    @sveltejs/vite-plugin-svelte: ^6.1.4 => 6.1.4 
    svelte: ^5.38.7 => 5.38.7 
    vite: ^7.1.5 => 7.1.5

Severity

blocking an upgrade

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions