Skip to content

Commit df679d2

Browse files
PatrickGteemingc
andauthored
fix: error pages with discarded promises fail to load (#14722)
* test * fix * changeset * Update .changeset/clear-vans-sniff.md Co-authored-by: Tee Ming <[email protected]> * move test * format * move test back --------- Co-authored-by: Tee Ming <[email protected]>
1 parent a78d8b1 commit df679d2

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

.changeset/clear-vans-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: avoid hanging when `error()` is used while streaming promises from a server `load` function

packages/kit/src/runtime/server/page/render.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ export async function render_response({
227227
paths.reset();
228228
}
229229

230-
// eslint-disable-next-line
231230
const { head, html, css } = options.async ? await rendered : rendered;
232231

233232
return { head, html, css };
@@ -654,7 +653,7 @@ export async function render_response({
654653
async start(controller) {
655654
controller.enqueue(text_encoder.encode(transformed + '\n'));
656655
for await (const chunk of chunks) {
657-
controller.enqueue(text_encoder.encode(chunk));
656+
if (chunk.length) controller.enqueue(text_encoder.encode(chunk));
658657
}
659658
controller.close();
660659
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function load() {
2+
return {
3+
promise: Promise.resolve(42)
4+
};
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { error } from '@sveltejs/kit';
2+
3+
export function load() {
4+
error(404);
5+
}

packages/kit/test/apps/basics/src/routes/streaming/discarded-promise/+page.svelte

Whitespace-only changes.

packages/kit/test/apps/basics/test/server.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,3 +1408,18 @@ test.describe('asset preload', () => {
14081408
});
14091409
}
14101410
});
1411+
1412+
test.describe('Streaming', () => {
1413+
test("Discarded promises from server load functions don't hang SSR request", async ({
1414+
request
1415+
}) => {
1416+
let error;
1417+
try {
1418+
await request.get('/streaming/discarded-promise');
1419+
} catch (e) {
1420+
error = e;
1421+
}
1422+
1423+
expect(error).toBeUndefined();
1424+
});
1425+
});

0 commit comments

Comments
 (0)