Skip to content

Add ability to enable/ disable SSR #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2025
Merged

Add ability to enable/ disable SSR #522

merged 4 commits into from
Jun 16, 2025

Conversation

peterp
Copy link
Member

@peterp peterp commented Jun 16, 2025

This PR adds the ability to toggle server-side rendering.

render(Document, [
 // routes
], {
   ssr: false,
   rscPayload: true,
})

Copy link

cloudflare-workers-and-pages bot commented Jun 16, 2025

Deploying redwood-sdk-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: ac8a605
Status: ✅  Deploy successful!
Preview URL: https://79ed0b64.redwood-sdk-docs.pages.dev
Branch Preview URL: https://pp-add-ssr-flag.redwood-sdk-docs.pages.dev

View logs

Comment on lines 349 to 359
* @param options.ssr - Disable sever side rendering for all these routes. This only allow client side rendering`, which requires `rscPayload` to be enabled.
*/
options: {
rscPayload: boolean;
} = { rscPayload: true },
ssr: boolean;
} = { rscPayload: true, ssr: true },
): Route<T>[] {
const documentMiddleware: RouteMiddleware<T> = ({ rw }) => {
rw.Document = Document;
rw.rscPayload = options.rscPayload;
rw.ssr = options.ssr;
Copy link
Member Author

Choose a reason for hiding this comment

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

Only relevant changes.

Comment on lines +152 to +171
let html: ReadableStream<any>;

if (rw.ssr) {
html = await transformRscToHtmlStream({
stream: rscPayloadStream1,
Document: rw.Document,
requestInfo: requestInfo,
});
} else {
const emptyRscStream = renderToRscStream({
node: React.createElement(React.Fragment, null, null),
actionResult: undefined,
onError,
});
html = await transformRscToHtmlStream({
stream: emptyRscStream,
Document: rw.Document,
requestInfo: requestInfo,
});
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Converts RSC to HTML or, not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aaah, ok! So we return just the shell for that page, clever!

@peterp peterp requested a review from justinvdm June 16, 2025 11:09
Copy link
Collaborator

@justinvdm justinvdm left a comment

Choose a reason for hiding this comment

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

🧠

@justinvdm justinvdm merged commit efb44a8 into main Jun 16, 2025
5 checks passed
justinvdm pushed a commit that referenced this pull request Jun 16, 2025
This PR adds the ability to toggle server-side rendering.

```tsx
render(Document, [
 // routes
], {
   ssr: false,
   rscPayload: true,
})
```
justinvdm added a commit that referenced this pull request Jun 16, 2025
#512 and #522 ported to stable branch for 0.0.x releases.
@justinvdm
Copy link
Collaborator

Released in:

@justinvdm
Copy link
Collaborator

Fixes #515

@jldec
Copy link
Contributor

jldec commented Jun 16, 2025

@justinvdm I'm seeing a hydration error with this new flag in my test-repo. Is there something else I need to configure besides the flag on the route render?

jldec/agents-chat#25

@jldec jldec mentioned this pull request Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants