@modern-js/runtime 2.7.0 → 2.9.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 +43 -0
- package/README.md +2 -2
- package/dist/cjs/cli/index.js +4 -3
- package/dist/cjs/router/runtime/DeferredDataScripts.js +2 -140
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +165 -0
- package/dist/cjs/ssr/cli/index.js +1 -2
- package/dist/cjs/ssr/serverRender/index.js +8 -0
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +7 -3
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +25 -9
- package/dist/cjs/ssr/serverRender/utils.js +3 -0
- package/dist/cjs/state/runtime/index.js +2 -8
- package/dist/esm/cli/index.js +4 -3
- package/dist/esm/router/runtime/DeferredDataScripts.js +2 -164
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +166 -0
- package/dist/esm/ssr/cli/index.js +2 -3
- package/dist/esm/ssr/serverRender/index.js +6 -1
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +24 -11
- package/dist/esm/ssr/serverRender/utils.js +2 -1
- package/dist/esm/state/runtime/index.js +1 -2
- package/dist/esm-node/cli/index.js +4 -3
- package/dist/esm-node/router/runtime/DeferredDataScripts.js +2 -144
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +148 -0
- package/dist/esm-node/ssr/cli/index.js +2 -3
- package/dist/esm-node/ssr/serverRender/index.js +8 -0
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +6 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +25 -9
- package/dist/esm-node/ssr/serverRender/utils.js +2 -0
- package/dist/esm-node/state/runtime/index.js +1 -4
- package/dist/types/router/runtime/DeferredDataScripts.d.ts +2 -7
- package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +8 -0
- package/dist/types/router/runtime/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.worker.d.ts +1 -1
- package/dist/types/ssr/serverRender/utils.d.ts +1 -0
- package/dist/types/state/runtime/index.d.ts +0 -1
- package/package.json +12 -12
- package/types/router.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 2.9.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e8c580125d: fix: remove `serialze-javascript` from client bundle
|
|
8
|
+
fix: 移除客户端构建产物中的 `serialze-javascript`
|
|
9
|
+
- 7035d5c22f: feat: support streaming ssr in worker
|
|
10
|
+
|
|
11
|
+
feat: worker 支持 streaming ssr
|
|
12
|
+
|
|
13
|
+
- 49bb8cd0ef: fix: move chunkmap.css comment to bottom of head
|
|
14
|
+
fix: 将 chunkmap.css 标记移动到 head 底部
|
|
15
|
+
- 755a053579: fix: export missing react-router types
|
|
16
|
+
fix: 导出缺少的 react-router 类型
|
|
17
|
+
- @modern-js/plugin@2.9.0
|
|
18
|
+
- @modern-js/types@2.9.0
|
|
19
|
+
- @modern-js/utils@2.9.0
|
|
20
|
+
|
|
21
|
+
## 2.8.0
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 3ef832741b: fix: fix types pathname for model field
|
|
26
|
+
fix: 修复 model 字段对应的 types 路径
|
|
27
|
+
- 9330022f4e: fix: add missing react-router type
|
|
28
|
+
fix: 添加丢失的 react-router 导出类型
|
|
29
|
+
- 40747e6fdd: fix: fix the order of runtime plugins
|
|
30
|
+
fix: 修复 runtime plugin 执行顺序
|
|
31
|
+
- 58a1fc64da: fix: pass basename to `matchRoutes`
|
|
32
|
+
fix: 修复 `matchRoutes` 未传入 basename 参数
|
|
33
|
+
- 4cfea8ce49: fix: remove esbuild from bff-core
|
|
34
|
+
fix: 从 bff-core 移除 esbuild
|
|
35
|
+
- 1f6ca2c7fb: fix: nested routes in ssg
|
|
36
|
+
fix: 修复嵌套路由在 SSG 中的问题
|
|
37
|
+
- 9c9ebba6f2: fix: fix duplicate re-exports of reduck
|
|
38
|
+
fix: 修复从 reduck 重复导出的 API
|
|
39
|
+
- Updated dependencies [1104a9f18b]
|
|
40
|
+
- Updated dependencies [70d82e1408]
|
|
41
|
+
- Updated dependencies [1f6ca2c7fb]
|
|
42
|
+
- @modern-js/utils@2.8.0
|
|
43
|
+
- @modern-js/types@2.8.0
|
|
44
|
+
- @modern-js/plugin@2.8.0
|
|
45
|
+
|
|
3
46
|
## 2.7.0
|
|
4
47
|
|
|
5
48
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
|
|
|
19
19
|
|
|
20
20
|
## Contributing
|
|
21
21
|
|
|
22
|
-
Please read the [Contributing Guide](https://github.com/
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
23
|
|
|
24
24
|
## License
|
|
25
25
|
|
|
26
|
-
Modern.js is [MIT licensed](https://github.com/
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -39,13 +39,14 @@ var import_cli4 = __toESM(require("../document/cli"));
|
|
|
39
39
|
var cli_default = () => ({
|
|
40
40
|
name: "@modern-js/runtime",
|
|
41
41
|
post: [
|
|
42
|
-
"@modern-js/plugin-router",
|
|
43
42
|
"@modern-js/plugin-ssr",
|
|
44
|
-
"@modern-js/plugin-document",
|
|
45
43
|
"@modern-js/plugin-state",
|
|
44
|
+
"@modern-js/plugin-router",
|
|
45
|
+
"@modern-js/plugin-document",
|
|
46
46
|
"@modern-js/plugin-design-token"
|
|
47
47
|
],
|
|
48
|
-
|
|
48
|
+
// the order of runtime plugins is affected by runtime hooks, mainly `init` and `hoc` hooks
|
|
49
|
+
usePlugins: [(0, import_cli2.default)(), (0, import_cli.default)(), (0, import_cli3.default)(), (0, import_cli4.default)()],
|
|
49
50
|
setup: (api) => {
|
|
50
51
|
return {
|
|
51
52
|
config() {
|
|
@@ -20,146 +20,8 @@ __export(DeferredDataScripts_exports, {
|
|
|
20
20
|
default: () => DeferredDataScripts_default
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(DeferredDataScripts_exports);
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
var import_react_router_dom = require("react-router-dom");
|
|
26
|
-
var import_serialize = require("@modern-js/utils/serialize");
|
|
27
|
-
var import_common = require("../../common");
|
|
28
|
-
var import_utils = require("./utils");
|
|
29
|
-
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
30
|
-
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
31
|
-
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resovle(e)};`;
|
|
32
|
-
const DeferredDataScripts = () => {
|
|
33
|
-
const context = (0, import_react.useContext)(import_react_router_dom.UNSAFE_DataRouterContext);
|
|
34
|
-
const { staticContext } = context || {};
|
|
35
|
-
const hydratedRef = (0, import_react.useRef)(false);
|
|
36
|
-
(0, import_react.useEffect)(() => {
|
|
37
|
-
hydratedRef.current = true;
|
|
38
|
-
}, []);
|
|
39
|
-
const deferredScripts = (0, import_react.useMemo)(() => {
|
|
40
|
-
if (!staticContext) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const activeDeferreds = staticContext.activeDeferreds || [];
|
|
44
|
-
const _ROUTER_DATA = {
|
|
45
|
-
loaderData: staticContext.loaderData,
|
|
46
|
-
errors: (0, import_utils.serializeErrors)(staticContext.errors)
|
|
47
|
-
};
|
|
48
|
-
let initialScripts = [
|
|
49
|
-
`_ROUTER_DATA = ${(0, import_serialize.serializeJson)(_ROUTER_DATA)};`,
|
|
50
|
-
`_ROUTER_DATA.s = ${setupFnStr}`,
|
|
51
|
-
`_ROUTER_DATA.r = ${resolveFnStr}`,
|
|
52
|
-
`_ROUTER_DATA.p = ${preResolvedFnStr}`
|
|
53
|
-
].join("\n");
|
|
54
|
-
const deferredDataScripts = [];
|
|
55
|
-
initialScripts += Object.entries(activeDeferreds).map(([routeId, deferredData]) => {
|
|
56
|
-
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
57
|
-
const { deferredKeys } = deferredData;
|
|
58
|
-
const deferredKeyPromiseStr = deferredKeys.map((key) => {
|
|
59
|
-
if (pendingKeys.has(key)) {
|
|
60
|
-
deferredDataScripts.push(
|
|
61
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
62
|
-
DeferredDataScript,
|
|
63
|
-
{
|
|
64
|
-
data: deferredData.data[key],
|
|
65
|
-
dataKey: key,
|
|
66
|
-
routeId
|
|
67
|
-
},
|
|
68
|
-
`${routeId} | ${key}`
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
return `${JSON.stringify(key)}: _ROUTER_DATA.s(${JSON.stringify(
|
|
72
|
-
routeId
|
|
73
|
-
)},${JSON.stringify(key)}) `;
|
|
74
|
-
} else {
|
|
75
|
-
const trackedPromise = deferredData.data[key];
|
|
76
|
-
if (typeof trackedPromise._error !== "undefined") {
|
|
77
|
-
const error = {
|
|
78
|
-
message: trackedPromise._error.message,
|
|
79
|
-
stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
|
|
80
|
-
};
|
|
81
|
-
return `${JSON.stringify(
|
|
82
|
-
key
|
|
83
|
-
)}: _ROUTER_DATA.p(${void 0}, ${(0, import_serialize.serializeJson)(error)})`;
|
|
84
|
-
} else {
|
|
85
|
-
if (typeof trackedPromise._data === "undefined") {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
return `${JSON.stringify(key)}: _ROUTER_DATA.p(${(0, import_serialize.serializeJson)(
|
|
91
|
-
trackedPromise._data
|
|
92
|
-
)})`;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}).join(",\n");
|
|
96
|
-
return `Object.assign(_ROUTER_DATA.loaderData[${JSON.stringify(
|
|
97
|
-
routeId
|
|
98
|
-
)}], {${deferredKeyPromiseStr}});`;
|
|
99
|
-
}).join("\n");
|
|
100
|
-
return [initialScripts, deferredDataScripts];
|
|
101
|
-
}, []);
|
|
102
|
-
if (!deferredScripts) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
106
|
-
!hydratedRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
107
|
-
"script",
|
|
108
|
-
{
|
|
109
|
-
async: true,
|
|
110
|
-
suppressHydrationWarning: true,
|
|
111
|
-
dangerouslySetInnerHTML: { __html: deferredScripts[0] }
|
|
112
|
-
}
|
|
113
|
-
),
|
|
114
|
-
!hydratedRef.current && deferredScripts[1],
|
|
115
|
-
import_common.JSX_SHELL_STREAM_END_MARK
|
|
116
|
-
] });
|
|
117
|
-
};
|
|
118
|
-
const DeferredDataScript = ({
|
|
119
|
-
data,
|
|
120
|
-
routeId,
|
|
121
|
-
dataKey
|
|
122
|
-
}) => {
|
|
123
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: typeof document === "undefined" && data && dataKey && routeId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
-
import_react_router_dom.Await,
|
|
125
|
-
{
|
|
126
|
-
resolve: data,
|
|
127
|
-
errorElement: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorDeferredDataScript, { routeId, dataKey }),
|
|
128
|
-
children: (data2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
129
|
-
"script",
|
|
130
|
-
{
|
|
131
|
-
async: true,
|
|
132
|
-
suppressHydrationWarning: true,
|
|
133
|
-
dangerouslySetInnerHTML: {
|
|
134
|
-
__html: `_ROUTER_DATA.r(${JSON.stringify(
|
|
135
|
-
routeId
|
|
136
|
-
)}, ${JSON.stringify(dataKey)}, ${(0, import_serialize.serializeJson)(data2)});`
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
) : null });
|
|
142
|
-
};
|
|
143
|
-
const ErrorDeferredDataScript = ({
|
|
144
|
-
routeId,
|
|
145
|
-
dataKey
|
|
146
|
-
}) => {
|
|
147
|
-
const error = (0, import_react_router_dom.useAsyncError)();
|
|
148
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
149
|
-
"script",
|
|
150
|
-
{
|
|
151
|
-
suppressHydrationWarning: true,
|
|
152
|
-
dangerouslySetInnerHTML: {
|
|
153
|
-
__html: `_ROUTER_DATA.r(${JSON.stringify(routeId)}, ${JSON.stringify(
|
|
154
|
-
dataKey
|
|
155
|
-
)}, ${void 0}, ${(0, import_serialize.serializeJson)({
|
|
156
|
-
message: error.message,
|
|
157
|
-
stack: error.stack
|
|
158
|
-
})});`
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
);
|
|
23
|
+
var DeferredDataScripts_default = () => {
|
|
24
|
+
return null;
|
|
162
25
|
};
|
|
163
|
-
var DeferredDataScripts_default = DeferredDataScripts;
|
|
164
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
165
27
|
0 && (module.exports = {});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var DeferredDataScripts_node_exports = {};
|
|
19
|
+
__export(DeferredDataScripts_node_exports, {
|
|
20
|
+
default: () => DeferredDataScripts_node_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(DeferredDataScripts_node_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_react_router_dom = require("react-router-dom");
|
|
26
|
+
var import_serialize = require("@modern-js/utils/serialize");
|
|
27
|
+
var import_common = require("../../common");
|
|
28
|
+
var import_utils = require("./utils");
|
|
29
|
+
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
30
|
+
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
31
|
+
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resovle(e)};`;
|
|
32
|
+
const DeferredDataScripts = () => {
|
|
33
|
+
const context = (0, import_react.useContext)(import_react_router_dom.UNSAFE_DataRouterContext);
|
|
34
|
+
const { staticContext } = context || {};
|
|
35
|
+
const hydratedRef = (0, import_react.useRef)(false);
|
|
36
|
+
(0, import_react.useEffect)(() => {
|
|
37
|
+
hydratedRef.current = true;
|
|
38
|
+
}, []);
|
|
39
|
+
const deferredScripts = (0, import_react.useMemo)(() => {
|
|
40
|
+
if (!staticContext) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const activeDeferreds = staticContext.activeDeferreds || [];
|
|
44
|
+
const _ROUTER_DATA = {
|
|
45
|
+
loaderData: staticContext.loaderData,
|
|
46
|
+
errors: (0, import_utils.serializeErrors)(staticContext.errors)
|
|
47
|
+
};
|
|
48
|
+
let initialScripts = [
|
|
49
|
+
`_ROUTER_DATA = ${(0, import_serialize.serializeJson)(_ROUTER_DATA)};`,
|
|
50
|
+
`_ROUTER_DATA.s = ${setupFnStr}`,
|
|
51
|
+
`_ROUTER_DATA.r = ${resolveFnStr}`,
|
|
52
|
+
`_ROUTER_DATA.p = ${preResolvedFnStr}`
|
|
53
|
+
].join("\n");
|
|
54
|
+
const deferredDataScripts = [];
|
|
55
|
+
initialScripts += Object.entries(activeDeferreds).map(([routeId, deferredData]) => {
|
|
56
|
+
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
57
|
+
const { deferredKeys } = deferredData;
|
|
58
|
+
const deferredKeyPromiseStr = deferredKeys.map((key) => {
|
|
59
|
+
if (pendingKeys.has(key)) {
|
|
60
|
+
deferredDataScripts.push(
|
|
61
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
62
|
+
DeferredDataScript,
|
|
63
|
+
{
|
|
64
|
+
data: deferredData.data[key],
|
|
65
|
+
dataKey: key,
|
|
66
|
+
routeId
|
|
67
|
+
},
|
|
68
|
+
`${routeId} | ${key}`
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
return `${JSON.stringify(key)}: _ROUTER_DATA.s(${JSON.stringify(
|
|
72
|
+
routeId
|
|
73
|
+
)},${JSON.stringify(key)}) `;
|
|
74
|
+
} else {
|
|
75
|
+
const trackedPromise = deferredData.data[key];
|
|
76
|
+
if (typeof trackedPromise._error !== "undefined") {
|
|
77
|
+
const error = {
|
|
78
|
+
message: trackedPromise._error.message,
|
|
79
|
+
stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
|
|
80
|
+
};
|
|
81
|
+
return `${JSON.stringify(
|
|
82
|
+
key
|
|
83
|
+
)}: _ROUTER_DATA.p(${void 0}, ${(0, import_serialize.serializeJson)(error)})`;
|
|
84
|
+
} else {
|
|
85
|
+
if (typeof trackedPromise._data === "undefined") {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return `${JSON.stringify(key)}: _ROUTER_DATA.p(${(0, import_serialize.serializeJson)(
|
|
91
|
+
trackedPromise._data
|
|
92
|
+
)})`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}).join(",\n");
|
|
96
|
+
return `Object.assign(_ROUTER_DATA.loaderData[${JSON.stringify(
|
|
97
|
+
routeId
|
|
98
|
+
)}], {${deferredKeyPromiseStr}});`;
|
|
99
|
+
}).join("\n");
|
|
100
|
+
return [initialScripts, deferredDataScripts];
|
|
101
|
+
}, []);
|
|
102
|
+
if (!deferredScripts) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
106
|
+
!hydratedRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
107
|
+
"script",
|
|
108
|
+
{
|
|
109
|
+
async: true,
|
|
110
|
+
suppressHydrationWarning: true,
|
|
111
|
+
dangerouslySetInnerHTML: { __html: deferredScripts[0] }
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
!hydratedRef.current && deferredScripts[1],
|
|
115
|
+
import_common.JSX_SHELL_STREAM_END_MARK
|
|
116
|
+
] });
|
|
117
|
+
};
|
|
118
|
+
const DeferredDataScript = ({
|
|
119
|
+
data,
|
|
120
|
+
routeId,
|
|
121
|
+
dataKey
|
|
122
|
+
}) => {
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: typeof document === "undefined" && data && dataKey && routeId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
import_react_router_dom.Await,
|
|
125
|
+
{
|
|
126
|
+
resolve: data,
|
|
127
|
+
errorElement: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorDeferredDataScript, { routeId, dataKey }),
|
|
128
|
+
children: (data2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
129
|
+
"script",
|
|
130
|
+
{
|
|
131
|
+
async: true,
|
|
132
|
+
suppressHydrationWarning: true,
|
|
133
|
+
dangerouslySetInnerHTML: {
|
|
134
|
+
__html: `_ROUTER_DATA.r(${JSON.stringify(
|
|
135
|
+
routeId
|
|
136
|
+
)}, ${JSON.stringify(dataKey)}, ${(0, import_serialize.serializeJson)(data2)});`
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
) : null });
|
|
142
|
+
};
|
|
143
|
+
const ErrorDeferredDataScript = ({
|
|
144
|
+
routeId,
|
|
145
|
+
dataKey
|
|
146
|
+
}) => {
|
|
147
|
+
const error = (0, import_react_router_dom.useAsyncError)();
|
|
148
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
149
|
+
"script",
|
|
150
|
+
{
|
|
151
|
+
suppressHydrationWarning: true,
|
|
152
|
+
dangerouslySetInnerHTML: {
|
|
153
|
+
__html: `_ROUTER_DATA.r(${JSON.stringify(routeId)}, ${JSON.stringify(
|
|
154
|
+
dataKey
|
|
155
|
+
)}, ${void 0}, ${(0, import_serialize.serializeJson)({
|
|
156
|
+
message: error.message,
|
|
157
|
+
stack: error.stack
|
|
158
|
+
})});`
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
var DeferredDataScripts_node_default = DeferredDataScripts;
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {});
|
|
@@ -138,8 +138,7 @@ var cli_default = () => ({
|
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
const
|
|
142
|
-
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);
|
|
143
142
|
ssrConfigMap.set(entryName, ssrConfig || useSSG);
|
|
144
143
|
if (ssrConfig || useSSG) {
|
|
145
144
|
imports.push({
|
|
@@ -21,7 +21,15 @@ __export(serverRender_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(serverRender_exports);
|
|
23
23
|
var import_utils = require("../utils");
|
|
24
|
+
var import_utils2 = require("./utils");
|
|
24
25
|
async function serverRender(options) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if ((_a = options.context.ssrContext) == null ? void 0 : _a.template) {
|
|
28
|
+
options.context.ssrContext.template = (_b = options.context.ssrContext) == null ? void 0 : _b.template.replace(
|
|
29
|
+
"</head>",
|
|
30
|
+
`${import_utils2.CSS_CHUNKS_PLACEHOLDER}</head>`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
25
33
|
if ((0, import_utils.isReact18)() && options.config.mode === "stream") {
|
|
26
34
|
const pipe = await require("./renderToStream").render(options);
|
|
27
35
|
return pipe;
|
|
@@ -33,8 +33,8 @@ module.exports = __toCommonJS(bulidTemplate_before_exports);
|
|
|
33
33
|
var import_react_helmet = __toESM(require("react-helmet"));
|
|
34
34
|
var import_react_router_dom = require("react-router-dom");
|
|
35
35
|
var import_helmet = __toESM(require("../helmet"));
|
|
36
|
+
var import_utils = require("../utils");
|
|
36
37
|
var import_buildTemplate = require("./buildTemplate.share");
|
|
37
|
-
const CSS_CHUNKS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
|
|
38
38
|
function getHeadTemplate(beforeEntryTemplate, context) {
|
|
39
39
|
const callbacks = [
|
|
40
40
|
(headTemplate2) => {
|
|
@@ -50,7 +50,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
50
50
|
}
|
|
51
51
|
return (0, import_buildTemplate.buildTemplate)(headTemplate, callbacks);
|
|
52
52
|
function injectCss(headTemplate2) {
|
|
53
|
-
return headTemplate2.replace(CSS_CHUNKS_PLACEHOLDER, getCssChunks());
|
|
53
|
+
return headTemplate2.replace(import_utils.CSS_CHUNKS_PLACEHOLDER, getCssChunks());
|
|
54
54
|
function getCssChunks() {
|
|
55
55
|
const { routeManifest, routerContext, routes } = context;
|
|
56
56
|
if (!routeManifest || !routerContext || !routes) {
|
|
@@ -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;
|
|
@@ -21,11 +21,18 @@ __export(renderToPipe_worker_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(renderToPipe_worker_exports);
|
|
23
23
|
var import_types = require("../types");
|
|
24
|
+
var import_common = require("../../../common");
|
|
24
25
|
var import_template = require("./template");
|
|
26
|
+
var ShellChunkStatus = /* @__PURE__ */ ((ShellChunkStatus2) => {
|
|
27
|
+
ShellChunkStatus2[ShellChunkStatus2["IDLE"] = 0] = "IDLE";
|
|
28
|
+
ShellChunkStatus2[ShellChunkStatus2["START"] = 1] = "START";
|
|
29
|
+
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 2] = "FINIESH";
|
|
30
|
+
return ShellChunkStatus2;
|
|
31
|
+
})(ShellChunkStatus || {});
|
|
25
32
|
function renderToPipe(rootElement, context, options) {
|
|
26
|
-
let
|
|
33
|
+
let shellChunkStatus = 0 /* IDLE */;
|
|
27
34
|
const { ssrContext } = context;
|
|
28
|
-
const forUserPipe = async (
|
|
35
|
+
const forUserPipe = async () => {
|
|
29
36
|
let renderToReadableStream;
|
|
30
37
|
try {
|
|
31
38
|
({ renderToReadableStream } = require("react-dom/server"));
|
|
@@ -57,11 +64,20 @@ function renderToPipe(rootElement, context, options) {
|
|
|
57
64
|
controller.close();
|
|
58
65
|
return;
|
|
59
66
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
if (shellChunkStatus !== 2 /* FINIESH */) {
|
|
68
|
+
let concatedChunk = new TextDecoder().decode(value);
|
|
69
|
+
if (shellChunkStatus === 0 /* IDLE */) {
|
|
70
|
+
concatedChunk = `${shellBefore}${concatedChunk}`;
|
|
71
|
+
shellChunkStatus = 1 /* START */;
|
|
72
|
+
}
|
|
73
|
+
if (shellChunkStatus === 1 /* START */ && concatedChunk.endsWith(import_common.ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
74
|
+
concatedChunk = concatedChunk.replace(
|
|
75
|
+
import_common.ESCAPED_SHELL_STREAM_END_MARK,
|
|
76
|
+
shellAfter
|
|
77
|
+
);
|
|
78
|
+
shellChunkStatus = 2 /* FINIESH */;
|
|
79
|
+
}
|
|
80
|
+
controller.enqueue(encodeForWebStream(concatedChunk));
|
|
65
81
|
} else {
|
|
66
82
|
controller.enqueue(value);
|
|
67
83
|
}
|
|
@@ -70,7 +86,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
70
86
|
push();
|
|
71
87
|
}
|
|
72
88
|
});
|
|
73
|
-
return
|
|
89
|
+
return injectableStream;
|
|
74
90
|
} catch (err) {
|
|
75
91
|
ssrContext.metrics.emitCounter("app.render.streaming.shell.error", 1);
|
|
76
92
|
const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = (0, import_template.getTemplates)(
|
|
@@ -81,7 +97,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
81
97
|
return fallbackHtml;
|
|
82
98
|
}
|
|
83
99
|
};
|
|
84
|
-
return forUserPipe;
|
|
100
|
+
return forUserPipe();
|
|
85
101
|
}
|
|
86
102
|
let encoder;
|
|
87
103
|
function encodeForWebStream(thing) {
|
|
@@ -17,9 +17,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var utils_exports = {};
|
|
19
19
|
__export(utils_exports, {
|
|
20
|
+
CSS_CHUNKS_PLACEHOLDER: () => CSS_CHUNKS_PLACEHOLDER,
|
|
20
21
|
getLoadableScripts: () => getLoadableScripts
|
|
21
22
|
});
|
|
22
23
|
module.exports = __toCommonJS(utils_exports);
|
|
24
|
+
const CSS_CHUNKS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
|
|
23
25
|
function getLoadableScripts(extractor) {
|
|
24
26
|
const check = (scripts2) => (scripts2 || "").includes("__LOADABLE_REQUIRED_CHUNKS___ext");
|
|
25
27
|
const scripts = extractor.getScriptTags();
|
|
@@ -30,5 +32,6 @@ function getLoadableScripts(extractor) {
|
|
|
30
32
|
}
|
|
31
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
34
|
0 && (module.exports = {
|
|
35
|
+
CSS_CHUNKS_PLACEHOLDER,
|
|
33
36
|
getLoadableScripts
|
|
34
37
|
});
|
|
@@ -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
|
],
|