kit
kit copied to clipboard
Page always returns HTTP 200 when layout uses streaming with promises
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
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
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)
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.