kit icon indicating copy to clipboard operation
kit copied to clipboard

Page always returns HTTP 200 when layout uses streaming with promises

Open tomekrozalski opened this issue 1 year ago • 1 comments

Describe the bug

+page.server.ts should return HTTP 404:

import { error } from '@sveltejs/kit';

export const load = () => {
  error(404, 'Something went wrong');

  return {
    pageData: true
  };
};

But it returns HTTP 200 when +layout.server.ts streams data:

export const load = () => {
  return {
    streamedData: new Promise((resolve) => setTimeout(resolve, 200)),
    layoutData: true
  };
};

We can see on a screen 404 page, but in a browser's network it is HTTP 200.

Reproduction

Stackblitz preview

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (11) arm64 Apple M3 Pro
    Memory: 82.66 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 9.1.1 - ~/.nvm/versions/node/v20.11.1/bin/pnpm
  Browsers:
    Chrome: 127.0.6533.88
    Safari: 17.5
  npmPackages:
    @sveltejs/adapter-node: ^5.2.0 => 5.2.0
    @sveltejs/kit: ^2.5.18 => 2.5.18
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.1
    svelte: ^4.2.18 => 4.2.18
    vite: ^5.3.5 => 5.3.5

Severity

serious, but I can work around it

Additional Information

No response

tomekrozalski avatar Aug 01 '24 14:08 tomekrozalski

The more I think about that, the more I believe this is how it should work 🤔 A workaround for that is using streaming data inside +layout.ts file (not .server.ts)

tomekrozalski avatar Aug 02 '24 20:08 tomekrozalski

I'm not able to reproduce the issue given the stackblitz link; I receive the thrown error as expected. I'll close this issue for now but please feel free to provide another minimal reproduction and I'll re-open the issue.

teemingc avatar Oct 26 '24 07:10 teemingc