-
-
Notifications
You must be signed in to change notification settings - Fork 260
[codex] add Cloudflare SSR for playground #1303
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6e428d2
feat: add cloudflare ssr for playground
jderochervlk 0a8853a
chore: format v12.3 api data
jderochervlk 2621ca1
chore: remove unrelated API JSON formatting
jderochervlk 1ca04f5
fix(docs): build SSR bundle before Wrangler dev
jderochervlk 5368342
fix(docs): include playground in sitemap
jderochervlk b3633d1
docs: clarify hybrid SSR loader guidance
jderochervlk 055055f
fix(docs): preserve HTML headers for playground HEAD
jderochervlk dafcedc
Merge remote-tracking branch 'origin/master' into codex/cloudflare-ssr
jderochervlk 036775f
fix(ci): build docs before Wrangler validation
jderochervlk c2ffa45
fix(docs): use React Router request context
jderochervlk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import React from "react"; | ||
| import { renderToReadableStream } from "react-dom/server"; | ||
| import { isbot } from "isbot"; | ||
| import { ServerRouter } from "react-router"; | ||
|
|
||
| export const streamTimeout = 5_000; | ||
|
|
||
| export default async function handleRequest( | ||
| request, | ||
| responseStatusCode, | ||
| responseHeaders, | ||
| routerContext, | ||
| ) { | ||
| responseHeaders.set("Content-Type", "text/html"); | ||
|
|
||
| if (request.method.toUpperCase() === "HEAD") { | ||
| return new Response(null, { | ||
| status: responseStatusCode, | ||
| headers: responseHeaders, | ||
| }); | ||
| } | ||
|
|
||
| let shellRendered = false; | ||
| let userAgent = request.headers.get("user-agent"); | ||
|
|
||
| let body = await renderToReadableStream( | ||
| React.createElement(ServerRouter, { | ||
| context: routerContext, | ||
| url: request.url, | ||
| }), | ||
| { | ||
| signal: AbortSignal.timeout(streamTimeout + 1_000), | ||
| onError(error) { | ||
| responseStatusCode = 500; | ||
| if (shellRendered) { | ||
| console.error(error); | ||
| } | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| shellRendered = true; | ||
|
|
||
| if ( | ||
| ((userAgent && isbot(userAgent)) || routerContext.isSpaMode) && | ||
| body.allReady | ||
| ) { | ||
| await body.allReady; | ||
| } | ||
|
|
||
| return new Response(body, { | ||
| headers: responseHeaders, | ||
| status: responseStatusCode, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { onRequest } from "../server/react-router-handler.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { onRequest } from "../server/react-router-handler.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { createRequestHandler, RouterContextProvider } from "react-router"; | ||
|
|
||
| const mode = globalThis.process?.env?.NODE_ENV ?? "production"; | ||
|
|
||
| const handleReactRouterRequest = createRequestHandler( | ||
| () => import("../build/server/index.js"), | ||
|
jderochervlk marked this conversation as resolved.
|
||
| mode, | ||
| ); | ||
|
|
||
| export function onRequest(context) { | ||
| return handleReactRouterRequest(context.request, new RouterContextProvider()); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| name = "rescript-lang-org" | ||
| compatibility_date = "2026-09-10" | ||
| compatibility_flags = ["nodejs_compat"] | ||
| pages_build_output_dir = "out" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.