@bleedingdev/modern-js-plugin-tanstack 3.9.3-ultramodern.12 → 3.9.3-ultramodern.14

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.
@@ -51,6 +51,7 @@ const payloadRouter_js_namespaceObject = require("./rsc/payloadRouter.js");
51
51
  const payloadStorage_js_namespaceObject = require("./rsc/payloadStorage.js");
52
52
  const external_ssrManagedTags_js_namespaceObject = require("./ssrManagedTags.js");
53
53
  const external_ssrPreload_js_namespaceObject = require("./ssrPreload.js");
54
+ const external_ssrStream_js_namespaceObject = require("./ssrStream.js");
54
55
  const external_types_js_namespaceObject = require("./types.js");
55
56
  const tanstackRouterPlugin = (userConfig = {})=>{
56
57
  const plugin = {
@@ -178,11 +179,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
178
179
  }));
179
180
  if (isRSCNavigation) context.ssrContext.response.setHeader('Content-Type', 'text/x-component');
180
181
  }
181
- const initialScriptTags = serverRouter.serverSsr?.takeInitialHydrationScriptTags();
182
- const hydrationScripts = initialScriptTags ? (0, external_ssrManagedTags_js_namespaceObject.routerManagedTagsToHtml)([
183
- ...initialScriptTags.before,
184
- initialScriptTags.boundary
185
- ]) : [];
182
+ const hydrationScripts = (0, external_ssrStream_js_namespaceObject.takeRouterHydrationScripts)(serverRouter, context.ssrContext?.mode === 'stream');
186
183
  const matchedRouteIds = (0, index_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
187
184
  const routerServerSnapshot = {
188
185
  framework: 'tanstack',
@@ -216,6 +213,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
216
213
  } catch {}
217
214
  }
218
215
  });
216
+ api.extendStreamSSR((info)=>(0, external_ssrStream_js_namespaceObject.createTanstackSsrStreamExtender)((0, external_lifecycle_js_namespaceObject.getRouterRuntimeState)(info.runtimeContext)?.instance, info.request));
219
217
  api.wrapRoot((App)=>{
220
218
  const getRouteApp = ()=>{
221
219
  if ((0, context_namespaceObject.getGlobalEnableRsc)()) return (props)=>{
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ createTanstackSsrStreamExtender: ()=>createTanstackSsrStreamExtender,
32
+ takeRouterHydrationScripts: ()=>takeRouterHydrationScripts
33
+ });
34
+ const server_namespaceObject = require("@tanstack/router-core/ssr/server");
35
+ const external_ssrManagedTags_js_namespaceObject = require("./ssrManagedTags.js");
36
+ const streamBoundaries = new WeakMap();
37
+ function takeRouterHydrationScripts(router, streaming) {
38
+ const tags = router.serverSsr?.takeInitialHydrationScriptTags();
39
+ if (void 0 === tags) return [];
40
+ if (!streaming) return (0, external_ssrManagedTags_js_namespaceObject.routerManagedTagsToHtml)([
41
+ ...tags.before,
42
+ tags.boundary
43
+ ]);
44
+ streamBoundaries.set(router, (0, external_ssrManagedTags_js_namespaceObject.routerManagedTagsToHtml)(tags.boundary).join(''));
45
+ return (0, external_ssrManagedTags_js_namespaceObject.routerManagedTagsToHtml)(tags.before);
46
+ }
47
+ function createTanstackSsrStreamExtender(router, request) {
48
+ const boundary = void 0 === router ? void 0 : streamBoundaries.get(router);
49
+ if (router?.serverSsr === void 0 || void 0 === boundary || '' === boundary) return {};
50
+ let boundaryWritten = false;
51
+ return {
52
+ completedBody (html) {
53
+ if (boundaryWritten) return html;
54
+ boundaryWritten = true;
55
+ return html + boundary;
56
+ },
57
+ processResponseStream (stream) {
58
+ return (0, server_namespaceObject.transformReadableStreamWithRouter)(router, stream, {
59
+ signal: request.signal,
60
+ rendererSafePoint: "script-close"
61
+ });
62
+ }
63
+ };
64
+ }
65
+ exports.createTanstackSsrStreamExtender = __webpack_exports__.createTanstackSsrStreamExtender;
66
+ exports.takeRouterHydrationScripts = __webpack_exports__.takeRouterHydrationScripts;
67
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
68
+ "createTanstackSsrStreamExtender",
69
+ "takeRouterHydrationScripts"
70
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
71
+ Object.defineProperty(exports, '__esModule', {
72
+ value: true
73
+ });
@@ -16,8 +16,9 @@ import { Link } from "./prefetchLink.mjs";
16
16
  import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree/index.mjs";
17
17
  import { createTanstackRscServerPayload, handleTanstackRscRedirect } from "./rsc/payloadRouter.mjs";
18
18
  import { getTanstackRscRouter, setTanstackRscRouter, setTanstackRscServerPayload } from "./rsc/payloadStorage.mjs";
19
- import { attachServerSsrUtils, collectRouterErrors, createGetSsrHref, routerManagedTagsToHtml } from "./ssrManagedTags.mjs";
19
+ import { attachServerSsrUtils, collectRouterErrors, createGetSsrHref } from "./ssrManagedTags.mjs";
20
20
  import { preloadMatchedRouteComponents } from "./ssrPreload.mjs";
21
+ import { createTanstackSsrStreamExtender, takeRouterHydrationScripts } from "./ssrStream.mjs";
21
22
  import { getModernTanstackRouterFastDefaults } from "./types.mjs";
22
23
  const tanstackRouterPlugin = (userConfig = {})=>{
23
24
  const plugin = {
@@ -145,11 +146,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
145
146
  }));
146
147
  if (isRSCNavigation) context.ssrContext.response.setHeader('Content-Type', 'text/x-component');
147
148
  }
148
- const initialScriptTags = serverRouter.serverSsr?.takeInitialHydrationScriptTags();
149
- const hydrationScripts = initialScriptTags ? routerManagedTagsToHtml([
150
- ...initialScriptTags.before,
151
- initialScriptTags.boundary
152
- ]) : [];
149
+ const hydrationScripts = takeRouterHydrationScripts(serverRouter, context.ssrContext?.mode === 'stream');
153
150
  const matchedRouteIds = getModernRouteIdsFromMatches(serverRouter);
154
151
  const routerServerSnapshot = {
155
152
  framework: 'tanstack',
@@ -183,6 +180,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
183
180
  } catch {}
184
181
  }
185
182
  });
183
+ api.extendStreamSSR((info)=>createTanstackSsrStreamExtender(getRouterRuntimeState(info.runtimeContext)?.instance, info.request));
186
184
  api.wrapRoot((App)=>{
187
185
  const getRouteApp = ()=>{
188
186
  if (getGlobalEnableRsc()) return (props)=>{
@@ -0,0 +1,32 @@
1
+ import { transformReadableStreamWithRouter } from "@tanstack/router-core/ssr/server";
2
+ import { routerManagedTagsToHtml } from "./ssrManagedTags.mjs";
3
+ const streamBoundaries = new WeakMap();
4
+ function takeRouterHydrationScripts(router, streaming) {
5
+ const tags = router.serverSsr?.takeInitialHydrationScriptTags();
6
+ if (void 0 === tags) return [];
7
+ if (!streaming) return routerManagedTagsToHtml([
8
+ ...tags.before,
9
+ tags.boundary
10
+ ]);
11
+ streamBoundaries.set(router, routerManagedTagsToHtml(tags.boundary).join(''));
12
+ return routerManagedTagsToHtml(tags.before);
13
+ }
14
+ function createTanstackSsrStreamExtender(router, request) {
15
+ const boundary = void 0 === router ? void 0 : streamBoundaries.get(router);
16
+ if (router?.serverSsr === void 0 || void 0 === boundary || '' === boundary) return {};
17
+ let boundaryWritten = false;
18
+ return {
19
+ completedBody (html) {
20
+ if (boundaryWritten) return html;
21
+ boundaryWritten = true;
22
+ return html + boundary;
23
+ },
24
+ processResponseStream (stream) {
25
+ return transformReadableStreamWithRouter(router, stream, {
26
+ signal: request.signal,
27
+ rendererSafePoint: "script-close"
28
+ });
29
+ }
30
+ };
31
+ }
32
+ export { createTanstackSsrStreamExtender, takeRouterHydrationScripts };
@@ -17,8 +17,9 @@ import { Link } from "./prefetchLink.mjs";
17
17
  import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree/index.mjs";
18
18
  import { createTanstackRscServerPayload, handleTanstackRscRedirect } from "./rsc/payloadRouter.mjs";
19
19
  import { getTanstackRscRouter, setTanstackRscRouter, setTanstackRscServerPayload } from "./rsc/payloadStorage.mjs";
20
- import { attachServerSsrUtils, collectRouterErrors, createGetSsrHref, routerManagedTagsToHtml } from "./ssrManagedTags.mjs";
20
+ import { attachServerSsrUtils, collectRouterErrors, createGetSsrHref } from "./ssrManagedTags.mjs";
21
21
  import { preloadMatchedRouteComponents } from "./ssrPreload.mjs";
22
+ import { createTanstackSsrStreamExtender, takeRouterHydrationScripts } from "./ssrStream.mjs";
22
23
  import { getModernTanstackRouterFastDefaults } from "./types.mjs";
23
24
  const tanstackRouterPlugin = (userConfig = {})=>{
24
25
  const plugin = {
@@ -146,11 +147,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
146
147
  }));
147
148
  if (isRSCNavigation) context.ssrContext.response.setHeader('Content-Type', 'text/x-component');
148
149
  }
149
- const initialScriptTags = serverRouter.serverSsr?.takeInitialHydrationScriptTags();
150
- const hydrationScripts = initialScriptTags ? routerManagedTagsToHtml([
151
- ...initialScriptTags.before,
152
- initialScriptTags.boundary
153
- ]) : [];
150
+ const hydrationScripts = takeRouterHydrationScripts(serverRouter, context.ssrContext?.mode === 'stream');
154
151
  const matchedRouteIds = getModernRouteIdsFromMatches(serverRouter);
155
152
  const routerServerSnapshot = {
156
153
  framework: 'tanstack',
@@ -184,6 +181,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
184
181
  } catch {}
185
182
  }
186
183
  });
