Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-crabs-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: ensure SSR rendering gets request store context
20 changes: 14 additions & 6 deletions packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,26 @@ export async function render_response({
};

try {
rendered = with_request_store({ event, state: event_state }, () =>
options.root.render(props, render_opts)
);
rendered = with_request_store({ event, state: event_state }, () => {
const result = options.root.render(props, render_opts);
// Svelte 5.39.0 changed the properties lazily start the rendering to be able to have the same signature for sync and async render.
// 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,
// else we might get errors about missing request store context
result.html;
return result;
Comment on lines +210 to +211

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just return { ...result } I think, don't care too much though

});
} finally {
globalThis.fetch = fetch;
paths.reset();
}
} else {
try {
rendered = with_request_store({ event, state: event_state }, () =>
options.root.render(props, render_opts)
);
rendered = with_request_store({ event, state: event_state }, () => {
const result = options.root.render(props, render_opts);
// See comment above
result.html;
return result;
});
} finally {
paths.reset();
}
Expand Down
Loading