@bleedingdev/modern-js-runtime 3.2.0-ultramodern.11 → 3.2.0-ultramodern.111
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/boundary-debugger/index.js +303 -0
- package/dist/cjs/cache/index.js +9 -5
- package/dist/cjs/cli/alias.js +9 -5
- package/dist/cjs/cli/code.js +9 -5
- package/dist/cjs/cli/constants.js +20 -16
- package/dist/cjs/cli/entry.js +9 -5
- package/dist/cjs/cli/index.js +9 -5
- package/dist/cjs/cli/ssr/index.js +14 -20
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +9 -5
- package/dist/cjs/cli/ssr/mode.js +12 -8
- package/dist/cjs/cli/template.js +9 -5
- package/dist/cjs/cli/template.server.js +10 -5
- package/dist/cjs/common.js +14 -10
- package/dist/cjs/core/browser/hydrate.js +9 -5
- package/dist/cjs/core/browser/index.js +9 -5
- package/dist/cjs/core/browser/withCallback.js +9 -5
- package/dist/cjs/core/compat/hooks.js +14 -10
- package/dist/cjs/core/compat/index.js +9 -5
- package/dist/cjs/core/compat/requestContext.js +13 -9
- package/dist/cjs/core/config.js +12 -8
- package/dist/cjs/core/constants.js +15 -10
- package/dist/cjs/core/context/index.js +9 -5
- package/dist/cjs/core/context/monitors/default.js +12 -8
- package/dist/cjs/core/context/monitors/index.js +9 -5
- package/dist/cjs/core/context/monitors/index.server.js +9 -5
- package/dist/cjs/core/context/request/index.js +12 -8
- package/dist/cjs/core/context/request/index.server.js +9 -5
- package/dist/cjs/core/context/response/index.js +15 -11
- package/dist/cjs/core/context/response/index.server.js +9 -5
- package/dist/cjs/core/context/runtime.js +9 -5
- package/dist/cjs/core/context/serverPayload/index.js +13 -9
- package/dist/cjs/core/context/serverPayload/index.server.js +9 -5
- package/dist/cjs/core/index.js +9 -5
- package/dist/cjs/core/plugin/index.js +9 -5
- package/dist/cjs/core/react/index.js +9 -5
- package/dist/cjs/core/react/wrapper.js +18 -8
- package/dist/cjs/core/server/constants.js +15 -11
- package/dist/cjs/core/server/federatedCss.js +51 -0
- package/dist/cjs/core/server/helmet.js +17 -7
- package/dist/cjs/core/server/index.js +9 -5
- package/dist/cjs/core/server/react/index.js +9 -5
- package/dist/cjs/core/server/react/no-ssr-cache/index.js +9 -5
- package/dist/cjs/core/server/react/nossr/index.js +9 -5
- package/dist/cjs/core/server/requestHandler.js +9 -5
- package/dist/cjs/core/server/scriptOrder.js +63 -0
- package/dist/cjs/core/server/server.js +9 -5
- package/dist/cjs/core/server/shared.js +12 -8
- package/dist/cjs/core/server/stream/afterTemplate.js +22 -10
- package/dist/cjs/core/server/stream/beforeTemplate.js +22 -25
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +102 -0
- package/dist/cjs/core/server/stream/createReadableStream.js +16 -7
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +13 -7
- package/dist/cjs/core/server/stream/deferredScript.js +9 -5
- package/dist/cjs/core/server/stream/index.js +9 -5
- package/dist/cjs/core/server/stream/shared.js +12 -6
- package/dist/cjs/core/server/stream/template.js +9 -5
- package/dist/cjs/core/server/string/index.js +25 -14
- package/dist/cjs/core/server/string/loadable.js +83 -15
- package/dist/cjs/core/server/string/ssrData.js +9 -5
- package/dist/cjs/core/server/tracer.js +13 -9
- package/dist/cjs/core/server/utils.js +9 -5
- package/dist/cjs/document/Body.js +9 -5
- package/dist/cjs/document/Comment.js +9 -5
- package/dist/cjs/document/DocumentContext.js +9 -5
- package/dist/cjs/document/DocumentStructureContext.js +9 -5
- package/dist/cjs/document/Head.js +9 -5
- package/dist/cjs/document/Html.js +9 -5
- package/dist/cjs/document/Links.js +9 -5
- package/dist/cjs/document/Root.js +9 -5
- package/dist/cjs/document/Script.js +9 -5
- package/dist/cjs/document/Scripts.js +9 -5
- package/dist/cjs/document/Style.js +9 -5
- package/dist/cjs/document/Title.js +9 -5
- package/dist/cjs/document/cli/index.js +12 -6
- package/dist/cjs/document/constants.js +9 -5
- package/dist/cjs/document/index.js +9 -5
- package/dist/cjs/exports/config-routes.js +12 -8
- package/dist/cjs/exports/head.js +209 -10
- package/dist/cjs/exports/loadable.js +51 -12
- package/dist/cjs/exports/tanstack-router.js +320 -59
- package/dist/cjs/index.js +9 -5
- package/dist/cjs/internal.js +9 -5
- package/dist/cjs/react-server.js +9 -5
- package/dist/cjs/router/cli/code/getClientRoutes/getRoutes.js +9 -5
- package/dist/cjs/router/cli/code/getClientRoutes/index.js +9 -5
- package/dist/cjs/router/cli/code/getClientRoutes/utils.js +9 -5
- package/dist/cjs/router/cli/code/index.js +9 -5
- package/dist/cjs/router/cli/code/inspect.js +9 -5
- package/dist/cjs/router/cli/code/makeLegalIdentifier.js +12 -8
- package/dist/cjs/router/cli/code/nestedRoutes.js +9 -5
- package/dist/cjs/router/cli/code/tanstackTypes.js +125 -56
- package/dist/cjs/router/cli/code/templates.js +24 -14
- package/dist/cjs/router/cli/code/utils.js +9 -5
- package/dist/cjs/router/cli/config-routes/converter.js +9 -5
- package/dist/cjs/router/cli/config-routes/parseRouteConfig.js +9 -5
- package/dist/cjs/router/cli/constants.js +23 -19
- package/dist/cjs/router/cli/entry.js +9 -5
- package/dist/cjs/router/cli/handler.js +9 -5
- package/dist/cjs/router/cli/index.js +9 -5
- package/dist/cjs/router/index.js +9 -5
- package/dist/cjs/router/internal.js +12 -8
- package/dist/cjs/router/runtime/CSSLinks.js +9 -5
- package/dist/cjs/router/runtime/DefaultNotFound.js +9 -5
- package/dist/cjs/router/runtime/DeferredDataScripts.js +12 -8
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +9 -5
- package/dist/cjs/router/runtime/PrefetchLink.js +162 -26
- package/dist/cjs/router/runtime/constants.js +9 -5
- package/dist/cjs/router/runtime/hooks.js +9 -5
- package/dist/cjs/router/runtime/index.js +15 -10
- package/dist/cjs/router/runtime/internal.js +9 -5
- package/dist/cjs/router/runtime/lifecycle.js +18 -14
- package/dist/cjs/router/runtime/plugin.js +9 -5
- package/dist/cjs/router/runtime/plugin.node.js +9 -5
- package/dist/cjs/router/runtime/routerHelper.js +9 -5
- package/dist/cjs/router/runtime/rsc-router.js +9 -5
- package/dist/cjs/router/runtime/rsc.js +9 -5
- package/dist/cjs/router/runtime/server.js +9 -5
- package/dist/cjs/router/runtime/tanstack/basepathRewrite.js +12 -8
- package/dist/cjs/router/runtime/tanstack/dataMutation.js +9 -5
- package/dist/cjs/router/runtime/tanstack/hydrationBoundary.js +48 -0
- package/dist/cjs/router/runtime/tanstack/outlet.js +58 -0
- package/dist/cjs/router/runtime/tanstack/plugin.js +199 -96
- package/dist/cjs/router/runtime/tanstack/plugin.node.js +13 -19
- package/dist/cjs/router/runtime/tanstack/prefetchLink.js +10 -6
- package/dist/cjs/router/runtime/tanstack/routeTree.js +73 -17
- package/dist/cjs/router/runtime/tanstack/rsc/ClientSlot.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/CompositeComponent.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/ReplayableStream.js +14 -9
- package/dist/cjs/router/runtime/tanstack/rsc/RscNodeRenderer.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/SlotContext.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/client.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/createRscProxy.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/index.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/server.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/slotUsageSanitizer.js +9 -5
- package/dist/cjs/router/runtime/tanstack/rsc/symbols.js +20 -15
- package/dist/cjs/router/runtime/utils.js +9 -5
- package/dist/cjs/router/runtime/withRouter.js +9 -5
- package/dist/cjs/rsc/client.js +12 -8
- package/dist/cjs/rsc/server.js +9 -5
- package/dist/cjs/rsc/server.worker.js +62 -0
- package/dist/cjs/ssr/index.node.js +13 -9
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +9 -5
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +18 -13
- package/dist/cjs/ssr/serverRender/types.js +9 -5
- package/dist/esm/boundary-debugger/index.mjs +263 -0
- package/dist/esm/cli/ssr/index.mjs +5 -15
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/react/wrapper.mjs +9 -3
- package/dist/esm/core/server/federatedCss.mjs +13 -0
- package/dist/esm/core/server/helmet.mjs +5 -2
- package/dist/esm/core/server/scriptOrder.mjs +25 -0
- package/dist/esm/core/server/stream/afterTemplate.mjs +14 -6
- package/dist/esm/core/server/stream/beforeTemplate.mjs +14 -11
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +64 -0
- package/dist/esm/core/server/stream/createReadableStream.mjs +7 -2
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm/core/server/stream/shared.mjs +3 -1
- package/dist/esm/core/server/string/index.mjs +17 -9
- package/dist/esm/core/server/string/loadable.mjs +70 -9
- package/dist/esm/document/cli/index.mjs +3 -1
- package/dist/esm/exports/head.mjs +193 -4
- package/dist/esm/exports/loadable.mjs +26 -3
- package/dist/esm/exports/tanstack-router.mjs +2 -1
- package/dist/esm/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm/router/cli/code/templates.mjs +15 -9
- package/dist/esm/router/runtime/PrefetchLink.mjs +153 -21
- package/dist/esm/router/runtime/tanstack/hydrationBoundary.mjs +10 -0
- package/dist/esm/router/runtime/tanstack/outlet.mjs +17 -0
- package/dist/esm/router/runtime/tanstack/plugin.mjs +193 -94
- package/dist/esm/router/runtime/tanstack/plugin.node.mjs +5 -15
- package/dist/esm/router/runtime/tanstack/prefetchLink.mjs +1 -1
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +65 -13
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/esm-node/boundary-debugger/index.mjs +264 -0
- package/dist/esm-node/cli/ssr/index.mjs +5 -15
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/core/react/wrapper.mjs +9 -3
- package/dist/esm-node/core/server/federatedCss.mjs +14 -0
- package/dist/esm-node/core/server/helmet.mjs +5 -2
- package/dist/esm-node/core/server/scriptOrder.mjs +26 -0
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +14 -6
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +14 -11
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +65 -0
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +7 -2
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm-node/core/server/stream/shared.mjs +3 -1
- package/dist/esm-node/core/server/string/index.mjs +17 -9
- package/dist/esm-node/core/server/string/loadable.mjs +70 -9
- package/dist/esm-node/document/cli/index.mjs +3 -1
- package/dist/esm-node/exports/head.mjs +193 -4
- package/dist/esm-node/exports/loadable.mjs +26 -3
- package/dist/esm-node/exports/tanstack-router.mjs +2 -1
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm-node/router/cli/code/templates.mjs +15 -9
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +153 -21
- package/dist/esm-node/router/runtime/tanstack/hydrationBoundary.mjs +11 -0
- package/dist/esm-node/router/runtime/tanstack/outlet.mjs +18 -0
- package/dist/esm-node/router/runtime/tanstack/plugin.mjs +193 -94
- package/dist/esm-node/router/runtime/tanstack/plugin.node.mjs +5 -15
- package/dist/esm-node/router/runtime/tanstack/prefetchLink.mjs +1 -1
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +65 -13
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/esm-node/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/dist/types/cli/entry.d.ts +2 -2
- package/dist/types/core/context/response/index.server.d.ts +4 -1
- package/dist/types/core/context/runtime.d.ts +4 -0
- package/dist/types/core/plugin/index.d.ts +1 -1
- package/dist/types/core/server/federatedCss.d.ts +5 -0
- package/dist/types/core/server/helmet.d.ts +5 -3
- package/dist/types/core/server/scriptOrder.d.ts +1 -0
- package/dist/types/core/server/stream/beforeTemplate.d.ts +1 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +10 -0
- package/dist/types/core/server/stream/shared.d.ts +8 -0
- package/dist/types/core/server/string/loadable.d.ts +11 -0
- package/dist/types/core/server/utils.d.ts +11 -1
- package/dist/types/document/constants.d.ts +3 -1
- package/dist/types/exports/head.d.ts +10 -3
- package/dist/types/exports/loadable.d.ts +8 -1
- package/dist/types/exports/tanstack-router.d.ts +3 -1
- package/dist/types/router/cli/code/utils.d.ts +1 -1
- package/dist/types/router/cli/entry.d.ts +1 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +5 -1
- package/dist/types/router/runtime/tanstack/hydrationBoundary.d.ts +2 -0
- package/dist/types/router/runtime/tanstack/outlet.d.ts +2 -0
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +31 -25
|
@@ -10,45 +10,142 @@ function composeEventHandlers(theirHandler, ourHandler) {
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const DEFAULT_PREFETCH_BEHAVIOR = 'render';
|
|
14
|
+
const DEFAULT_PRELOAD_BEHAVIOR = 'viewport';
|
|
15
|
+
const INTENT_DELAY = 100;
|
|
16
|
+
const VIEWPORT_ROOT_MARGIN = '200px';
|
|
17
|
+
const MAX_CONCURRENT_WARMUPS = 4;
|
|
18
|
+
const WARMUP_TTL = 30000;
|
|
19
|
+
const SLOW_EFFECTIVE_TYPES = new Set([
|
|
20
|
+
'slow-2g',
|
|
21
|
+
'2g'
|
|
22
|
+
]);
|
|
23
|
+
const warmupCache = new Map();
|
|
24
|
+
const warmupQueue = [];
|
|
25
|
+
let activeWarmups = 0;
|
|
26
|
+
const getWarmupTimestamp = ()=>performance.now();
|
|
27
|
+
const getConnection = ()=>{
|
|
28
|
+
const nav = globalThis.navigator;
|
|
29
|
+
return nav?.connection || nav?.mozConnection || nav?.webkitConnection;
|
|
30
|
+
};
|
|
31
|
+
const shouldWarmupOnCurrentNetwork = ()=>{
|
|
32
|
+
const connection = getConnection();
|
|
33
|
+
if (connection?.saveData) return false;
|
|
34
|
+
if ('string' == typeof connection?.effectiveType && SLOW_EFFECTIVE_TYPES.has(connection.effectiveType)) return false;
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
37
|
+
const pruneWarmupCache = (now = getWarmupTimestamp())=>{
|
|
38
|
+
for (const [key, timestamp] of warmupCache)if (now - timestamp > WARMUP_TTL) warmupCache.delete(key);
|
|
39
|
+
};
|
|
40
|
+
const runNextWarmup = ()=>{
|
|
41
|
+
while(activeWarmups < MAX_CONCURRENT_WARMUPS && warmupQueue.length > 0){
|
|
42
|
+
const task = warmupQueue.shift();
|
|
43
|
+
if (task.cancelled) continue;
|
|
44
|
+
activeWarmups += 1;
|
|
45
|
+
task.run().catch((error)=>{
|
|
46
|
+
console.error(error);
|
|
47
|
+
warmupCache.delete(task.key);
|
|
48
|
+
}).finally(()=>{
|
|
49
|
+
activeWarmups -= 1;
|
|
50
|
+
runNextWarmup();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const scheduleWarmup = (key, run)=>{
|
|
55
|
+
if (!shouldWarmupOnCurrentNetwork()) return ()=>{};
|
|
56
|
+
pruneWarmupCache();
|
|
57
|
+
if (warmupCache.has(key)) return ()=>{};
|
|
58
|
+
warmupCache.set(key, getWarmupTimestamp());
|
|
59
|
+
const task = {
|
|
60
|
+
key,
|
|
61
|
+
run,
|
|
62
|
+
cancelled: false
|
|
63
|
+
};
|
|
64
|
+
warmupQueue.push(task);
|
|
65
|
+
runNextWarmup();
|
|
66
|
+
return ()=>{
|
|
67
|
+
task.cancelled = true;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const setRef = (ref, value)=>{
|
|
71
|
+
if (!ref) return;
|
|
72
|
+
if ('function' == typeof ref) return void ref(value);
|
|
73
|
+
try {
|
|
74
|
+
ref.current = value;
|
|
75
|
+
} catch {}
|
|
76
|
+
};
|
|
77
|
+
const isDataWarmupEnabled = (route)=>{
|
|
78
|
+
const handle = route.handle;
|
|
79
|
+
return handle?.navigationWarmup?.data === true;
|
|
80
|
+
};
|
|
81
|
+
function usePrefetchBehavior(prefetch, preload, theirElementProps) {
|
|
82
|
+
const [maybeWarmup, setMaybeWarmup] = react.useState(false);
|
|
15
83
|
const [shouldPrefetch, setShouldPrefetch] = react.useState(false);
|
|
84
|
+
const [shouldPreload, setShouldPreload] = react.useState(false);
|
|
85
|
+
const [viewportElement, setViewportElement] = react.useState(null);
|
|
16
86
|
const { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
|
17
87
|
react.useEffect(()=>{
|
|
18
88
|
if ('render' === prefetch) setShouldPrefetch(true);
|
|
89
|
+
if ('render' === preload) setShouldPreload(true);
|
|
19
90
|
}, [
|
|
20
|
-
prefetch
|
|
91
|
+
prefetch,
|
|
92
|
+
preload
|
|
21
93
|
]);
|
|
22
94
|
const setIntent = ()=>{
|
|
23
|
-
if ('intent' === prefetch)
|
|
95
|
+
if ('intent' === prefetch || 'intent' === preload) setMaybeWarmup(true);
|
|
24
96
|
};
|
|
25
97
|
const cancelIntent = ()=>{
|
|
26
|
-
if ('intent' === prefetch) {
|
|
27
|
-
|
|
98
|
+
if ('intent' === prefetch || 'intent' === preload) {
|
|
99
|
+
setMaybeWarmup(false);
|
|
28
100
|
setShouldPrefetch(false);
|
|
101
|
+
setShouldPreload(false);
|
|
29
102
|
}
|
|
30
103
|
};
|
|
31
104
|
react.useEffect(()=>{
|
|
32
|
-
if (
|
|
105
|
+
if (maybeWarmup) {
|
|
33
106
|
const id = setTimeout(()=>{
|
|
34
|
-
setShouldPrefetch(true);
|
|
35
|
-
|
|
107
|
+
if ('intent' === prefetch) setShouldPrefetch(true);
|
|
108
|
+
if ('intent' === preload) setShouldPreload(true);
|
|
109
|
+
}, INTENT_DELAY);
|
|
36
110
|
return ()=>{
|
|
37
111
|
clearTimeout(id);
|
|
38
112
|
};
|
|
39
113
|
}
|
|
40
114
|
}, [
|
|
41
|
-
|
|
115
|
+
maybeWarmup,
|
|
116
|
+
prefetch,
|
|
117
|
+
preload
|
|
118
|
+
]);
|
|
119
|
+
react.useEffect(()=>{
|
|
120
|
+
if (!viewportElement || 'viewport' !== prefetch && 'viewport' !== preload || "u" < typeof IntersectionObserver) return;
|
|
121
|
+
const observer = new IntersectionObserver((entries)=>{
|
|
122
|
+
if (!entries.some((entry)=>entry.isIntersecting)) return;
|
|
123
|
+
if ('viewport' === prefetch) setShouldPrefetch(true);
|
|
124
|
+
if ('viewport' === preload) setShouldPreload(true);
|
|
125
|
+
observer.disconnect();
|
|
126
|
+
}, {
|
|
127
|
+
rootMargin: VIEWPORT_ROOT_MARGIN
|
|
128
|
+
});
|
|
129
|
+
observer.observe(viewportElement);
|
|
130
|
+
return ()=>{
|
|
131
|
+
observer.disconnect();
|
|
132
|
+
};
|
|
133
|
+
}, [
|
|
134
|
+
prefetch,
|
|
135
|
+
preload,
|
|
136
|
+
viewportElement
|
|
42
137
|
]);
|
|
43
138
|
return [
|
|
44
139
|
shouldPrefetch,
|
|
140
|
+
shouldPreload,
|
|
45
141
|
{
|
|
46
142
|
onFocus: composeEventHandlers(onFocus, setIntent),
|
|
47
143
|
onBlur: composeEventHandlers(onBlur, cancelIntent),
|
|
48
144
|
onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
|
|
49
145
|
onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
|
50
146
|
onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
|
51
|
-
}
|
|
147
|
+
},
|
|
148
|
+
setViewportElement
|
|
52
149
|
];
|
|
53
150
|
}
|
|
54
151
|
async function loadRouteModule(route, routeAssets) {
|
|
@@ -83,14 +180,34 @@ const getDataHref = (route, pathname, basename)=>{
|
|
|
83
180
|
const url = getRequestUrl(path, id);
|
|
84
181
|
return createDataHref(url.toString());
|
|
85
182
|
};
|
|
86
|
-
const PrefetchPageLinks = ({ path })=>{
|
|
183
|
+
const PrefetchPageLinks = ({ path, includeData })=>{
|
|
87
184
|
const { pathname } = path;
|
|
88
185
|
const context = useContext(InternalRuntimeContext);
|
|
89
186
|
const { routeManifest, routes } = context;
|
|
90
187
|
const { routeAssets } = routeManifest || {};
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
188
|
+
const allowNetworkWarmup = shouldWarmupOnCurrentNetwork();
|
|
189
|
+
const matches = useMemo(()=>Array.isArray(routes) ? matchRoutes(routes, pathname) : [], [
|
|
190
|
+
pathname,
|
|
191
|
+
routes
|
|
192
|
+
]);
|
|
193
|
+
react.useEffect(()=>{
|
|
194
|
+
if (!allowNetworkWarmup || !Array.isArray(matches) || !routeAssets || !__webpack_chunk_load__) return;
|
|
195
|
+
const cancellations = matches.map((match)=>{
|
|
196
|
+
const routeId = match.route.id;
|
|
197
|
+
const routeAsset = routeId ? routeAssets[routeId] : void 0;
|
|
198
|
+
const chunkIds = routeAsset?.chunkIds;
|
|
199
|
+
if (!routeId || !Array.isArray(chunkIds) || 0 === chunkIds.length) return ()=>{};
|
|
200
|
+
return scheduleWarmup(`route-module:${routeId}:${chunkIds.join(',')}`, ()=>loadRouteModule(match.route, routeAssets));
|
|
201
|
+
});
|
|
202
|
+
return ()=>{
|
|
203
|
+
cancellations.forEach((cancel)=>cancel());
|
|
204
|
+
};
|
|
205
|
+
}, [
|
|
206
|
+
allowNetworkWarmup,
|
|
207
|
+
matches,
|
|
208
|
+
routeAssets
|
|
209
|
+
]);
|
|
210
|
+
if (!allowNetworkWarmup || !includeData || !window._SSR_DATA) return null;
|
|
94
211
|
return /*#__PURE__*/ jsx(PrefetchDataLinks, {
|
|
95
212
|
matches: matches,
|
|
96
213
|
path: path,
|
|
@@ -102,7 +219,7 @@ const PrefetchDataLinks = ({ matches, path, routeManifest })=>{
|
|
|
102
219
|
const currentMatches = useMatches();
|
|
103
220
|
const basename = useHref('/');
|
|
104
221
|
const dataHrefs = useMemo(()=>matches?.filter((match, index)=>{
|
|
105
|
-
if (!match.route.loader || 'function' != typeof match.route.loader || 0 === match.route.loader.length) return false;
|
|
222
|
+
if (!isDataWarmupEnabled(match.route) || !match.route.loader || 'function' != typeof match.route.loader || 0 === match.route.loader.length) return false;
|
|
106
223
|
if (match.route.shouldRevalidate) {
|
|
107
224
|
const currentUrl = new URL(location.pathname + location.search + location.hash, window.origin);
|
|
108
225
|
const nextUrl = new URL(pathname + search + hash, window.origin);
|
|
@@ -129,20 +246,35 @@ const PrefetchDataLinks = ({ matches, path, routeManifest })=>{
|
|
|
129
246
|
children: dataHrefs
|
|
130
247
|
});
|
|
131
248
|
};
|
|
132
|
-
const
|
|
249
|
+
const normalizePreloadBehavior = (preload, prefetch)=>{
|
|
250
|
+
if (false === preload || 'none' === preload) return 'none';
|
|
251
|
+
if (void 0 !== preload) return preload;
|
|
252
|
+
if ('none' === prefetch) return 'none';
|
|
253
|
+
return DEFAULT_PRELOAD_BEHAVIOR;
|
|
254
|
+
};
|
|
255
|
+
const createPrefetchLink = (Link)=>/*#__PURE__*/ react.forwardRef(({ to, prefetch = DEFAULT_PREFETCH_BEHAVIOR, preload, ...props }, forwardedRef)=>{
|
|
133
256
|
const isAbsolute = 'string' == typeof to && ABSOLUTE_URL_REGEX.test(to);
|
|
134
|
-
const
|
|
257
|
+
const resolvedPreload = normalizePreloadBehavior(preload, prefetch);
|
|
258
|
+
const [shouldPrefetch, shouldPreload, prefetchHandlers, setViewportElement] = usePrefetchBehavior(prefetch, resolvedPreload, props);
|
|
259
|
+
const setAnchorRef = react.useCallback((element)=>{
|
|
260
|
+
setViewportElement(element);
|
|
261
|
+
setRef(forwardedRef, element);
|
|
262
|
+
}, [
|
|
263
|
+
forwardedRef,
|
|
264
|
+
setViewportElement
|
|
265
|
+
]);
|
|
135
266
|
const resolvedPath = useResolvedPath(to);
|
|
136
267
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
137
268
|
children: [
|
|
138
269
|
/*#__PURE__*/ jsx(Link, {
|
|
139
|
-
ref:
|
|
270
|
+
ref: setAnchorRef,
|
|
140
271
|
to: to,
|
|
141
272
|
...props,
|
|
142
273
|
...prefetchHandlers
|
|
143
274
|
}),
|
|
144
|
-
shouldPrefetch
|
|
145
|
-
path: resolvedPath
|
|
275
|
+
(shouldPrefetch || shouldPreload) && !isAbsolute ? /*#__PURE__*/ jsx(PrefetchPageLinks, {
|
|
276
|
+
path: resolvedPath,
|
|
277
|
+
includeData: shouldPrefetch
|
|
146
278
|
}) : null
|
|
147
279
|
]
|
|
148
280
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
function wrapTanstackSsrHydrationBoundary(routerContent, shouldWrap) {
|
|
4
|
+
if (shouldWrap) return /*#__PURE__*/ jsx(Suspense, {
|
|
5
|
+
fallback: null,
|
|
6
|
+
children: routerContent
|
|
7
|
+
});
|
|
8
|
+
return routerContent;
|
|
9
|
+
}
|
|
10
|
+
export { wrapTanstackSsrHydrationBoundary };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Outlet } from "@tanstack/react-router";
|
|
3
|
+
import { createElement, memo } from "react";
|
|
4
|
+
const outlet_Outlet = /*#__PURE__*/ memo(function() {
|
|
5
|
+
return /*#__PURE__*/ jsx(Outlet, {});
|
|
6
|
+
});
|
|
7
|
+
function withModernRouteMatchContext(component, _routeId) {
|
|
8
|
+
if (null == component) return component;
|
|
9
|
+
const Component = component;
|
|
10
|
+
const WrappedRouteComponent = (props)=>/*#__PURE__*/ createElement(Component, props);
|
|
11
|
+
const preloadable = component;
|
|
12
|
+
if ('function' == typeof preloadable.load) WrappedRouteComponent.load = preloadable.load.bind(preloadable);
|
|
13
|
+
if ('function' == typeof preloadable.preload) WrappedRouteComponent.preload = preloadable.preload.bind(preloadable);
|
|
14
|
+
else if ('function' == typeof preloadable.load) WrappedRouteComponent.preload = WrappedRouteComponent.load;
|
|
15
|
+
return WrappedRouteComponent;
|
|
16
|
+
}
|
|
17
|
+
export { outlet_Outlet as Outlet, withModernRouteMatchContext };
|
|
@@ -2,15 +2,18 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
3
|
import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
4
4
|
import { RouterProvider, createBrowserHistory, createHashHistory, createRouter, useLocation, useMatches, useNavigate, useRouter } from "@tanstack/react-router";
|
|
5
|
-
import {
|
|
5
|
+
import { hydrate } from "@tanstack/react-router/ssr/client";
|
|
6
|
+
import { useContext, useMemo } from "react";
|
|
6
7
|
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../../core/context/index.mjs";
|
|
7
8
|
import { onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeHydrateRouter } from "../hooks.mjs";
|
|
8
9
|
import { applyRouterRuntimeState } from "../lifecycle.mjs";
|
|
9
10
|
import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
|
|
10
11
|
import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
|
|
12
|
+
import { wrapTanstackSsrHydrationBoundary } from "./hydrationBoundary.mjs";
|
|
13
|
+
import { withModernRouteMatchContext } from "./outlet.mjs";
|
|
14
|
+
import { Link } from "./prefetchLink.mjs";
|
|
11
15
|
import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
|
|
12
16
|
import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
|
|
13
|
-
import * as __rspack_external_react from "react";
|
|
14
17
|
const BLOCKING_SUBSCRIBE_SYMBOL = Symbol.for('@modern-js/plugin-runtime:tanstack-blocking-subscribe');
|
|
15
18
|
const BLOCKING_STATE_SYMBOL = Symbol.for('@modern-js/plugin-runtime:tanstack-blocking-state');
|
|
16
19
|
function normalizeBase(b) {
|
|
@@ -38,6 +41,82 @@ function wrapRouterSubscribeWithBlockState(router, getBlockNavState) {
|
|
|
38
41
|
};
|
|
39
42
|
target[BLOCKING_SUBSCRIBE_SYMBOL] = true;
|
|
40
43
|
}
|
|
44
|
+
const routerHydrationRecords = new WeakMap();
|
|
45
|
+
const routeModulesKey = '_routeModules';
|
|
46
|
+
function pickRouteModuleComponent(routeModule, seen = new Set()) {
|
|
47
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
48
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
49
|
+
if (seen.has(routeModule)) return;
|
|
50
|
+
seen.add(routeModule);
|
|
51
|
+
const module = routeModule;
|
|
52
|
+
for (const candidate of [
|
|
53
|
+
module.default,
|
|
54
|
+
module.Component
|
|
55
|
+
]){
|
|
56
|
+
const component = pickRouteModuleComponent(candidate, seen);
|
|
57
|
+
if (component) return component;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function getCachedRouteModule(routeId) {
|
|
61
|
+
if ("u" < typeof window) return;
|
|
62
|
+
return window[routeModulesKey]?.[routeId];
|
|
63
|
+
}
|
|
64
|
+
function preloadHydratedRouteComponents(router) {
|
|
65
|
+
const preloadableRouter = router;
|
|
66
|
+
const routesById = preloadableRouter.routesById || {};
|
|
67
|
+
const matches = preloadableRouter.stores.matches.get();
|
|
68
|
+
return Promise.all(matches.map((match)=>{
|
|
69
|
+
if (void 0 === match.routeId || '' === match.routeId) return;
|
|
70
|
+
const route = routesById[match.routeId];
|
|
71
|
+
const component = route?.options?.component;
|
|
72
|
+
const preload = component?.load || component?.preload;
|
|
73
|
+
if ('function' != typeof preload) return;
|
|
74
|
+
return Promise.resolve(preload.call(component)).then((routeModule)=>{
|
|
75
|
+
const modernRouteId = route?.options?.staticData?.modernRouteId;
|
|
76
|
+
const cachedRouteModule = 'string' == typeof modernRouteId && '' !== modernRouteId ? getCachedRouteModule(modernRouteId) : void 0;
|
|
77
|
+
const resolvedComponent = pickRouteModuleComponent(cachedRouteModule ?? routeModule);
|
|
78
|
+
if (void 0 !== resolvedComponent && 'string' == typeof modernRouteId && '' !== modernRouteId) route.options.component = withModernRouteMatchContext(resolvedComponent, modernRouteId);
|
|
79
|
+
});
|
|
80
|
+
})).then(()=>void 0);
|
|
81
|
+
}
|
|
82
|
+
function getTanstackSsrHydrationRecord(router) {
|
|
83
|
+
const existingHydrationRecord = routerHydrationRecords.get(router);
|
|
84
|
+
if (void 0 !== existingHydrationRecord) return existingHydrationRecord;
|
|
85
|
+
const hydrationRecord = {
|
|
86
|
+
promise: Promise.resolve(),
|
|
87
|
+
status: 'pending'
|
|
88
|
+
};
|
|
89
|
+
routerHydrationRecords.set(router, hydrationRecord);
|
|
90
|
+
try {
|
|
91
|
+
hydrationRecord.promise = hydrate(router).then((value)=>preloadHydratedRouteComponents(router).then(()=>value)).then((value)=>{
|
|
92
|
+
hydrationRecord.status = 'fulfilled';
|
|
93
|
+
return value;
|
|
94
|
+
}, (error)=>{
|
|
95
|
+
hydrationRecord.status = 'rejected';
|
|
96
|
+
hydrationRecord.error = error;
|
|
97
|
+
throw error;
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
hydrationRecord.status = 'rejected';
|
|
101
|
+
hydrationRecord.error = error;
|
|
102
|
+
hydrationRecord.promise = Promise.reject(error);
|
|
103
|
+
hydrationRecord.promise.catch(()=>{});
|
|
104
|
+
}
|
|
105
|
+
return hydrationRecord;
|
|
106
|
+
}
|
|
107
|
+
function getTanstackSsrHydrationPromise(router) {
|
|
108
|
+
return getTanstackSsrHydrationRecord(router).promise;
|
|
109
|
+
}
|
|
110
|
+
function hasTanstackSsrHydrationRecord(router) {
|
|
111
|
+
return routerHydrationRecords.has(router);
|
|
112
|
+
}
|
|
113
|
+
function ModernRouterClient({ router }) {
|
|
114
|
+
const hydrationRecord = getTanstackSsrHydrationRecord(router);
|
|
115
|
+
if ('rejected' === hydrationRecord.status) throw hydrationRecord.error;
|
|
116
|
+
return /*#__PURE__*/ jsx(RouterProvider, {
|
|
117
|
+
router: router
|
|
118
|
+
});
|
|
119
|
+
}
|
|
41
120
|
function stripSyntheticNotFoundRoute(routes) {
|
|
42
121
|
return routes.filter((route)=>!('*' === route.path && !route.id && !route.loader)).map((route)=>{
|
|
43
122
|
if (!route.children?.length) return route;
|
|
@@ -56,110 +135,131 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
56
135
|
onBeforeHydrateRouter: onBeforeHydrateRouter
|
|
57
136
|
},
|
|
58
137
|
setup: (api)=>{
|
|
59
|
-
api.
|
|
138
|
+
const hooks = api.getHooks();
|
|
139
|
+
let cachedRouteObjects;
|
|
140
|
+
let cachedRouteTree = null;
|
|
141
|
+
let cachedRouter = null;
|
|
142
|
+
let cachedRouterBasepath = null;
|
|
143
|
+
const getMergedConfig = ()=>{
|
|
60
144
|
const pluginConfig = api.getRuntimeConfig();
|
|
61
|
-
|
|
62
|
-
|
|
145
|
+
return merge(pluginConfig.router || {}, userConfig);
|
|
146
|
+
};
|
|
147
|
+
const getRouteObjects = ()=>{
|
|
148
|
+
if (void 0 !== cachedRouteObjects) return cachedRouteObjects;
|
|
149
|
+
const mergedConfig = getMergedConfig();
|
|
150
|
+
const { routesConfig, createRoutes } = mergedConfig;
|
|
151
|
+
const finalRouteConfig = {
|
|
152
|
+
routes: getGlobalRoutes(),
|
|
153
|
+
globalApp: getGlobalLayoutApp(),
|
|
154
|
+
...routesConfig
|
|
155
|
+
};
|
|
156
|
+
const routeObjects = createRoutes ? createRoutes() : createRouteObjectsFromConfig({
|
|
157
|
+
routesConfig: finalRouteConfig
|
|
158
|
+
}) || [];
|
|
159
|
+
const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
|
|
160
|
+
cachedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
|
|
161
|
+
return cachedRouteObjects;
|
|
162
|
+
};
|
|
163
|
+
const getRouteTree = ()=>{
|
|
164
|
+
if (cachedRouteTree) return cachedRouteTree;
|
|
165
|
+
const routeObjects = getRouteObjects();
|
|
166
|
+
if (!routeObjects.length) return null;
|
|
167
|
+
cachedRouteTree = createRouteTreeFromRouteObjects(routeObjects);
|
|
168
|
+
return cachedRouteTree;
|
|
169
|
+
};
|
|
170
|
+
const selectBasePath = (pathname)=>{
|
|
171
|
+
const { serverBase = [] } = getMergedConfig();
|
|
172
|
+
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
173
|
+
return match || '/';
|
|
174
|
+
};
|
|
175
|
+
const getClientBasename = (runtimeContext)=>{
|
|
176
|
+
const { basename = '' } = getMergedConfig();
|
|
177
|
+
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
178
|
+
return '/' === baseUrl ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
179
|
+
};
|
|
180
|
+
const getRouter = (runtimeContext, _basename)=>{
|
|
181
|
+
const routeTree = getRouteTree();
|
|
182
|
+
if (!routeTree) return null;
|
|
183
|
+
const lifecycleContext = {
|
|
184
|
+
framework: 'tanstack',
|
|
185
|
+
phase: 'client-create',
|
|
186
|
+
routes: getRouteObjects(),
|
|
187
|
+
runtimeContext,
|
|
188
|
+
basename: _basename
|
|
189
|
+
};
|
|
190
|
+
hooks.onBeforeCreateRouter.call(lifecycleContext);
|
|
191
|
+
if (cachedRouter && cachedRouterBasepath === _basename) {
|
|
192
|
+
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
193
|
+
hooks.onAfterCreateRouter.call({
|
|
194
|
+
...lifecycleContext,
|
|
195
|
+
router: cachedRouter,
|
|
196
|
+
runtimeContext
|
|
197
|
+
});
|
|
198
|
+
return cachedRouter;
|
|
199
|
+
}
|
|
200
|
+
const mergedConfig = getMergedConfig();
|
|
201
|
+
const { supportHtml5History = true } = mergedConfig;
|
|
202
|
+
const history = supportHtml5History ? createBrowserHistory() : createHashHistory();
|
|
203
|
+
const rewrite = createModernBasepathRewrite(_basename);
|
|
204
|
+
const serializationAdapters = getGlobalEnableRsc() ? getTanstackRscSerializationAdapters() : void 0;
|
|
205
|
+
cachedRouter = createRouter({
|
|
206
|
+
routeTree,
|
|
207
|
+
basepath: '/',
|
|
208
|
+
rewrite,
|
|
209
|
+
history,
|
|
210
|
+
context: {},
|
|
211
|
+
...serializationAdapters ? {
|
|
212
|
+
serializationAdapters
|
|
213
|
+
} : {}
|
|
214
|
+
});
|
|
215
|
+
cachedRouterBasepath = _basename;
|
|
216
|
+
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
217
|
+
hooks.onAfterCreateRouter.call({
|
|
218
|
+
...lifecycleContext,
|
|
219
|
+
router: cachedRouter,
|
|
220
|
+
runtimeContext
|
|
221
|
+
});
|
|
222
|
+
return cachedRouter;
|
|
223
|
+
};
|
|
224
|
+
api.onBeforeRender((context)=>{
|
|
225
|
+
const mergedConfig = getMergedConfig();
|
|
226
|
+
if ("u" > typeof window && void 0 !== window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
|
|
63
227
|
const { ssrContext } = context;
|
|
64
228
|
const currentPathname = normalizePathname(window.location.pathname);
|
|
65
|
-
const initialPathname = ssrContext?.request?.pathname
|
|
66
|
-
if (initialPathname && initialPathname !== currentPathname) {
|
|
229
|
+
const initialPathname = 'string' == typeof ssrContext?.request?.pathname ? normalizePathname(ssrContext.request.pathname) : void 0;
|
|
230
|
+
if (void 0 !== initialPathname && '' !== initialPathname && initialPathname !== currentPathname) {
|
|
67
231
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
68
232
|
console.error(errorMsg);
|
|
69
233
|
window.location.reload();
|
|
70
234
|
}
|
|
71
235
|
}
|
|
72
236
|
context.router = {
|
|
237
|
+
Link: Link,
|
|
73
238
|
useMatches: useMatches,
|
|
74
239
|
useLocation: useLocation,
|
|
75
240
|
useNavigate: useNavigate,
|
|
76
241
|
useRouter: useRouter
|
|
77
242
|
};
|
|
243
|
+
const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
|
|
244
|
+
if (hasSSRBootstrap && getRouteObjects().length > 0) {
|
|
245
|
+
const runtimeContext = context;
|
|
246
|
+
const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
|
|
247
|
+
if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
|
|
248
|
+
}
|
|
78
249
|
});
|
|
79
250
|
api.wrapRoot((App)=>{
|
|
80
|
-
|
|
81
|
-
const { serverBase = [], supportHtml5History = true, basename = '', routesConfig, createRoutes } = mergedConfig;
|
|
82
|
-
const finalRouteConfig = {
|
|
83
|
-
routes: getGlobalRoutes(),
|
|
84
|
-
globalApp: getGlobalLayoutApp(),
|
|
85
|
-
...routesConfig
|
|
86
|
-
};
|
|
87
|
-
if (!finalRouteConfig.routes && !createRoutes) return App;
|
|
88
|
-
const hooks = api.getHooks();
|
|
89
|
-
let cachedRouteObjects;
|
|
90
|
-
const getRouteObjects = ()=>{
|
|
91
|
-
if (void 0 !== cachedRouteObjects) return cachedRouteObjects;
|
|
92
|
-
const routeObjects = createRoutes ? createRoutes() : createRouteObjectsFromConfig({
|
|
93
|
-
routesConfig: finalRouteConfig
|
|
94
|
-
}) || [];
|
|
95
|
-
const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
|
|
96
|
-
cachedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
|
|
97
|
-
return cachedRouteObjects;
|
|
98
|
-
};
|
|
99
|
-
const selectBasePath = (pathname)=>{
|
|
100
|
-
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
101
|
-
return match || '/';
|
|
102
|
-
};
|
|
103
|
-
let cachedRouteTree = null;
|
|
104
|
-
let cachedRouter = null;
|
|
105
|
-
let cachedRouterBasepath = null;
|
|
251
|
+
if (0 === getRouteObjects().length) return App;
|
|
106
252
|
const RouterWrapper = ()=>{
|
|
107
|
-
const runtimeContext =
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const routeTree = (0, __rspack_external_react.useMemo)(()=>{
|
|
111
|
-
if (cachedRouteTree) return cachedRouteTree;
|
|
112
|
-
const routeObjects = getRouteObjects();
|
|
113
|
-
if (!routeObjects.length) return null;
|
|
114
|
-
cachedRouteTree = createRouteTreeFromRouteObjects(routeObjects);
|
|
115
|
-
return cachedRouteTree;
|
|
116
|
-
}, []);
|
|
253
|
+
const runtimeContext = useContext(InternalRuntimeContext);
|
|
254
|
+
const _basename = getClientBasename(runtimeContext);
|
|
255
|
+
const routeTree = useMemo(()=>getRouteTree(), []);
|
|
117
256
|
if (!routeTree) return App ? /*#__PURE__*/ jsx(App, {}) : null;
|
|
118
|
-
const router =
|
|
119
|
-
const lifecycleContext = {
|
|
120
|
-
framework: 'tanstack',
|
|
121
|
-
phase: 'client-create',
|
|
122
|
-
routes: getRouteObjects(),
|
|
123
|
-
runtimeContext,
|
|
124
|
-
basename: _basename
|
|
125
|
-
};
|
|
126
|
-
hooks.onBeforeCreateRouter.call(lifecycleContext);
|
|
127
|
-
if (cachedRouter && cachedRouterBasepath === _basename) {
|
|
128
|
-
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
129
|
-
hooks.onAfterCreateRouter.call({
|
|
130
|
-
...lifecycleContext,
|
|
131
|
-
router: cachedRouter,
|
|
132
|
-
runtimeContext
|
|
133
|
-
});
|
|
134
|
-
return cachedRouter;
|
|
135
|
-
}
|
|
136
|
-
const history = supportHtml5History ? createBrowserHistory() : createHashHistory();
|
|
137
|
-
const rewrite = createModernBasepathRewrite(_basename);
|
|
138
|
-
const serializationAdapters = getGlobalEnableRsc() ? getTanstackRscSerializationAdapters() : void 0;
|
|
139
|
-
cachedRouter = createRouter({
|
|
140
|
-
routeTree,
|
|
141
|
-
basepath: '/',
|
|
142
|
-
rewrite,
|
|
143
|
-
history,
|
|
144
|
-
context: {},
|
|
145
|
-
...serializationAdapters ? {
|
|
146
|
-
serializationAdapters
|
|
147
|
-
} : {}
|
|
148
|
-
});
|
|
149
|
-
cachedRouterBasepath = _basename;
|
|
150
|
-
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
151
|
-
hooks.onAfterCreateRouter.call({
|
|
152
|
-
...lifecycleContext,
|
|
153
|
-
router: cachedRouter,
|
|
154
|
-
runtimeContext
|
|
155
|
-
});
|
|
156
|
-
return cachedRouter;
|
|
157
|
-
}, [
|
|
257
|
+
const router = useMemo(()=>getRouter(runtimeContext, _basename), [
|
|
158
258
|
_basename,
|
|
159
259
|
routeTree,
|
|
160
|
-
supportHtml5History,
|
|
161
260
|
runtimeContext
|
|
162
261
|
]);
|
|
262
|
+
if (!router) return App ? /*#__PURE__*/ jsx(App, {}) : null;
|
|
163
263
|
const runtimeState = applyRouterRuntimeState(runtimeContext, {
|
|
164
264
|
framework: 'tanstack',
|
|
165
265
|
basename: _basename,
|
|
@@ -173,30 +273,29 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
173
273
|
basename: _basename,
|
|
174
274
|
router
|
|
175
275
|
};
|
|
176
|
-
const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
|
|
177
|
-
|
|
276
|
+
const hasSSRBootstrap = "u" > typeof window && (Boolean(window.$_TSR) || hasTanstackSsrHydrationRecord(router));
|
|
277
|
+
const needsRouterClient = hasSSRBootstrap;
|
|
278
|
+
if (needsRouterClient) hooks.onBeforeHydrateRouter.call({
|
|
178
279
|
...lifecycleContext,
|
|
179
280
|
phase: 'hydrate',
|
|
180
281
|
router,
|
|
181
282
|
runtimeContext: runtimeState
|
|
182
283
|
});
|
|
183
|
-
const RouterContent =
|
|
184
|
-
|
|
185
|
-
children: /*#__PURE__*/ jsx(RouterClient, {
|
|
186
|
-
router: router
|
|
187
|
-
})
|
|
284
|
+
const RouterContent = needsRouterClient ? /*#__PURE__*/ jsx(ModernRouterClient, {
|
|
285
|
+
router: router
|
|
188
286
|
}) : /*#__PURE__*/ jsx(RouterProvider, {
|
|
189
287
|
router: router
|
|
190
288
|
});
|
|
191
|
-
|
|
289
|
+
const HydratableRouterContent = wrapTanstackSsrHydrationBoundary(RouterContent, hasSSRBootstrap);
|
|
290
|
+
if (needsRouterClient) hooks.onAfterHydrateRouter.call({
|
|
192
291
|
...lifecycleContext,
|
|
193
292
|
phase: 'hydrate',
|
|
194
293
|
router,
|
|
195
294
|
runtimeContext: runtimeState
|
|
196
295
|
});
|
|
197
296
|
return App ? /*#__PURE__*/ jsx(App, {
|
|
198
|
-
children:
|
|
199
|
-
}) :
|
|
297
|
+
children: HydratableRouterContent
|
|
298
|
+
}) : HydratableRouterContent;
|
|
200
299
|
};
|
|
201
300
|
return RouterWrapper;
|
|
202
301
|
});
|