184
+ api.extendStreamSSR((info)=>createTanstackSsrStreamExtender(getRouterRuntimeState(info.runtimeContext)?.instance, info.request));
187
185
  api.wrapRoot((App)=>{
188
186
  const getRouteApp = ()=>{
189
187
  if (getGlobalEnableRsc()) return (props)=>{
@@ -0,0 +1,33 @@
1
+ import "node:module";
2
+ import { transformReadableStreamWithRouter } from "@tanstack/router-core/ssr/server";
3
+ import { routerManagedTagsToHtml } from "./ssrManagedTags.mjs";
4
+ const streamBoundaries = new WeakMap();
5
+ function takeRouterHydrationScripts(router, streaming) {
6
+ const tags = router.serverSsr?.takeInitialHydrationScriptTags();
7
+ if (void 0 === tags) return [];
8
+ if (!streaming) return routerManagedTagsToHtml([
9
+ ...tags.before,
10
+ tags.boundary
11
+ ]);
12
+ streamBoundaries.set(router, routerManagedTagsToHtml(tags.boundary).join(''));
13
+ return routerManagedTagsToHtml(tags.before);
14
+ }
15
+ function createTanstackSsrStreamExtender(router, request) {
16
+ const boundary = void 0 === router ? void 0 : streamBoundaries.get(router);
17
+ if (router?.serverSsr === void 0 || void 0 === boundary || '' === boundary) return {};
18
+ let boundaryWritten = false;
19
+ return {
20
+ completedBody (html) {
21
+ if (boundaryWritten) return html;
22
+ boundaryWritten = true;
23
+ return html + boundary;
24
+ },
25
+ processResponseStream (stream) {
26
+ return transformReadableStreamWithRouter(router, stream, {
27
+ signal: request.signal,
28
+ rendererSafePoint: "script-close"
29
+ });
30
+ }
31
+ };
32
+ }
33
+ export { createTanstackSsrStreamExtender, takeRouterHydrationScripts };
@@ -0,0 +1,4 @@
1
+ import type { StreamSSRExtender } from '@modern-js/plugin/runtime';
2
+ import type { AnyRouter } from '@tanstack/react-router';
3
+ export declare function takeRouterHydrationScripts(router: AnyRouter, streaming: boolean): string[];
4
+ export declare function createTanstackSsrStreamExtender(router: AnyRouter | undefined, request: Request): StreamSSRExtender;
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "modern.js",
19
19
  "tanstack-router"
20
20
  ],
21
- "version": "3.9.3-ultramodern.12",
21
+ "version": "3.9.3-ultramodern.14",
22
22
  "engines": {
23
23
  "node": ">=20"
24
24
  },
@@ -94,19 +94,19 @@
94
94
  }
95
95
  },
96
96
  "dependencies": {
97
- "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.9.3-ultramodern.12",
98
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.12",
99
- "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.12",
100
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.3-ultramodern.12",
101
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.12",
102
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.12",
97
+ "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.9.3-ultramodern.14",
98
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.14",
99
+ "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.14",
100
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.3-ultramodern.14",
101
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.14",
102
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.14",
103
103
  "@swc/helpers": "^0.5.23",
104
104
  "@tanstack/react-router": "1.170.44",
105
105
  "@tanstack/router-core": "1.171.37"
106
106
  },
107
107
  "peerDependencies": {
108
- "@modern-js/app-tools": "3.9.3-ultramodern.12",
109
- "@modern-js/runtime": "3.9.3-ultramodern.12",
108
+ "@modern-js/app-tools": "3.9.3-ultramodern.14",
109
+ "@modern-js/runtime": "3.9.3-ultramodern.14",
110
110
  "react": "^19.3.1",
111
111
  "react-dom": "^19.3.1",
112
112
  "react-server-dom-rspack": "0.1.0"
@@ -117,9 +117,9 @@
117
117
  }
118
118
  },
