@bleedingdev/modern-js-runtime 3.9.0-ultramodern.9 → 3.9.3-ultramodern.1
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/cli/code.js +2 -2
- package/dist/cjs/cli/index.js +0 -7
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +2 -0
- package/dist/cjs/cli/template.server.js +1 -2
- package/dist/cjs/core/browser/hydrate.js +3 -9
- package/dist/cjs/core/browser/index.js +4 -5
- package/dist/cjs/core/context/index.js +8 -2
- package/dist/cjs/core/context/public.js +4 -4
- package/dist/cjs/core/context/runtime.js +3 -9
- package/dist/cjs/core/index.js +3 -3
- package/dist/cjs/core/plugin/index.js +2 -2
- package/dist/cjs/core/react/index.js +3 -3
- package/dist/cjs/core/react/wrapper.js +7 -8
- package/dist/cjs/core/server/requestHandler.js +253 -25
- package/dist/cjs/core/server/stream/beforeTemplate.js +3 -3
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +2 -2
- package/dist/cjs/core/server/stream/createReadableStream.js +51 -19
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +54 -27
- package/dist/cjs/core/server/stream/deferredScript.js +12 -6
- package/dist/cjs/core/server/stream/deferredScriptOutputCoordinator.js +370 -0
- package/dist/cjs/core/server/stream/shared.js +4 -0
- package/dist/cjs/core/server/string/index.js +6 -4
- package/dist/cjs/core/server/string/loadable.js +4 -4
- package/dist/cjs/document/cli/index.js +14 -5
- package/dist/cjs/exports/head.js +2 -2
- package/dist/cjs/internal.js +2 -2
- package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
- package/dist/cjs/router/cli/code/templates.js +2 -2
- package/dist/cjs/router/cli/code/utils.js +5 -4
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +13 -10
- package/dist/cjs/router/runtime/PrefetchLink.js +4 -4
- package/dist/cjs/router/runtime/hooks.js +6 -7
- package/dist/cjs/router/runtime/plugin.js +22 -27
- package/dist/cjs/router/runtime/plugin.node.js +8 -9
- package/dist/esm/cli/code.mjs +2 -2
- package/dist/esm/cli/index.mjs +0 -7
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +2 -0
- package/dist/esm/cli/template.server.mjs +1 -2
- package/dist/esm/core/browser/hydrate.mjs +3 -9
- package/dist/esm/core/browser/index.mjs +1 -2
- package/dist/esm/core/context/index.mjs +1 -1
- package/dist/esm/core/context/public.mjs +1 -1
- package/dist/esm/core/context/runtime.mjs +3 -9
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/core/plugin/index.mjs +1 -1
- package/dist/esm/core/react/index.mjs +1 -1
- package/dist/esm/core/react/wrapper.mjs +1 -2
- package/dist/esm/core/server/requestHandler.mjs +223 -19
- package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +2 -2
- package/dist/esm/core/server/stream/createReadableStream.mjs +48 -16
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +53 -26
- package/dist/esm/core/server/stream/deferredScript.mjs +12 -6
- package/dist/esm/core/server/stream/deferredScriptOutputCoordinator.mjs +332 -0
- package/dist/esm/core/server/stream/shared.mjs +2 -1
- package/dist/esm/core/server/string/index.mjs +3 -1
- package/dist/esm/core/server/string/loadable.mjs +4 -4
- package/dist/esm/document/cli/index.mjs +12 -6
- package/dist/esm/exports/head.mjs +1 -1
- package/dist/esm/internal.mjs +1 -1
- package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm/router/cli/code/templates.mjs +2 -2
- package/dist/esm/router/cli/code/utils.mjs +6 -5
- package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +13 -10
- package/dist/esm/router/runtime/PrefetchLink.mjs +1 -1
- package/dist/esm/router/runtime/hooks.mjs +6 -7
- package/dist/esm/router/runtime/plugin.mjs +14 -19
- package/dist/esm/router/runtime/plugin.node.mjs +3 -4
- package/dist/esm-node/cli/code.mjs +2 -2
- package/dist/esm-node/cli/index.mjs +1 -9
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +2 -0
- package/dist/esm-node/cli/template.server.mjs +1 -2
- package/dist/esm-node/core/browser/hydrate.mjs +3 -9
- package/dist/esm-node/core/browser/index.mjs +1 -2
- package/dist/esm-node/core/context/index.mjs +1 -1
- package/dist/esm-node/core/context/public.mjs +1 -1
- package/dist/esm-node/core/context/runtime.mjs +3 -9
- package/dist/esm-node/core/index.mjs +1 -1
- package/dist/esm-node/core/plugin/index.mjs +1 -1
- package/dist/esm-node/core/react/index.mjs +1 -1
- package/dist/esm-node/core/react/wrapper.mjs +1 -2
- package/dist/esm-node/core/server/requestHandler.mjs +223 -19
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +2 -2
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +48 -16
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +53 -26
- package/dist/esm-node/core/server/stream/deferredScript.mjs +12 -6
- package/dist/esm-node/core/server/stream/deferredScriptOutputCoordinator.mjs +333 -0
- package/dist/esm-node/core/server/stream/shared.mjs +2 -1
- package/dist/esm-node/core/server/string/index.mjs +3 -1
- package/dist/esm-node/core/server/string/loadable.mjs +4 -4
- package/dist/esm-node/document/cli/index.mjs +12 -6
- package/dist/esm-node/exports/head.mjs +1 -1
- package/dist/esm-node/internal.mjs +1 -1
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm-node/router/cli/code/templates.mjs +2 -2
- package/dist/esm-node/router/cli/code/utils.mjs +6 -5
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +13 -10
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +1 -1
- package/dist/esm-node/router/runtime/hooks.mjs +6 -7
- package/dist/esm-node/router/runtime/plugin.mjs +14 -19
- package/dist/esm-node/router/runtime/plugin.node.mjs +3 -4
- package/dist/types/common.d.ts +2 -8
- package/dist/types/core/context/index.d.ts +1 -1
- package/dist/types/core/context/public.d.ts +1 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/react/wrapper.d.ts +1 -1
- package/dist/types/core/server/requestHandler.d.ts +30 -1
- package/dist/types/core/server/stream/deferredScript.d.ts +1 -1
- package/dist/types/core/server/stream/deferredScriptOutputCoordinator.d.ts +72 -0
- package/dist/types/core/server/stream/shared.d.ts +14 -0
- package/dist/types/document/cli/index.d.ts +1 -0
- package/dist/types/internal.d.ts +1 -1
- package/dist/types/router/cli/code/utils.d.ts +1 -1
- package/dist/types/router/runtime/hooks.d.ts +12 -16
- package/package.json +32 -26
- package/rslib.config.mts +3 -0
- package/rstest.config.mts +0 -4
- package/dist/cjs/core/server/requestResponse.js +0 -107
- package/dist/cjs/core/server/routerCleanup.js +0 -129
- package/dist/cjs/rsc/server.worker.js +0 -62
- package/dist/esm/core/server/requestResponse.mjs +0 -63
- package/dist/esm/core/server/routerCleanup.mjs +0 -82
- package/dist/esm/rsc/server.worker.mjs +0 -1
- package/dist/esm-node/core/server/requestResponse.mjs +0 -64
- package/dist/esm-node/core/server/routerCleanup.mjs +0 -83
- package/dist/esm-node/rsc/server.worker.mjs +0 -2
- package/dist/types/core/server/requestResponse.d.ts +0 -15
- package/dist/types/core/server/routerCleanup.d.ts +0 -31
- package/dist/types/rsc/server.worker.d.ts +0 -1
|
@@ -42,8 +42,7 @@ const optimizeRoute = (routeTree)=>{
|
|
|
42
42
|
children: optimizedChildren
|
|
43
43
|
}
|
|
44
44
|
];
|
|
45
|
-
}
|
|
46
|
-
{
|
|
45
|
+
} else {
|
|
47
46
|
const newRoutes = children.map((child)=>{
|
|
48
47
|
const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
|
|
49
48
|
const newRoute = {
|
|
@@ -351,7 +351,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
351
351
|
source: rootLayout.toString(),
|
|
352
352
|
filename: rootLayoutFile
|
|
353
353
|
});
|
|
354
|
-
const hasAppInit = moduleExports.some((e)=>e.
|
|
354
|
+
const hasAppInit = moduleExports.some((e)=>'reexport-all' !== e.type && e.name === APP_INIT_EXPORTED);
|
|
355
355
|
const layoutPath = formatImportPath(getPathWithoutExt(replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias)));
|
|
356
356
|
if (hasAppInit) imports.push(`import { init as appInit } from '${layoutPath}';`);
|
|
357
357
|
else imports.push("let appInit;");
|
|
@@ -377,7 +377,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
377
377
|
enableRsc: true,
|
|
378
378
|
});
|
|
379
379
|
`;
|
|
380
|
-
return `${imports.join('\n')}
|
|
380
|
+
else return `${imports.join('\n')}
|
|
381
381
|
|
|
382
382
|
import { routes } from '${routesImportPath}';
|
|
383
383
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JS_EXTENSIONS, fs, normalizeToPosixPath } from "@modern-js/utils";
|
|
2
|
-
import { parse } from "es-module-lexer";
|
|
2
|
+
import { init, parse } from "es-module-lexer";
|
|
3
3
|
import { transform } from "esbuild";
|
|
4
4
|
import fs_0 from "fs";
|
|
5
5
|
import path from "path";
|
|
@@ -10,7 +10,7 @@ const walkDirectory = (dir)=>fs_0.readdirSync(dir).reduce((previous, filename)=>
|
|
|
10
10
|
...previous,
|
|
11
11
|
...walkDirectory(filePath)
|
|
12
12
|
];
|
|
13
|
-
return [
|
|
13
|
+
else return [
|
|
14
14
|
...previous,
|
|
15
15
|
filePath
|
|
16
16
|
];
|
|
@@ -27,7 +27,7 @@ const isPageComponentFile = (filePath)=>{
|
|
|
27
27
|
};
|
|
28
28
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
29
29
|
if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
30
|
-
return filePath;
|
|
30
|
+
else return filePath;
|
|
31
31
|
};
|
|
32
32
|
const parseModule = async ({ source, filename })=>{
|
|
33
33
|
let content = source;
|
|
@@ -47,6 +47,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
47
47
|
});
|
|
48
48
|
content = result.code;
|
|
49
49
|
}
|
|
50
|
+
await init();
|
|
50
51
|
return parse(content);
|
|
51
52
|
};
|
|
52
53
|
const hasLoader = async (filename, source)=>{
|
|
@@ -57,7 +58,7 @@ const hasLoader = async (filename, source)=>{
|
|
|
57
58
|
source: content.toString(),
|
|
58
59
|
filename
|
|
59
60
|
});
|
|
60
|
-
return moduleExports.some((e)=>e.
|
|
61
|
+
return moduleExports.some((e)=>'reexport-all' !== e.type && e.name === LOADER_EXPORT_NAME);
|
|
61
62
|
}
|
|
62
63
|
return false;
|
|
63
64
|
};
|
|
@@ -69,7 +70,7 @@ const hasAction = async (filename, source)=>{
|
|
|
69
70
|
source: content.toString(),
|
|
70
71
|
filename
|
|
71
72
|
});
|
|
72
|
-
return moduleExports.some((e)=>e.
|
|
73
|
+
return moduleExports.some((e)=>'reexport-all' !== e.type && e.name === ACTION_EXPORT_NAME);
|
|
73
74
|
}
|
|
74
75
|
return false;
|
|
75
76
|
};
|
|
@@ -28,7 +28,8 @@ const DeferredDataScripts = (props)=>{
|
|
|
28
28
|
}, []);
|
|
29
29
|
const deferredScripts = useMemo(()=>{
|
|
30
30
|
if (!staticContext) return null;
|
|
31
|
-
const
|
|
31
|
+
const requestStorage = storage.useContext();
|
|
32
|
+
const activeDeferreds = requestStorage.activeDeferreds;
|
|
32
33
|
const _ROUTER_DATA = {
|
|
33
34
|
loaderData: staticContext.loaderData,
|
|
34
35
|
errors: serializeErrors(staticContext.errors)
|
|
@@ -41,6 +42,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
41
42
|
const deferredDataScripts = [];
|
|
42
43
|
const initialScripts = Array.from(activeDeferreds.entries()).map(([routeId, deferredData])=>{
|
|
43
44
|
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
45
|
+
requestStorage.deferredScriptKeys?.set(routeId, Array.from(pendingKeys));
|
|
44
46
|
const { deferredKeys } = deferredData;
|
|
45
47
|
const deferredKeyPromiseManifests = deferredKeys.map((key)=>{
|
|
46
48
|
if (pendingKeys.has(key)) return {
|
|
@@ -51,7 +53,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
51
53
|
serializeJson(key)
|
|
52
54
|
]
|
|
53
55
|
};
|
|
54
|
-
{
|
|
56
|
+
else {
|
|
55
57
|
const trackedPromise = deferredData.data[key];
|
|
56
58
|
if (void 0 !== trackedPromise._error) {
|
|
57
59
|
const error = toDeferredErrorInfo(trackedPromise._error);
|
|
@@ -63,15 +65,16 @@ const DeferredDataScripts = (props)=>{
|
|
|
63
65
|
serializeJson(error)
|
|
64
66
|
]
|
|
65
67
|
};
|
|
68
|
+
} else {
|
|
69
|
+
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
70
|
+
return {
|
|
71
|
+
key,
|
|
72
|
+
routerDataFnName: 'p',
|
|
73
|
+
routerDataFnArgs: [
|
|
74
|
+
serializeJson(trackedPromise._data)
|
|
75
|
+
]
|
|
76
|
+
};
|
|
66
77
|
}
|
|
67
|
-
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
68
|
-
return {
|
|
69
|
-
key,
|
|
70
|
-
routerDataFnName: 'p',
|
|
71
|
-
routerDataFnArgs: [
|
|
72
|
-
serializeJson(trackedPromise._data)
|
|
73
|
-
]
|
|
74
|
-
};
|
|
75
78
|
}
|
|
76
79
|
});
|
|
77
80
|
return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { InternalRuntimeContext } from "@modern-js/runtime/context";
|
|
3
4
|
import { Link as router_Link, NavLink, matchRoutes, useHref, useMatches, useResolvedPath } from "@modern-js/runtime-utils/router";
|
|
4
5
|
import react, { useContext, useMemo } from "react";
|
|
5
|
-
import { InternalRuntimeContext } from "../../core/context/index.mjs";
|
|
6
6
|
import { __webpack_require__ } from "../../rslib-runtime~1.mjs";
|
|
7
7
|
const getWebpackChunkLoader = ()=>__webpack_chunk_load__;
|
|
8
8
|
const getWebpackPublicPath = ()=>{
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createSyncHook } from "@modern-js/plugin";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const onAfterHydrateRouter = createRouterSyncHook();
|
|
2
|
+
const modifyRoutes = createSyncHook();
|
|
3
|
+
const onBeforeCreateRoutes = createSyncHook();
|
|
4
|
+
const onBeforeCreateRouter = createSyncHook();
|
|
5
|
+
const onAfterCreateRouter = createSyncHook();
|
|
6
|
+
const onBeforeHydrateRouter = createSyncHook();
|
|
7
|
+
const onAfterHydrateRouter = createSyncHook();
|
|
9
8
|
const routerProviderRegistryHooks = {
|
|
10
9
|
modifyRoutes: modifyRoutes,
|
|
11
10
|
onBeforeCreateRoutes: onBeforeCreateRoutes,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRoutes } from "@modern-js/runtime/context";
|
|
2
3
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
4
|
import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useInRouterContext, useLocation, useMatches, useNavigate, useParams } from "@modern-js/runtime-utils/router";
|
|
4
5
|
import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
5
6
|
import * as __rspack_external_react from "react";
|
|
6
|
-
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context/index.mjs";
|
|
7
7
|
import { routerProviderRegistryHooks } from "./hooks.mjs";
|
|
8
8
|
import { Link } from "./PrefetchLink.mjs";
|
|
9
9
|
import { createClientRouterFromPayload } from "./rsc-router.mjs";
|
|
@@ -66,24 +66,20 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
66
66
|
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
67
67
|
return match || '/';
|
|
68
68
|
};
|
|
69
|
-
|
|
69
|
+
const routerCache = new WeakMap();
|
|
70
70
|
const RouterWrapper = (props)=>{
|
|
71
71
|
const routerResult = useRouterCreation(("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === getGlobalEnableRsc()) ? {
|
|
72
72
|
...props,
|
|
73
73
|
rscPayload: props?.rscPayload
|
|
74
74
|
} : props, {
|
|
75
75
|
api: api,
|
|
76
|
+
cache: routerCache,
|
|
76
77
|
createRoutes,
|
|
77
78
|
supportHtml5History,
|
|
78
79
|
selectBasePath,
|
|
79
80
|
basename
|
|
80
81
|
});
|
|
81
|
-
const router =
|
|
82
|
-
if (cachedRouter) return cachedRouter;
|
|
83
|
-
cachedRouter = routerResult.router;
|
|
84
|
-
return cachedRouter;
|
|
85
|
-
}, []);
|
|
86
|
-
const { routes } = routerResult;
|
|
82
|
+
const { router, routes } = routerResult;
|
|
87
83
|
routesContainer.current = routes;
|
|
88
84
|
beforeCreateRouter = false;
|
|
89
85
|
const routerContent = /*#__PURE__*/ jsxs(Fragment, {
|
|
@@ -120,14 +116,15 @@ function isSegmentPrefix(pathname, base) {
|
|
|
120
116
|
return p === b || p.startsWith(`${b}/`);
|
|
121
117
|
}
|
|
122
118
|
function useRouterCreation(props, options) {
|
|
123
|
-
const { api, createRoutes, supportHtml5History, selectBasePath, basename } = options;
|
|
119
|
+
const { api, cache, createRoutes, supportHtml5History, selectBasePath, basename } = options;
|
|
124
120
|
const runtimeContext = (0, __rspack_external_react.useContext)(InternalRuntimeContext);
|
|
125
121
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
126
122
|
const _basename = '/' === baseUrl ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
127
123
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
128
124
|
const rscPayload = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === getGlobalEnableRsc()) && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
129
125
|
let hydrationData = "u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA : true === getGlobalEnableRsc() ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
130
|
-
|
|
126
|
+
const result = (0, __rspack_external_react.useRef)(cache.get(runtimeContext) ?? null);
|
|
127
|
+
if (null === result.current) {
|
|
131
128
|
if (hydrationData?.errors) hydrationData = {
|
|
132
129
|
...hydrationData,
|
|
133
130
|
errors: deserializeErrors(hydrationData.errors)
|
|
@@ -143,10 +140,12 @@ function useRouterCreation(props, options) {
|
|
|
143
140
|
const hooks = api.getHooks();
|
|
144
141
|
if (("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === getGlobalEnableRsc()) && rscPayload) try {
|
|
145
142
|
const router = createClientRouterFromPayload(rscPayload, routes, _basename);
|
|
146
|
-
|
|
143
|
+
result.current = {
|
|
147
144
|
router,
|
|
148
145
|
routes: router.routes || []
|
|
149
146
|
};
|
|
147
|
+
cache.set(runtimeContext, result.current);
|
|
148
|
+
return result.current;
|
|
150
149
|
} catch (e) {
|
|
151
150
|
console.error('Failed to create router from RSC payload:', e);
|
|
152
151
|
}
|
|
@@ -195,16 +194,12 @@ function useRouterCreation(props, options) {
|
|
|
195
194
|
};
|
|
196
195
|
return originSubscribe(wrappedListener);
|
|
197
196
|
};
|
|
198
|
-
|
|
197
|
+
result.current = {
|
|
199
198
|
router,
|
|
200
199
|
routes: modifiedRoutes
|
|
201
200
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
_basename,
|
|
206
|
-
hydrationData,
|
|
207
|
-
getBlockNavState
|
|
208
|
-
]);
|
|
201
|
+
cache.set(runtimeContext, result.current);
|
|
202
|
+
}
|
|
203
|
+
return result.current;
|
|
209
204
|
}
|
|
210
205
|
export { beforeCreateRouter, finalRouteConfig, modifyRoutes, routerPlugin };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "@modern-js/runtime/context";
|
|
2
3
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
4
|
import { createRequestContext } from "@modern-js/runtime-utils/node";
|
|
4
5
|
import { StaticRouterProvider, createRoutesFromElements, createStaticHandler, createStaticRouter, useInRouterContext, useLocation, useNavigate, useParams } from "@modern-js/runtime-utils/router";
|
|
5
6
|
import { time } from "@modern-js/runtime-utils/time";
|
|
6
7
|
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
7
8
|
import { useContext } from "react";
|
|
8
|
-
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context/index.mjs";
|
|
9
9
|
import { setServerPayload } from "../../core/context/serverPayload/index.server.mjs";
|
|
10
10
|
import DeferredDataScripts_node from "./DeferredDataScripts.node.mjs";
|
|
11
11
|
import { routerProviderRegistryHooks } from "./hooks.mjs";
|
|
@@ -15,11 +15,10 @@ import { createRouteObjectsFromConfig, renderRoutes, urlJoin } from "./utils.mjs
|
|
|
15
15
|
function createRemixRequest(request) {
|
|
16
16
|
const method = 'GET';
|
|
17
17
|
const { headers } = request;
|
|
18
|
-
const controller = new AbortController();
|
|
19
18
|
return new Request(request.url, {
|
|
20
19
|
method,
|
|
21
20
|
headers,
|
|
22
|
-
signal:
|
|
21
|
+
signal: request.signal
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
24
|
const routerPlugin = (userConfig = {})=>({
|
|
@@ -123,7 +122,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
123
122
|
}) : /*#__PURE__*/ jsx(RSCStaticRouter, {
|
|
124
123
|
basename: basename
|
|
125
124
|
});
|
|
126
|
-
{
|
|
125
|
+
else {
|
|
127
126
|
const { nonce, mode, useJsonScript } = context.ssrContext;
|
|
128
127
|
const remixRouter = createStaticRouter(routes, routerContext);
|
|
129
128
|
const routerWrapper = /*#__PURE__*/ jsxs(Fragment, {
|
|
@@ -44,7 +44,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
44
44
|
entryName,
|
|
45
45
|
customEntry,
|
|
46
46
|
mountId,
|
|
47
|
-
enableRsc: config.server.rsc,
|
|
47
|
+
enableRsc: Boolean(config.server.rsc),
|
|
48
48
|
isNestedRouter: !!entrypoint.nestedRoutesEntry
|
|
49
49
|
}) : __rspack_external__template_mjs_d1604447.entryForCSRWithRSC({
|
|
50
50
|
metaName,
|
|
@@ -87,7 +87,7 @@ requestHandler.catch(() => {});`, 'utf8');
|
|
|
87
87
|
mode: ssrMode,
|
|
88
88
|
customServerEntry,
|
|
89
89
|
srcDirectory,
|
|
90
|
-
enableRsc: config.server.rsc
|
|
90
|
+
enableRsc: Boolean(config.server.rsc)
|
|
91
91
|
});
|
|
92
92
|
const indexServerFile = path.resolve(internalDirectory, `./${entryName}/${SERVER_ENTRY_POINT_FILE_NAME}`);
|
|
93
93
|
await fs.outputFile(indexServerFile, indexServerCode, 'utf8');
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
-
import { cleanRequireCache } from "@modern-js/utils";
|
|
1
|
+
import "node:module";
|
|
4
2
|
import path_0 from "path";
|
|
5
3
|
import { documentPlugin } from "../document/cli/index.mjs";
|
|
6
4
|
import { getEntrypointRoutesDir, getEntrypointRoutesOwner, handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints, isRouteEntry, routerPlugin, updateNestedRoutesSpec } from "../router/cli/index.mjs";
|
|
@@ -72,12 +70,6 @@ const runtimePlugin = (params)=>({
|
|
|
72
70
|
}
|
|
73
71
|
};
|
|
74
72
|
});
|
|
75
|
-
api.onBeforeRestart(()=>{
|
|
76
|
-
cleanRequireCache([
|
|
77
|
-
require.resolve('../router/cli'),
|
|
78
|
-
require.resolve('./ssr')
|
|
79
|
-
]);
|
|
80
|
-
});
|
|
81
73
|
}
|
|
82
74
|
});
|
|
83
75
|
const cli = runtimePlugin;
|
|
@@ -3,6 +3,7 @@ import { fs } from "@modern-js/utils";
|
|
|
3
3
|
import path_0 from "path";
|
|
4
4
|
const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
|
|
5
5
|
const DEFAULT_CHUNK_LOADING_GLOBAL = '__LOADABLE_LOADED_CHUNKS__';
|
|
6
|
+
const normalizeStatsPublicPath = (publicPath)=>'auto' === publicPath || 'auto/' === publicPath ? '/' : publicPath;
|
|
6
7
|
const normalizeChunkGroup = (group)=>({
|
|
7
8
|
...group,
|
|
8
9
|
chunks: (group.chunks || []).map(normalizeChunkId)
|
|
@@ -45,6 +46,7 @@ class LoadablePlugin {
|
|
|
45
46
|
for (const [name, ep] of Object.entries(stats.entrypoints || {}))entrypoints[name] = normalizeChunkGroup(ep);
|
|
46
47
|
const output = {
|
|
47
48
|
...stats,
|
|
49
|
+
publicPath: normalizeStatsPublicPath(stats.publicPath),
|
|
48
50
|
namedChunkGroups,
|
|
49
51
|
entrypoints,
|
|
50
52
|
generator: 'loadable-components',
|
|
@@ -121,8 +121,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
|
|
|
121
121
|
return `
|
|
122
122
|
export * from '${realEntryPath}';
|
|
123
123
|
export { default as requestHandler } from '${realEntryPath}'`;
|
|
124
|
-
}
|
|
125
|
-
{
|
|
124
|
+
} else {
|
|
126
125
|
const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
|
|
127
126
|
const serverEntry = transformServerEntry(entrySource, {
|
|
128
127
|
metaName: metaName || 'modern-js',
|
|
@@ -30,7 +30,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
30
30
|
if ('stream' === renderMode) return streamSSRHydrate();
|
|
31
31
|
function streamSSRHydrate() {
|
|
32
32
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
33
|
-
{
|
|
33
|
+
else {
|
|
34
34
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
35
35
|
callback: callback,
|
|
36
36
|
children: App
|
|
@@ -46,7 +46,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
46
46
|
return stringSSRHydrate();
|
|
47
47
|
function stringSSRHydrate() {
|
|
48
48
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
49
|
-
{
|
|
49
|
+
else {
|
|
50
50
|
if (renderLevel === RenderLevel.SERVER_RENDER) return loadableReady(()=>void 0, loadableReadyOptions).then(()=>{
|
|
51
51
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
52
52
|
callback: callback,
|
|
@@ -54,13 +54,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
54
54
|
});
|
|
55
55
|
return ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext));
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
if (null !== runtimeConsole && 'object' == typeof runtimeConsole) {
|
|
59
|
-
const warn = Reflect.get(runtimeConsole, 'warn');
|
|
60
|
-
if ('function' == typeof warn) Reflect.apply(warn, runtimeConsole, [
|
|
61
|
-
`unknow render level: ${renderLevel}, execute render()`
|
|
62
|
-
]);
|
|
63
|
-
}
|
|
57
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
64
58
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
65
59
|
}
|
|
66
60
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { getGlobalInternalRuntimeContext, getInitialContext } from "@modern-js/runtime/context";
|
|
2
3
|
import { parseCookie } from "cookie";
|
|
3
4
|
import { createRoot } from "react-dom/client";
|
|
4
|
-
import { getGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
5
|
-
import { getInitialContext } from "../context/runtime.mjs";
|
|
6
5
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
7
6
|
import { hydrateRoot, hydrateWithReact } from "./hydrate.mjs";
|
|
8
7
|
const IS_REACT18 = 'true' === process.env.IS_REACT18;
|
|
@@ -43,6 +43,6 @@ function getGlobalBasename() {
|
|
|
43
43
|
}
|
|
44
44
|
export { DefaultNotFound } from "../../router/runtime/DefaultNotFound.mjs";
|
|
45
45
|
export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, routerProviderRegistryHooks } from "../../router/runtime/hooks.mjs";
|
|
46
|
-
export { InternalRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
46
|
+
export { InternalRuntimeContext, ReactRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext, useRuntimeContext } from "./runtime.mjs";
|
|
47
47
|
export { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
48
48
|
export { getCurrentEntryName, getGlobalApp, getGlobalBasename, getGlobalEnableRsc, getGlobalInternalRuntimeContext, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRSCRoot, getGlobalRoutes, setGlobalContext, setGlobalInternalRuntimeContext };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "
|
|
2
|
+
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "@modern-js/runtime/context";
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { createContext, useContext } from "react";
|
|
3
3
|
const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
contexts[key] ??= create();
|
|
8
|
-
return contexts[key];
|
|
9
|
-
}
|
|
10
|
-
const InternalRuntimeContext = getRuntimeReactContext('internal', ()=>createContext({}));
|
|
11
|
-
const RuntimeContext = getRuntimeReactContext('public', ()=>createContext({}));
|
|
12
|
-
const RuntimeComponentResolverContext = getRuntimeReactContext('component-resolver', ()=>createContext(void 0));
|
|
4
|
+
const InternalRuntimeContext = createContext({});
|
|
5
|
+
const RuntimeContext = createContext({});
|
|
6
|
+
const RuntimeComponentResolverContext = createContext(void 0);
|
|
13
7
|
const ReactRuntimeContext = RuntimeContext;
|
|
14
8
|
const useRuntimeContext = ()=>useContext(RuntimeContext);
|
|
15
9
|
const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { runtime } from "@modern-js/plugin/runtime";
|
|
3
|
+
import { setGlobalInternalRuntimeContext } from "@modern-js/runtime/context";
|
|
3
4
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
4
5
|
import { compatPlugin } from "../compat/index.mjs";
|
|
5
6
|
import { handleSetupResult } from "../compat/hooks.mjs";
|
|
6
7
|
import { requestContextPlugin } from "../compat/requestContext.mjs";
|
|
7
|
-
import { setGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
8
8
|
function registerPlugin(internalPlugins, runtimeConfig) {
|
|
9
9
|
const { plugins = [] } = runtimeConfig || {};
|
|
10
10
|
const { runtimeContext } = runtime.run({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { getGlobalApp, getGlobalInternalRuntimeContext } from "@modern-js/runtime/context";
|
|
2
3
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
3
4
|
import { isBrowser } from "../../common.mjs";
|
|
4
5
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants.mjs";
|
|
5
|
-
import { getGlobalApp, getGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
6
6
|
function createRoot(UserApp) {
|
|
7
7
|
const App = UserApp || getGlobalApp();
|
|
8
8
|
if (isBrowser()) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { InternalRuntimeContext, RuntimeContext, getGlobalEnableRsc, getGlobalInternalRuntimeContext } from "
|
|
4
|
-
import { RuntimeComponentResolverContext } from "../context/runtime.mjs";
|
|
3
|
+
import { InternalRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getGlobalEnableRsc, getGlobalInternalRuntimeContext } from "@modern-js/runtime/context";
|
|
5
4
|
function wrapRuntimeComponentResolver(root, hooks = getGlobalInternalRuntimeContext()?.hooks) {
|
|
6
5
|
return /*#__PURE__*/ jsx(RuntimeComponentResolverContext.Provider, {
|
|
7
6
|
value: hooks?.resolveComponent?.call,
|