@tanstack/react-router 1.139.11 → 1.139.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ssr/renderRouterToStream.cjs +6 -0
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs +2 -0
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/esm/ssr/renderRouterToStream.js +6 -0
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +2 -0
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/package.json +2 -2
- package/src/ssr/renderRouterToStream.tsx +7 -0
- package/src/ssr/renderRouterToString.tsx +2 -0
|
@@ -45,10 +45,16 @@ const renderRouterToStream = async ({
|
|
|
45
45
|
},
|
|
46
46
|
onError: (error, info) => {
|
|
47
47
|
console.error("Error in renderToPipeableStream:", error, info);
|
|
48
|
+
if (!reactAppPassthrough.destroyed) {
|
|
49
|
+
reactAppPassthrough.destroy(
|
|
50
|
+
error instanceof Error ? error : new Error(String(error))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
48
53
|
}
|
|
49
54
|
});
|
|
50
55
|
} catch (e) {
|
|
51
56
|
console.error("Error in renderToPipeableStream:", e);
|
|
57
|
+
reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)));
|
|
52
58
|
}
|
|
53
59
|
const responseStream = server.transformPipeableStreamWithRouter(
|
|
54
60
|
router,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouterToStream.cjs","sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"names":["isbot","transformReadableStreamWithRouter","PassThrough","transformPipeableStreamWithRouter"],"mappings":";;;;;;AAWO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,SAAS,MAAM,eAAe,uBAAuB,UAAU;AAAA,MACnE,QAAQ,QAAQ;AAAA,MAChB,OAAO,OAAO,QAAQ,KAAK;AAAA,MAC3B,sBAAsB,OAAO;AAAA,IAAA,CAC9B;AAED,QAAIA,MAAAA,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,GAAG;AAC5C,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,iBAAiBC,OAAAA;AAAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,SAAS,gBAAuB;AAAA,MACzC,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,sBAAsB,IAAIC,wBAAA;AAEhC,QAAI;AACF,YAAM,WAAW,eAAe,uBAAuB,UAAU;AAAA,QAC/D,OAAO,OAAO,QAAQ,KAAK;AAAA,QAC3B,sBAAsB,OAAO;AAAA,QAC7B,GAAIF,MAAAA,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,IACvC;AAAA,UACE,aAAa;AACX,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA,IAEF;AAAA,UACE,eAAe;AACb,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA;AAAA,QAEN,SAAS,CAAC,OAAO,SAAS;AACxB,kBAAQ,MAAM,oCAAoC,OAAO,IAAI;AAAA,
|
|
1
|
+
{"version":3,"file":"renderRouterToStream.cjs","sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n // Destroy the passthrough stream on error\n if (!reactAppPassthrough.destroyed) {\n reactAppPassthrough.destroy(\n error instanceof Error ? error : new Error(String(error)),\n )\n }\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)))\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"names":["isbot","transformReadableStreamWithRouter","PassThrough","transformPipeableStreamWithRouter"],"mappings":";;;;;;AAWO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,SAAS,MAAM,eAAe,uBAAuB,UAAU;AAAA,MACnE,QAAQ,QAAQ;AAAA,MAChB,OAAO,OAAO,QAAQ,KAAK;AAAA,MAC3B,sBAAsB,OAAO;AAAA,IAAA,CAC9B;AAED,QAAIA,MAAAA,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,GAAG;AAC5C,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,iBAAiBC,OAAAA;AAAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,SAAS,gBAAuB;AAAA,MACzC,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,sBAAsB,IAAIC,wBAAA;AAEhC,QAAI;AACF,YAAM,WAAW,eAAe,uBAAuB,UAAU;AAAA,QAC/D,OAAO,OAAO,QAAQ,KAAK;AAAA,QAC3B,sBAAsB,OAAO;AAAA,QAC7B,GAAIF,MAAAA,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,IACvC;AAAA,UACE,aAAa;AACX,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA,IAEF;AAAA,UACE,eAAe;AACb,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA;AAAA,QAEN,SAAS,CAAC,OAAO,SAAS;AACxB,kBAAQ,MAAM,oCAAoC,OAAO,IAAI;AAE7D,cAAI,CAAC,oBAAoB,WAAW;AAClC,gCAAoB;AAAA,cAClB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,YAAA;AAAA,UAE5D;AAAA,QACF;AAAA,MAAA,CACD;AAAA,IACH,SAAS,GAAG;AACV,cAAQ,MAAM,oCAAoC,CAAC;AACnD,0BAAoB,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC;AAAA,IAC3E;AAEA,UAAM,iBAAiBG,OAAAA;AAAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,SAAS,gBAAuB;AAAA,MACzC,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouterToString.cjs","sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n const injectedHtml = await Promise.all(router.serverSsr!.injectedHtml).then(\n (htmls) => htmls.join(''),\n )\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n }\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACJ,MAAI;AACF,QAAI,OAAO,eAAe,eAAe,QAAQ;AACjD,WAAO,UAAW,kBAAA;AAClB,UAAM,eAAe,MAAM,QAAQ,IAAI,OAAO,UAAW,YAAY,EAAE;AAAA,MACrE,CAAC,UAAU,MAAM,KAAK,EAAE;AAAA,IAAA;AAE1B,WAAO,KAAK,QAAQ,WAAW,MAAM,GAAG,YAAY,SAAS;AAC7D,WAAO,IAAI,SAAS,kBAAkB,IAAI,IAAI;AAAA,MAC5C,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO,IAAI,SAAS,yBAAyB;AAAA,MAC3C,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AACF;;"}
|
|
1
|
+
{"version":3,"file":"renderRouterToString.cjs","sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n const injectedHtml = await Promise.all(router.serverSsr!.injectedHtml).then(\n (htmls) => htmls.join(''),\n )\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n } finally {\n router.serverSsr?.cleanup()\n }\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACJ,MAAI;AACF,QAAI,OAAO,eAAe,eAAe,QAAQ;AACjD,WAAO,UAAW,kBAAA;AAClB,UAAM,eAAe,MAAM,QAAQ,IAAI,OAAO,UAAW,YAAY,EAAE;AAAA,MACrE,CAAC,UAAU,MAAM,KAAK,EAAE;AAAA,IAAA;AAE1B,WAAO,KAAK,QAAQ,WAAW,MAAM,GAAG,YAAY,SAAS;AAC7D,WAAO,IAAI,SAAS,kBAAkB,IAAI,IAAI;AAAA,MAC5C,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO,IAAI,SAAS,yBAAyB;AAAA,MAC3C,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH,UAAA;AACE,WAAO,WAAW,QAAA;AAAA,EACpB;AACF;;"}
|
|
@@ -43,10 +43,16 @@ const renderRouterToStream = async ({
|
|
|
43
43
|
},
|
|
44
44
|
onError: (error, info) => {
|
|
45
45
|
console.error("Error in renderToPipeableStream:", error, info);
|
|
46
|
+
if (!reactAppPassthrough.destroyed) {
|
|
47
|
+
reactAppPassthrough.destroy(
|
|
48
|
+
error instanceof Error ? error : new Error(String(error))
|
|
49
|
+
);
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
52
|
});
|
|
48
53
|
} catch (e) {
|
|
49
54
|
console.error("Error in renderToPipeableStream:", e);
|
|
55
|
+
reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)));
|
|
50
56
|
}
|
|
51
57
|
const responseStream = transformPipeableStreamWithRouter(
|
|
52
58
|
router,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouterToStream.js","sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,SAAS,MAAM,eAAe,uBAAuB,UAAU;AAAA,MACnE,QAAQ,QAAQ;AAAA,MAChB,OAAO,OAAO,QAAQ,KAAK;AAAA,MAC3B,sBAAsB,OAAO;AAAA,IAAA,CAC9B;AAED,QAAI,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,GAAG;AAC5C,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,iBAAiB;AAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,SAAS,gBAAuB;AAAA,MACzC,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,sBAAsB,IAAI,YAAA;AAEhC,QAAI;AACF,YAAM,WAAW,eAAe,uBAAuB,UAAU;AAAA,QAC/D,OAAO,OAAO,QAAQ,KAAK;AAAA,QAC3B,sBAAsB,OAAO;AAAA,QAC7B,GAAI,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,IACvC;AAAA,UACE,aAAa;AACX,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA,IAEF;AAAA,UACE,eAAe;AACb,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA;AAAA,QAEN,SAAS,CAAC,OAAO,SAAS;AACxB,kBAAQ,MAAM,oCAAoC,OAAO,IAAI;AAAA,
|
|
1
|
+
{"version":3,"file":"renderRouterToStream.js","sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n // Destroy the passthrough stream on error\n if (!reactAppPassthrough.destroyed) {\n reactAppPassthrough.destroy(\n error instanceof Error ? error : new Error(String(error)),\n )\n }\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)))\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,SAAS,MAAM,eAAe,uBAAuB,UAAU;AAAA,MACnE,QAAQ,QAAQ;AAAA,MAChB,OAAO,OAAO,QAAQ,KAAK;AAAA,MAC3B,sBAAsB,OAAO;AAAA,IAAA,CAC9B;AAED,QAAI,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,GAAG;AAC5C,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,iBAAiB;AAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,SAAS,gBAAuB;AAAA,MACzC,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,MAAI,OAAO,eAAe,2BAA2B,YAAY;AAC/D,UAAM,sBAAsB,IAAI,YAAA;AAEhC,QAAI;AACF,YAAM,WAAW,eAAe,uBAAuB,UAAU;AAAA,QAC/D,OAAO,OAAO,QAAQ,KAAK;AAAA,QAC3B,sBAAsB,OAAO;AAAA,QAC7B,GAAI,MAAM,QAAQ,QAAQ,IAAI,YAAY,CAAC,IACvC;AAAA,UACE,aAAa;AACX,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA,IAEF;AAAA,UACE,eAAe;AACb,qBAAS,KAAK,mBAAmB;AAAA,UACnC;AAAA,QAAA;AAAA,QAEN,SAAS,CAAC,OAAO,SAAS;AACxB,kBAAQ,MAAM,oCAAoC,OAAO,IAAI;AAE7D,cAAI,CAAC,oBAAoB,WAAW;AAClC,gCAAoB;AAAA,cAClB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,YAAA;AAAA,UAE5D;AAAA,QACF;AAAA,MAAA,CACD;AAAA,IACH,SAAS,GAAG;AACV,cAAQ,MAAM,oCAAoC,CAAC;AACnD,0BAAoB,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC;AAAA,IAC3E;AAEA,UAAM,iBAAiB;AAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,SAAS,gBAAuB;AAAA,MACzC,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouterToString.js","sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n const injectedHtml = await Promise.all(router.serverSsr!.injectedHtml).then(\n (htmls) => htmls.join(''),\n )\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n }\n}\n"],"names":[],"mappings":";AAIO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACJ,MAAI;AACF,QAAI,OAAO,eAAe,eAAe,QAAQ;AACjD,WAAO,UAAW,kBAAA;AAClB,UAAM,eAAe,MAAM,QAAQ,IAAI,OAAO,UAAW,YAAY,EAAE;AAAA,MACrE,CAAC,UAAU,MAAM,KAAK,EAAE;AAAA,IAAA;AAE1B,WAAO,KAAK,QAAQ,WAAW,MAAM,GAAG,YAAY,SAAS;AAC7D,WAAO,IAAI,SAAS,kBAAkB,IAAI,IAAI;AAAA,MAC5C,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO,IAAI,SAAS,yBAAyB;AAAA,MAC3C,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AACF;"}
|
|
1
|
+
{"version":3,"file":"renderRouterToString.js","sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n const injectedHtml = await Promise.all(router.serverSsr!.injectedHtml).then(\n (htmls) => htmls.join(''),\n )\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.state.statusCode,\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n } finally {\n router.serverSsr?.cleanup()\n }\n}\n"],"names":[],"mappings":";AAIO,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACJ,MAAI;AACF,QAAI,OAAO,eAAe,eAAe,QAAQ;AACjD,WAAO,UAAW,kBAAA;AAClB,UAAM,eAAe,MAAM,QAAQ,IAAI,OAAO,UAAW,YAAY,EAAE;AAAA,MACrE,CAAC,UAAU,MAAM,KAAK,EAAE;AAAA,IAAA;AAE1B,WAAO,KAAK,QAAQ,WAAW,MAAM,GAAG,YAAY,SAAS;AAC7D,WAAO,IAAI,SAAS,kBAAkB,IAAI,IAAI;AAAA,MAC5C,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO,IAAI,SAAS,yBAAyB;AAAA,MAC3C,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH,UAAA;AACE,WAAO,WAAW,QAAA;AAAA,EACpB;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.139.
|
|
3
|
+
"version": "1.139.12",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"tiny-invariant": "^1.3.3",
|
|
81
81
|
"tiny-warning": "^1.0.3",
|
|
82
82
|
"@tanstack/history": "1.139.0",
|
|
83
|
-
"@tanstack/router-core": "1.139.
|
|
83
|
+
"@tanstack/router-core": "1.139.12"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -61,10 +61,17 @@ export const renderRouterToStream = async ({
|
|
|
61
61
|
}),
|
|
62
62
|
onError: (error, info) => {
|
|
63
63
|
console.error('Error in renderToPipeableStream:', error, info)
|
|
64
|
+
// Destroy the passthrough stream on error
|
|
65
|
+
if (!reactAppPassthrough.destroyed) {
|
|
66
|
+
reactAppPassthrough.destroy(
|
|
67
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
68
|
+
)
|
|
69
|
+
}
|
|
64
70
|
},
|
|
65
71
|
})
|
|
66
72
|
} catch (e) {
|
|
67
73
|
console.error('Error in renderToPipeableStream:', e)
|
|
74
|
+
reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)))
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
const responseStream = transformPipeableStreamWithRouter(
|