@modern-js/runtime 2.6.0 → 2.8.0
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/CHANGELOG.md +53 -0
- package/README.md +2 -2
- package/dist/cjs/cli/index.js +4 -3
- package/dist/cjs/common.js +6 -0
- package/dist/cjs/core/{app-config.js → appConfig.js} +3 -3
- package/dist/cjs/core/compatible.js +4 -4
- package/dist/cjs/core/index.js +6 -6
- package/dist/cjs/core/loader/useLoader.js +2 -2
- package/dist/cjs/core/types.js +15 -0
- package/dist/cjs/router/runtime/DeferredDataScripts.js +165 -0
- package/dist/cjs/router/runtime/index.js +116 -3
- package/dist/cjs/router/runtime/plugin.js +14 -1
- package/dist/cjs/router/runtime/plugin.node.js +12 -52
- package/dist/cjs/router/runtime/utils.js +68 -69
- package/dist/cjs/{runtime-context.js → runtimeContext.js} +3 -3
- package/dist/cjs/ssr/cli/index.js +3 -2
- package/dist/cjs/ssr/index.node.js +1 -0
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +2 -14
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +22 -7
- package/dist/cjs/ssr/serverRender/renderToStream/template.js +2 -1
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +19 -8
- package/dist/cjs/state/runtime/index.js +2 -8
- package/dist/esm/cli/index.js +4 -3
- package/dist/esm/common.js +3 -1
- package/dist/esm/core/compatible.js +1 -1
- package/dist/esm/core/index.js +2 -2
- package/dist/esm/core/loader/useLoader.js +1 -1
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/router/runtime/DeferredDataScripts.js +166 -0
- package/dist/esm/router/runtime/index.js +3 -2
- package/dist/esm/router/runtime/plugin.js +11 -3
- package/dist/esm/router/runtime/plugin.node.js +11 -68
- package/dist/esm/router/runtime/utils.js +138 -81
- package/dist/esm/ssr/cli/index.js +4 -3
- package/dist/esm/ssr/index.node.js +1 -0
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +2 -4
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +19 -8
- package/dist/esm/ssr/serverRender/renderToStream/template.js +2 -1
- package/dist/esm/ssr/serverRender/renderToString/entry.js +15 -7
- package/dist/esm/state/runtime/index.js +1 -2
- package/dist/esm-node/cli/index.js +4 -3
- package/dist/esm-node/common.js +4 -0
- package/dist/esm-node/core/compatible.js +1 -1
- package/dist/esm-node/core/index.js +2 -2
- package/dist/esm-node/core/loader/useLoader.js +1 -1
- package/dist/esm-node/core/types.js +0 -0
- package/dist/esm-node/router/runtime/DeferredDataScripts.js +148 -0
- package/dist/esm-node/router/runtime/index.js +113 -2
- package/dist/esm-node/router/runtime/plugin.js +15 -2
- package/dist/esm-node/router/runtime/plugin.node.js +12 -55
- package/dist/esm-node/router/runtime/utils.js +59 -69
- package/dist/esm-node/ssr/cli/index.js +4 -3
- package/dist/esm-node/ssr/index.node.js +1 -0
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +2 -4
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +22 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/template.js +2 -1
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +19 -8
- package/dist/esm-node/state/runtime/index.js +1 -4
- package/dist/types/common.d.ts +3 -1
- package/dist/types/core/compatible.d.ts +1 -1
- package/dist/types/core/index.d.ts +4 -3
- package/dist/types/core/loader/index.d.ts +1 -2
- package/dist/types/core/loader/useLoader.d.ts +1 -15
- package/dist/types/core/plugin.d.ts +15 -15
- package/dist/types/core/types.d.ts +22 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/runtime/DeferredDataScripts.d.ts +8 -0
- package/dist/types/router/runtime/index.d.ts +4 -2
- package/dist/types/router/runtime/utils.d.ts +23 -4
- package/dist/types/{runtime-context.d.ts → runtimeContext.d.ts} +2 -0
- package/dist/types/ssr/serverRender/renderToStream/buildTemplate.after.d.ts +2 -0
- package/dist/types/state/runtime/index.d.ts +0 -1
- package/package.json +15 -18
- package/types/router.d.ts +1 -1
- /package/dist/esm/core/{app-config.js → appConfig.js} +0 -0
- /package/dist/esm/{runtime-context.js → runtimeContext.js} +0 -0
- /package/dist/esm-node/core/{app-config.js → appConfig.js} +0 -0
- /package/dist/esm-node/{runtime-context.js → runtimeContext.js} +0 -0
- /package/dist/types/core/{app-config.d.ts → appConfig.d.ts} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,67 +16,36 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
var utils_exports = {};
|
|
19
29
|
__export(utils_exports, {
|
|
30
|
+
deserializeErrors: () => deserializeErrors,
|
|
20
31
|
getLocation: () => getLocation,
|
|
21
32
|
getRouteComponents: () => getRouteComponents,
|
|
22
33
|
renderRoutes: () => renderRoutes,
|
|
34
|
+
serializeErrors: () => serializeErrors,
|
|
23
35
|
standardSlash: () => standardSlash,
|
|
24
36
|
urlJoin: () => urlJoin
|
|
25
37
|
});
|
|
26
38
|
module.exports = __toCommonJS(utils_exports);
|
|
27
39
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
-
var import_react = require("react");
|
|
29
40
|
var import_react_router_dom = require("react-router-dom");
|
|
41
|
+
var import_nestedRoutes = require("@modern-js/utils/nestedRoutes");
|
|
42
|
+
var import_remix_router = require("@modern-js/utils/remix-router");
|
|
30
43
|
var import_DefaultNotFound = require("./DefaultNotFound");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
path: nestedRoute.path,
|
|
37
|
-
id: nestedRoute.id,
|
|
38
|
-
loader: createLoader(nestedRoute),
|
|
39
|
-
action: nestedRoute.action,
|
|
40
|
-
hasErrorBoundary: nestedRoute.hasErrorBoundary,
|
|
41
|
-
shouldRevalidate: nestedRoute.shouldRevalidate,
|
|
42
|
-
handle: nestedRoute.handle,
|
|
43
|
-
index: nestedRoute.index,
|
|
44
|
-
element: nestedRoute.element,
|
|
45
|
-
errorElement: nestedRoute.errorElement
|
|
46
|
-
};
|
|
47
|
-
if (nestedRoute.error) {
|
|
48
|
-
const errorElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(nestedRoute.error, {});
|
|
49
|
-
routeProps.errorElement = errorElement;
|
|
50
|
-
}
|
|
51
|
-
let element;
|
|
52
|
-
if (Component) {
|
|
53
|
-
if (parent == null ? void 0 : parent.loading) {
|
|
54
|
-
const Loading = parent.loading;
|
|
55
|
-
if (isLoadableComponent(Component)) {
|
|
56
|
-
element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}) });
|
|
57
|
-
} else {
|
|
58
|
-
element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
|
|
59
|
-
}
|
|
60
|
-
} else if (isLoadableComponent(Component) || isRoot) {
|
|
61
|
-
element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
|
|
62
|
-
} else {
|
|
63
|
-
element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
nestedRoute.loading = parent == null ? void 0 : parent.loading;
|
|
67
|
-
}
|
|
68
|
-
if (element) {
|
|
69
|
-
routeProps.element = element;
|
|
70
|
-
}
|
|
71
|
-
const childElements = children == null ? void 0 : children.map((childRoute) => {
|
|
72
|
-
return renderNestedRoute(childRoute, nestedRoute);
|
|
73
|
-
});
|
|
74
|
-
const routeElement = index ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, { ...routeProps, index: true }, id) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, { ...routeProps, index: false, children: childElements }, id);
|
|
75
|
-
return routeElement;
|
|
76
|
-
};
|
|
77
|
-
function getRouteComponents(routes, globalApp) {
|
|
44
|
+
var import_DeferredDataScripts = __toESM(require("./DeferredDataScripts"));
|
|
45
|
+
function getRouteComponents(routes, {
|
|
46
|
+
globalApp,
|
|
47
|
+
ssrMode
|
|
48
|
+
}) {
|
|
78
49
|
const Layout = ({ Component, ...props }) => {
|
|
79
50
|
const GlobalLayout = globalApp;
|
|
80
51
|
if (!GlobalLayout) {
|
|
@@ -85,7 +56,9 @@ function getRouteComponents(routes, globalApp) {
|
|
|
85
56
|
const routeElements = [];
|
|
86
57
|
for (const route of routes) {
|
|
87
58
|
if (route.type === "nested") {
|
|
88
|
-
const routeElement = renderNestedRoute(route
|
|
59
|
+
const routeElement = (0, import_nestedRoutes.renderNestedRoute)(route, {
|
|
60
|
+
DeferredDataComponent: ssrMode === "stream" ? import_DeferredDataScripts.default : void 0
|
|
61
|
+
});
|
|
89
62
|
routeElements.push(routeElement);
|
|
90
63
|
} else {
|
|
91
64
|
const routeElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -102,7 +75,7 @@ function getRouteComponents(routes, globalApp) {
|
|
|
102
75
|
routeElements.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, { path: "*", element: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DefaultNotFound.DefaultNotFound, {}) }, "*"));
|
|
103
76
|
return routeElements;
|
|
104
77
|
}
|
|
105
|
-
function renderRoutes(routesConfig) {
|
|
78
|
+
function renderRoutes(routesConfig, ssrMode) {
|
|
106
79
|
if (!routesConfig) {
|
|
107
80
|
return null;
|
|
108
81
|
}
|
|
@@ -110,7 +83,7 @@ function renderRoutes(routesConfig) {
|
|
|
110
83
|
if (!routes) {
|
|
111
84
|
return null;
|
|
112
85
|
}
|
|
113
|
-
const routeElements = getRouteComponents(routes, globalApp);
|
|
86
|
+
const routeElements = getRouteComponents(routes, { globalApp, ssrMode });
|
|
114
87
|
return routeElements;
|
|
115
88
|
}
|
|
116
89
|
function getLocation(serverContext) {
|
|
@@ -144,32 +117,58 @@ function standardSlash(str) {
|
|
|
144
117
|
}
|
|
145
118
|
return addr;
|
|
146
119
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return (args) => {
|
|
151
|
-
if (typeof route.lazyImport === "function") {
|
|
152
|
-
route.lazyImport();
|
|
153
|
-
}
|
|
154
|
-
return loader(args);
|
|
155
|
-
};
|
|
156
|
-
} else {
|
|
157
|
-
return () => {
|
|
158
|
-
if (typeof route.lazyImport === "function") {
|
|
159
|
-
route.lazyImport();
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
};
|
|
120
|
+
function serializeErrors(errors) {
|
|
121
|
+
if (!errors) {
|
|
122
|
+
return null;
|
|
163
123
|
}
|
|
124
|
+
const entries = Object.entries(errors);
|
|
125
|
+
const serialized = {};
|
|
126
|
+
for (const [key, val] of entries) {
|
|
127
|
+
if ((0, import_remix_router.isRouteErrorResponse)(val)) {
|
|
128
|
+
serialized[key] = { ...val, __type: "RouteErrorResponse" };
|
|
129
|
+
} else if (val instanceof Error) {
|
|
130
|
+
serialized[key] = {
|
|
131
|
+
message: val.message,
|
|
132
|
+
stack: val.stack,
|
|
133
|
+
__type: "Error"
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
serialized[key] = val;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return serialized;
|
|
164
140
|
}
|
|
165
|
-
function
|
|
166
|
-
|
|
141
|
+
function deserializeErrors(errors) {
|
|
142
|
+
if (!errors) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const entries = Object.entries(errors);
|
|
146
|
+
const serialized = {};
|
|
147
|
+
for (const [key, val] of entries) {
|
|
148
|
+
if (val && val.__type === "RouteErrorResponse") {
|
|
149
|
+
serialized[key] = new import_remix_router.ErrorResponse(
|
|
150
|
+
val.status,
|
|
151
|
+
val.statusText,
|
|
152
|
+
val.data,
|
|
153
|
+
val.internal === true
|
|
154
|
+
);
|
|
155
|
+
} else if (val && val.__type === "Error") {
|
|
156
|
+
const error = new Error(val.message);
|
|
157
|
+
error.stack = val.stack;
|
|
158
|
+
serialized[key] = error;
|
|
159
|
+
} else {
|
|
160
|
+
serialized[key] = val;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return serialized;
|
|
167
164
|
}
|
|
168
165
|
// Annotate the CommonJS export names for ESM import in node:
|
|
169
166
|
0 && (module.exports = {
|
|
167
|
+
deserializeErrors,
|
|
170
168
|
getLocation,
|
|
171
169
|
getRouteComponents,
|
|
172
170
|
renderRoutes,
|
|
171
|
+
serializeErrors,
|
|
173
172
|
standardSlash,
|
|
174
173
|
urlJoin
|
|
175
174
|
});
|
|
@@ -15,12 +15,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var runtimeContext_exports = {};
|
|
19
|
+
__export(runtimeContext_exports, {
|
|
20
20
|
RuntimeReactContext: () => RuntimeReactContext,
|
|
21
21
|
ServerRouterContext: () => ServerRouterContext
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(runtimeContext_exports);
|
|
24
24
|
var import_react = require("react");
|
|
25
25
|
const RuntimeReactContext = (0, import_react.createContext)({});
|
|
26
26
|
const ServerRouterContext = (0, import_react.createContext)({});
|
|
@@ -64,6 +64,8 @@ var cli_default = () => ({
|
|
|
64
64
|
return {
|
|
65
65
|
source: {
|
|
66
66
|
alias: {
|
|
67
|
+
// ensure that all packages use the same storage in @modern-js/utils/ssr
|
|
68
|
+
"@modern-js/utils/ssr": require.resolve("@modern-js/utils/ssr"),
|
|
67
69
|
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
|
|
68
70
|
}
|
|
69
71
|
},
|
|
@@ -136,8 +138,7 @@ var cli_default = () => ({
|
|
|
136
138
|
);
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
|
-
const
|
|
140
|
-
const useSSG = (0, import_utils.isSingleEntry)(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig == null ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig == null ? void 0 : ssgConfig[entryName]);
|
|
141
|
+
const useSSG = (0, import_utils.isSSGEntry)(userConfig, entryName, entrypoints);
|
|
141
142
|
ssrConfigMap.set(entryName, ssrConfig || useSSG);
|
|
142
143
|
if (ssrConfig || useSSG) {
|
|
143
144
|
imports.push({
|
|
@@ -50,6 +50,7 @@ const ssr = (config = {}) => ({
|
|
|
50
50
|
init({ context }, next) {
|
|
51
51
|
const { request } = context.ssrContext;
|
|
52
52
|
context.ssrContext.request = (0, import_utils.formatServer)(request);
|
|
53
|
+
context.ssrContext.mode = config.mode;
|
|
53
54
|
return next({ context });
|
|
54
55
|
},
|
|
55
56
|
pickContext: ({ context, pickedContext }, next) => {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,21 +14,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
var buildTemplate_after_exports = {};
|
|
29
19
|
__export(buildTemplate_after_exports, {
|
|
30
20
|
buildShellAfterTemplate: () => buildShellAfterTemplate
|
|
31
21
|
});
|
|
32
22
|
module.exports = __toCommonJS(buildTemplate_after_exports);
|
|
33
|
-
var
|
|
23
|
+
var import_serialize = require("@modern-js/utils/serialize");
|
|
34
24
|
var import_buildTemplate = require("./buildTemplate.share");
|
|
35
25
|
function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
36
26
|
const callbacks = [injectSSRDataScript];
|
|
@@ -58,9 +48,7 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
58
48
|
renderLevel
|
|
59
49
|
};
|
|
60
50
|
return `
|
|
61
|
-
<script>window._SSR_DATA = ${(0,
|
|
62
|
-
isJSON: true
|
|
63
|
-
})}</script>
|
|
51
|
+
<script>window._SSR_DATA = ${(0, import_serialize.serializeJson)(SSRData)}</script>
|
|
64
52
|
`;
|
|
65
53
|
}
|
|
66
54
|
}
|
|
@@ -58,7 +58,11 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
58
58
|
}
|
|
59
59
|
const { routeAssets } = routeManifest;
|
|
60
60
|
const cssChunks = [];
|
|
61
|
-
const matches = (0, import_react_router_dom.matchRoutes)(
|
|
61
|
+
const matches = (0, import_react_router_dom.matchRoutes)(
|
|
62
|
+
routes,
|
|
63
|
+
routerContext.location,
|
|
64
|
+
routerContext.basename
|
|
65
|
+
);
|
|
62
66
|
matches == null ? void 0 : matches.forEach((match, index) => {
|
|
63
67
|
if (!index) {
|
|
64
68
|
return;
|
|
@@ -22,9 +22,16 @@ __export(renderToPipe_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(renderToPipe_exports);
|
|
23
23
|
var import_stream = require("stream");
|
|
24
24
|
var import_types = require("../types");
|
|
25
|
+
var import_common = require("../../../common");
|
|
25
26
|
var import_template = require("./template");
|
|
27
|
+
var ShellChunkStatus = /* @__PURE__ */ ((ShellChunkStatus2) => {
|
|
28
|
+
ShellChunkStatus2[ShellChunkStatus2["IDLE"] = 0] = "IDLE";
|
|
29
|
+
ShellChunkStatus2[ShellChunkStatus2["START"] = 1] = "START";
|
|
30
|
+
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 2] = "FINIESH";
|
|
31
|
+
return ShellChunkStatus2;
|
|
32
|
+
})(ShellChunkStatus || {});
|
|
26
33
|
function renderToPipe(rootElement, context, options) {
|
|
27
|
-
let
|
|
34
|
+
let shellChunkStatus = 0 /* IDLE */;
|
|
28
35
|
const { ssrContext } = context;
|
|
29
36
|
const forUserPipe = (stream) => {
|
|
30
37
|
return new Promise((resolve) => {
|
|
@@ -45,9 +52,20 @@ function renderToPipe(rootElement, context, options) {
|
|
|
45
52
|
const injectableTransform = new import_stream.Transform({
|
|
46
53
|
transform(chunk, _encoding, callback) {
|
|
47
54
|
try {
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
if (shellChunkStatus !== 2 /* FINIESH */) {
|
|
56
|
+
let concatedChunk = chunk.toString();
|
|
57
|
+
if (shellChunkStatus === 0 /* IDLE */) {
|
|
58
|
+
concatedChunk = `${shellBefore}${concatedChunk}`;
|
|
59
|
+
shellChunkStatus = 1 /* START */;
|
|
60
|
+
}
|
|
61
|
+
if (shellChunkStatus === 1 /* START */ && concatedChunk.endsWith(import_common.ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
62
|
+
concatedChunk = concatedChunk.replace(
|
|
63
|
+
import_common.ESCAPED_SHELL_STREAM_END_MARK,
|
|
64
|
+
shellAfter
|
|
65
|
+
);
|
|
66
|
+
shellChunkStatus = 2 /* FINIESH */;
|
|
67
|
+
}
|
|
68
|
+
this.push(concatedChunk);
|
|
51
69
|
} else {
|
|
52
70
|
this.push(chunk);
|
|
53
71
|
}
|
|
@@ -90,9 +108,6 @@ function renderToPipe(rootElement, context, options) {
|
|
|
90
108
|
});
|
|
91
109
|
};
|
|
92
110
|
return forUserPipe;
|
|
93
|
-
function joinChunk(before = "", chunk, after = "") {
|
|
94
|
-
return `${before}${chunk.toString()}${after}`;
|
|
95
|
-
}
|
|
96
111
|
}
|
|
97
112
|
var renderToPipe_default = renderToPipe;
|
|
98
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -24,7 +24,7 @@ var import_buildTemplate = require("./buildTemplate.after");
|
|
|
24
24
|
var import_bulidTemplate = require("./bulidTemplate.before");
|
|
25
25
|
const HTML_SEPARATOR = "<!--<?- html ?>-->";
|
|
26
26
|
const getTemplates = (context, renderLevel) => {
|
|
27
|
-
const { ssrContext } = context;
|
|
27
|
+
const { ssrContext, routerContext } = context;
|
|
28
28
|
const [beforeAppTemplate = "", afterAppHtmlTemplate = ""] = ssrContext.template.split(HTML_SEPARATOR) || [];
|
|
29
29
|
const builtBeforeTemplate = (0, import_bulidTemplate.buildShellBeforeTemplate)(
|
|
30
30
|
beforeAppTemplate,
|
|
@@ -32,6 +32,7 @@ const getTemplates = (context, renderLevel) => {
|
|
|
32
32
|
);
|
|
33
33
|
const builtAfterTemplate = (0, import_buildTemplate.buildShellAfterTemplate)(afterAppHtmlTemplate, {
|
|
34
34
|
ssrContext,
|
|
35
|
+
routerContext,
|
|
35
36
|
renderLevel
|
|
36
37
|
});
|
|
37
38
|
return {
|
|
@@ -32,8 +32,9 @@ __export(entry_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(entry_exports);
|
|
33
33
|
var import_react = __toESM(require("react"));
|
|
34
34
|
var import_server = __toESM(require("react-dom/server"));
|
|
35
|
-
var
|
|
35
|
+
var import_serialize = require("@modern-js/utils/serialize");
|
|
36
36
|
var import_react_helmet = __toESM(require("react-helmet"));
|
|
37
|
+
var import_utils = require("../../../router/runtime/utils");
|
|
37
38
|
var import_helmet = __toESM(require("../helmet"));
|
|
38
39
|
var import_types = require("../types");
|
|
39
40
|
var import_time = require("../time");
|
|
@@ -102,13 +103,18 @@ class Entry {
|
|
|
102
103
|
if ((_c = ssrContext.redirection) == null ? void 0 : _c.url) {
|
|
103
104
|
return "";
|
|
104
105
|
}
|
|
106
|
+
const { routerContext } = context;
|
|
107
|
+
const routerData = routerContext ? {
|
|
108
|
+
loaderData: routerContext.loaderData,
|
|
109
|
+
errors: (0, import_utils.serializeErrors)(routerContext.errors)
|
|
110
|
+
} : void 0;
|
|
105
111
|
let html = "";
|
|
106
112
|
const templateData = buildTemplateData(
|
|
107
113
|
ssrContext,
|
|
108
114
|
prefetchData,
|
|
109
115
|
this.result.renderLevel
|
|
110
116
|
);
|
|
111
|
-
const SSRData = this.getSSRDataScript(templateData);
|
|
117
|
+
const SSRData = this.getSSRDataScript(templateData, routerData);
|
|
112
118
|
for (const fragment of this.fragments) {
|
|
113
119
|
if (fragment.isVariable && fragment.content === "SSRDataScript") {
|
|
114
120
|
html += fragment.getValue(SSRData);
|
|
@@ -165,13 +171,18 @@ class Entry {
|
|
|
165
171
|
}
|
|
166
172
|
return html;
|
|
167
173
|
}
|
|
168
|
-
getSSRDataScript(templateData) {
|
|
174
|
+
getSSRDataScript(templateData, routerData) {
|
|
175
|
+
let ssrDataScripts = `<script>window._SSR_DATA = ${(0, import_serialize.serializeJson)(
|
|
176
|
+
templateData
|
|
177
|
+
)}</script>`;
|
|
178
|
+
if (routerData) {
|
|
179
|
+
ssrDataScripts += `
|
|
180
|
+
<script>window._ROUTER_DATA = ${(0, import_serialize.serializeJson)(
|
|
181
|
+
routerData
|
|
182
|
+
)}</script>`;
|
|
183
|
+
}
|
|
169
184
|
return {
|
|
170
|
-
SSRDataScript:
|
|
171
|
-
<script>window._SSR_DATA = ${(0, import_serialize_javascript.default)(templateData, {
|
|
172
|
-
isJSON: true
|
|
173
|
-
})}</script>
|
|
174
|
-
`
|
|
185
|
+
SSRDataScript: ssrDataScripts
|
|
175
186
|
};
|
|
176
187
|
}
|
|
177
188
|
}
|
|
@@ -28,17 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var runtime_exports = {};
|
|
30
30
|
__export(runtime_exports, {
|
|
31
|
-
|
|
32
|
-
default: () => import_plugin.default,
|
|
33
|
-
model: () => import_store.model
|
|
31
|
+
default: () => import_plugin.default
|
|
34
32
|
});
|
|
35
33
|
module.exports = __toCommonJS(runtime_exports);
|
|
36
34
|
__reExport(runtime_exports, require("@modern-js-reduck/react"), module.exports);
|
|
37
|
-
var import_store = require("@modern-js-reduck/store");
|
|
38
35
|
var import_plugin = __toESM(require("./plugin"));
|
|
39
36
|
__reExport(runtime_exports, require("./plugin"), module.exports);
|
|
40
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
createStore,
|
|
43
|
-
model
|
|
44
|
-
});
|
|
38
|
+
0 && (module.exports = {});
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -132,15 +132,16 @@ var cli_default = function() {
|
|
|
132
132
|
return {
|
|
133
133
|
name: "@modern-js/runtime",
|
|
134
134
|
post: [
|
|
135
|
-
"@modern-js/plugin-router",
|
|
136
135
|
"@modern-js/plugin-ssr",
|
|
137
|
-
"@modern-js/plugin-document",
|
|
138
136
|
"@modern-js/plugin-state",
|
|
137
|
+
"@modern-js/plugin-router",
|
|
138
|
+
"@modern-js/plugin-document",
|
|
139
139
|
"@modern-js/plugin-design-token"
|
|
140
140
|
],
|
|
141
|
+
// the order of runtime plugins is affected by runtime hooks, mainly `init` and `hoc` hooks
|
|
141
142
|
usePlugins: [
|
|
142
|
-
PluginState(),
|
|
143
143
|
PluginSSR(),
|
|
144
|
+
PluginState(),
|
|
144
145
|
PluginRouter(),
|
|
145
146
|
Document()
|
|
146
147
|
],
|
package/dist/esm/common.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var isBrowser = function() {
|
|
2
2
|
return typeof window !== "undefined" && window.name !== "nodejs";
|
|
3
3
|
};
|
|
4
|
-
|
|
4
|
+
var JSX_SHELL_STREAM_END_MARK = "<!--<?- SHELL_STREAM_END ?>-->";
|
|
5
|
+
var ESCAPED_SHELL_STREAM_END_MARK = "<!--<?- SHELL_STREAM_END ?>-->";
|
|
6
|
+
export { ESCAPED_SHELL_STREAM_END_MARK, JSX_SHELL_STREAM_END_MARK, isBrowser };
|
|
@@ -213,7 +213,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
213
213
|
import React, { useContext, useMemo } from "react";
|
|
214
214
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
215
215
|
import { ROUTE_MANIFEST } from "@modern-js/utils/constants";
|
|
216
|
-
import { RuntimeReactContext } from "../
|
|
216
|
+
import { RuntimeReactContext } from "../runtimeContext";
|
|
217
217
|
import { runtime } from "./plugin";
|
|
218
218
|
import { createLoaderManager } from "./loader/loaderManager";
|
|
219
219
|
var IS_REACT18 = process.env.IS_REACT18 === "true";
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createPlugin, createRuntime, runtime, registerInit } from "./plugin";
|
|
2
|
-
import { defineConfig, getConfig } from "./
|
|
2
|
+
import { defineConfig, getConfig } from "./appConfig";
|
|
3
3
|
export * from "./compatible";
|
|
4
|
-
import { RuntimeReactContext, ServerRouterContext } from "../
|
|
4
|
+
import { RuntimeReactContext, ServerRouterContext } from "../runtimeContext";
|
|
5
5
|
export * from "./loader";
|
|
6
6
|
export * from "@modern-js/plugin";
|
|
7
7
|
export { RuntimeReactContext, ServerRouterContext, createPlugin, createRuntime, defineConfig, getConfig, registerInit, runtime };
|
|
@@ -105,7 +105,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
105
105
|
}
|
|
106
106
|
import { useContext, useRef, useMemo, useState, useCallback, useEffect } from "react";
|
|
107
107
|
import invariant from "invariant";
|
|
108
|
-
import { RuntimeReactContext } from "../../
|
|
108
|
+
import { RuntimeReactContext } from "../../runtimeContext";
|
|
109
109
|
import { LoaderStatus } from "./loaderManager";
|
|
110
110
|
var useLoader = function(loaderFn) {
|
|
111
111
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|