Skip to content

Commit 46f12cf

Browse files
authored
fix: ensure SSR rendering gets request store context (#14476)
fixes #14473
1 parent 19211c1 commit 46f12cf

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

.changeset/rude-crabs-rescue.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: ensure SSR rendering gets request store context

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,26 @@ export async function render_response({
202202
};
203203

204204
try {
205-
rendered = with_request_store({ event, state: event_state }, () =>
206-
options.root.render(props, render_opts)
207-
);
205+
rendered = with_request_store({ event, state: event_state }, () => {
206+
const result = options.root.render(props, render_opts);
207+
// Svelte 5.39.0 changed the properties lazily start the rendering to be able to have the same signature for sync and async render.
208+
// 5.39.1 extended that to the old class components. Rendering isn't started until one of the properties is accessed, so we do that here,
209+
// else we might get errors about missing request store context
210+
result.html;
211+
return result;
212+
});
208213
} finally {
209214
globalThis.fetch = fetch;
210215
paths.reset();
211216
}
212217
} else {
213218
try {
214-
rendered = with_request_store({ event, state: event_state }, () =>
215-
options.root.render(props, render_opts)
216-
);
219+
rendered = with_request_store({ event, state: event_state }, () => {
220+
const result = options.root.render(props, render_opts);
221+
// See comment above
222+
result.html;
223+
return result;
224+
});
217225
} finally {
218226
paths.reset();
219227
}

0 commit comments

Comments
 (0)