119
119
  "devDependencies": {
120
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.3-ultramodern.12",
121
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.9.3-ultramodern.12",
122
- "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.9.3-ultramodern.12",
120
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.3-ultramodern.14",
121
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.9.3-ultramodern.14",
122
+ "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.9.3-ultramodern.14",
123
123
  "@rslib/core": "1.0.3",
124
124
  "@scripts/rstest-config": "2.66.0",
125
125
  "@tanstack/history": "1.162.5",
@@ -1,4 +1,5 @@
1
1
  // @effect-diagnostics asyncFunction:off newPromise:off strictBooleanExpressions:off unnecessaryArrowBlock:off
2
+ import type { StreamSSRInfo } from '@modern-js/plugin/runtime';
2
3
  import {
3
4
  getGlobalEnableRsc,
4
5
  InternalRuntimeContext,
@@ -56,9 +57,12 @@ import {
56
57
  attachServerSsrUtils,
57
58
  collectRouterErrors,
58
59
  createGetSsrHref,
59
- routerManagedTagsToHtml,
60
60
  } from './ssrManagedTags';
61
61
  import { preloadMatchedRouteComponents } from './ssrPreload';
62
+ import {
63
+ createTanstackSsrStreamExtender,
64
+ takeRouterHydrationScripts,
65
+ } from './ssrStream';
62
66
  import type {
63
67
  ModernTanstackRouterContext,
64
68
  TanstackRouterWithServerSsr,
@@ -263,14 +267,10 @@ export const tanstackRouterPlugin = (
263
267
  }
264
268
  }
265
269
 
266
- const initialScriptTags =
267
- serverRouter.serverSsr?.takeInitialHydrationScriptTags();
268
- const hydrationScripts = initialScriptTags
269
- ? routerManagedTagsToHtml([
270
- ...initialScriptTags.before,
271
- initialScriptTags.boundary,
272
- ])
273
- : [];
270
+ const hydrationScripts = takeRouterHydrationScripts(
271
+ serverRouter,
272
+ context.ssrContext?.mode === 'stream',
273
+ );
274
274
  const matchedRouteIds = getModernRouteIdsFromMatches(serverRouter);
275
275
  const routerServerSnapshot: InternalRouterServerSnapshot = {
276
276
  framework: 'tanstack',
@@ -310,6 +310,15 @@ export const tanstackRouterPlugin = (
310
310
  }
311
311
  });
312
312
 
313
+ api.extendStreamSSR((info: StreamSSRInfo<TInternalRuntimeContext>) =>
314
+ createTanstackSsrStreamExtender(
315
+ getRouterRuntimeState(info.runtimeContext)?.instance as
316
+ | AnyRouter
317
+ | undefined,
318
+ info.request,
319
+ ),
320
+ );
321
+
313
322
  api.wrapRoot(App => {
314
323
  const getRouteApp = () => {
315
324
  if (getGlobalEnableRsc()) {
@@ -0,0 +1,50 @@
1
+ import type { StreamSSRExtender } from '@modern-js/plugin/runtime';
2
+ import type { AnyRouter } from '@tanstack/react-router';
3
+ import { transformReadableStreamWithRouter } from '@tanstack/router-core/ssr/server';
4
+ import { routerManagedTagsToHtml } from './ssrManagedTags';
5
+
6
+ const streamBoundaries = new WeakMap<AnyRouter, string>();
7
+
8
+ export function takeRouterHydrationScripts(
9
+ router: AnyRouter,
10
+ streaming: boolean,
11
+ ) {
12
+ const tags = router.serverSsr?.takeInitialHydrationScriptTags();
13
+ if (tags === undefined) return [];
14
+ if (!streaming)
15
+ return routerManagedTagsToHtml([...tags.before, tags.boundary]);
16
+ streamBoundaries.set(router, routerManagedTagsToHtml(tags.boundary).join(''));
17
+ return routerManagedTagsToHtml(tags.before);
18
+ }
19
+
20
+ export function createTanstackSsrStreamExtender(
21
+ router: AnyRouter | undefined,
22
+ request: Request,
23
+ ): StreamSSRExtender {
24
+ const boundary =
25
+ router === undefined ? undefined : streamBoundaries.get(router);
26
+ if (
27
+ router?.serverSsr === undefined ||
28
+ boundary === undefined ||
29
+ boundary === ''
30
+ )
31
+ return {};
32
+ let boundaryWritten = false;
33
+ return {
34
+ completedBody(html) {
35
+ if (boundaryWritten) return html;
36
+ boundaryWritten = true;
37
+ // The native merger lifts its serialization barrier in body, after the
38
+ // renderer's shell, never at the bootstrap scripts in document.head.
39
+ return html + boundary;
40
+ },
41
+ processResponseStream(stream) {
42
+ return transformReadableStreamWithRouter(router, stream, {
43
+ signal: request.signal,
44
+ // Both Fizz and Redact close their reveal script after the complete
45
+ // hidden segment, so a router record cannot split renderer markup.
46
+ rendererSafePoint: 'script-close',
47
+ });
48
+ },
49
+ };
50
+ }