@tanstack/react-router 1.158.1 → 1.159.3
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.
|
@@ -4,6 +4,7 @@ const node_stream = require("node:stream");
|
|
|
4
4
|
const ReactDOMServer = require("react-dom/server");
|
|
5
5
|
const isbot = require("isbot");
|
|
6
6
|
const server = require("@tanstack/router-core/ssr/server");
|
|
7
|
+
const srvx = require("srvx");
|
|
7
8
|
const renderRouterToStream = async ({
|
|
8
9
|
request,
|
|
9
10
|
router,
|
|
@@ -23,7 +24,7 @@ const renderRouterToStream = async ({
|
|
|
23
24
|
router,
|
|
24
25
|
stream
|
|
25
26
|
);
|
|
26
|
-
return new
|
|
27
|
+
return new srvx.FastResponse(responseStream, {
|
|
27
28
|
status: router.state.statusCode,
|
|
28
29
|
headers: responseHeaders
|
|
29
30
|
});
|
|
@@ -60,7 +61,7 @@ const renderRouterToStream = async ({
|
|
|
60
61
|
router,
|
|
61
62
|
reactAppPassthrough
|
|
62
63
|
);
|
|
63
|
-
return new
|
|
64
|
+
return new srvx.FastResponse(responseStream, {
|
|
64
65
|
status: router.state.statusCode,
|
|
65
66
|
headers: responseHeaders
|
|
66
67
|
});
|
|
@@ -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
|
|
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 { FastResponse } from 'srvx'\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 FastResponse(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 FastResponse(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","FastResponse","PassThrough","transformPipeableStreamWithRouter"],"mappings":";;;;;;;AAYO,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,IAAIC,KAAAA,aAAa,gBAAuB;AAAA,MAC7C,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,GAAIH,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,iBAAiBI,OAAAA;AAAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAIF,KAAAA,aAAa,gBAAuB;AAAA,MAC7C,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EAAA;AAEJ;;"}
|
|
@@ -2,6 +2,7 @@ import { PassThrough } from "node:stream";
|
|
|
2
2
|
import ReactDOMServer from "react-dom/server";
|
|
3
3
|
import { isbot } from "isbot";
|
|
4
4
|
import { transformReadableStreamWithRouter, transformPipeableStreamWithRouter } from "@tanstack/router-core/ssr/server";
|
|
5
|
+
import { FastResponse } from "srvx";
|
|
5
6
|
const renderRouterToStream = async ({
|
|
6
7
|
request,
|
|
7
8
|
router,
|
|
@@ -21,7 +22,7 @@ const renderRouterToStream = async ({
|
|
|
21
22
|
router,
|
|
22
23
|
stream
|
|
23
24
|
);
|
|
24
|
-
return new
|
|
25
|
+
return new FastResponse(responseStream, {
|
|
25
26
|
status: router.state.statusCode,
|
|
26
27
|
headers: responseHeaders
|
|
27
28
|
});
|
|
@@ -58,7 +59,7 @@ const renderRouterToStream = async ({
|
|
|
58
59
|
router,
|
|
59
60
|
reactAppPassthrough
|
|
60
61
|
);
|
|
61
|
-
return new
|
|
62
|
+
return new FastResponse(responseStream, {
|
|
62
63
|
status: router.state.statusCode,
|
|
63
64
|
headers: responseHeaders
|
|
64
65
|
});
|
|
@@ -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
|
|
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 { FastResponse } from 'srvx'\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 FastResponse(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 FastResponse(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":";;;;;AAYO,MAAM,uBAAuB,OAAO;AAAA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AI,MAAM,OAAO,CAAC,CAAC,CAAC;AAAA,IAC3E;AAEA,UAAM,iBAAiB;AAAA,MACrB;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,IAAI,aAAa,gBAAuB;AAAA,MAC7C,QAAQ,OAAO,MAAM;AAAA,MACrB,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.159.3",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -79,10 +79,11 @@
|
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@tanstack/react-store": "^0.8.0",
|
|
81
81
|
"isbot": "^5.1.22",
|
|
82
|
+
"srvx": "^0.11.2",
|
|
82
83
|
"tiny-invariant": "^1.3.3",
|
|
83
84
|
"tiny-warning": "^1.0.3",
|
|
84
85
|
"@tanstack/history": "1.154.14",
|
|
85
|
-
"@tanstack/router-core": "1.158.
|
|
86
|
+
"@tanstack/router-core": "1.158.4"
|
|
86
87
|
},
|
|
87
88
|
"devDependencies": {
|
|
88
89
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
transformPipeableStreamWithRouter,
|
|
6
6
|
transformReadableStreamWithRouter,
|
|
7
7
|
} from '@tanstack/router-core/ssr/server'
|
|
8
|
+
import { FastResponse } from 'srvx'
|
|
8
9
|
import type { AnyRouter } from '@tanstack/router-core'
|
|
9
10
|
import type { ReadableStream } from 'node:stream/web'
|
|
10
11
|
import type { ReactNode } from 'react'
|
|
@@ -35,7 +36,7 @@ export const renderRouterToStream = async ({
|
|
|
35
36
|
router,
|
|
36
37
|
stream as unknown as ReadableStream,
|
|
37
38
|
)
|
|
38
|
-
return new
|
|
39
|
+
return new FastResponse(responseStream as any, {
|
|
39
40
|
status: router.state.statusCode,
|
|
40
41
|
headers: responseHeaders,
|
|
41
42
|
})
|
|
@@ -78,7 +79,7 @@ export const renderRouterToStream = async ({
|
|
|
78
79
|
router,
|
|
79
80
|
reactAppPassthrough,
|
|
80
81
|
)
|
|
81
|
-
return new
|
|
82
|
+
return new FastResponse(responseStream as any, {
|
|
82
83
|
status: router.state.statusCode,
|
|
83
84
|
headers: responseHeaders,
|
|
84
85
|
})
|