Skip to content

Commit

Permalink
fix(start): try/catch around renderToPipeableStream for React 19 (#3020)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
schiller-manuel and autofix-ci[bot] authored Dec 16, 2024
1 parent f063b49 commit 24217f8
Showing 1 changed file with 22 additions and 18 deletions.
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

0 comments on commit 24217f8

Please sign in to comment.