Skip to content
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

fix(start): try/catch around renderToPipeableStream for React 19 #3020

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
40 changes: 22 additions & 18 deletions packages/start/src/server/defaultStreamHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,29 @@ export const defaultStreamHandler: HandlerCallback<AnyRouter> = async ({
if (typeof ReactDOMServer.renderToPipeableStream === 'function') {
const passthrough = new PassThrough()

const pipeable = ReactDOMServer.renderToPipeableStream(
<StartServer router={router} />,
{
...(isbot(request.headers.get('User-Agent'))
? {
onAllReady() {
pipeable.pipe(passthrough)
},
}
: {
onShellReady() {
pipeable.pipe(passthrough)
},
}),
onError: (error, info) => {
console.log('Error in renderToPipeableStream:', error, info)
try {
const pipeable = ReactDOMServer.renderToPipeableStream(
<StartServer router={router} />,
{
...(isbot(request.headers.get('User-Agent'))
? {
onAllReady() {
pipeable.pipe(passthrough)
},
}
: {
onShellReady() {
pipeable.pipe(passthrough)
},
}),
onError: (error, info) => {
console.log('Error in renderToPipeableStream:', error, info)
},
},
},
)
)
} catch (e) {
console.log('Error in renderToPipeableStream:', e)
}

const transforms = [transformStreamWithRouter(router)]

Expand Down
Loading