@modern-js/runtime 2.26.0 → 2.28.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 +30 -0
- package/dist/cjs/core/compatible.js +16 -17
- package/dist/cjs/core/loader/useLoader.js +10 -12
- package/dist/cjs/core/plugin.js +3 -2
- package/dist/cjs/document/Html.js +4 -3
- package/dist/cjs/document/cli/index.js +138 -138
- package/dist/cjs/router/cli/index.js +91 -92
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +4 -2
- package/dist/cjs/router/runtime/PrefetchLink.js +8 -4
- package/dist/cjs/router/runtime/plugin.js +4 -3
- package/dist/cjs/router/runtime/plugin.node.js +11 -4
- package/dist/cjs/router/runtime/utils.js +3 -3
- package/dist/cjs/ssr/cli/index.js +122 -123
- package/dist/cjs/ssr/index.js +105 -107
- package/dist/cjs/ssr/index.node.js +37 -38
- package/dist/cjs/ssr/prefetch.js +37 -39
- package/dist/cjs/ssr/react/prerender/util.js +4 -2
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -2
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +8 -7
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +8 -6
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +2 -1
- package/dist/cjs/state/cli/index.js +70 -72
- package/dist/cjs/state/runtime/plugin.js +40 -42
- package/dist/esm/core/compatible.js +10 -9
- package/dist/esm/core/loader/useLoader.js +9 -9
- package/dist/esm/core/plugin.js +3 -2
- package/dist/esm/document/Html.js +4 -3
- package/dist/esm/document/cli/index.js +4 -3
- package/dist/esm/router/cli/index.js +2 -1
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +4 -2
- package/dist/esm/router/runtime/PrefetchLink.js +8 -4
- package/dist/esm/router/runtime/plugin.js +4 -3
- package/dist/esm/router/runtime/plugin.node.js +11 -4
- package/dist/esm/router/runtime/utils.js +3 -3
- package/dist/esm/ssr/cli/index.js +7 -6
- package/dist/esm/ssr/index.js +6 -6
- package/dist/esm/ssr/index.node.js +2 -1
- package/dist/esm/ssr/prefetch.js +2 -2
- package/dist/esm/ssr/react/prerender/util.js +4 -2
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -2
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +8 -7
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +7 -7
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +2 -1
- package/dist/esm/state/runtime/plugin.js +2 -2
- package/dist/esm-node/core/compatible.js +16 -17
- package/dist/esm-node/core/loader/useLoader.js +10 -12
- package/dist/esm-node/core/plugin.js +3 -2
- package/dist/esm-node/document/Html.js +4 -3
- package/dist/esm-node/document/cli/index.js +138 -138
- package/dist/esm-node/router/cli/index.js +91 -92
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +4 -2
- package/dist/esm-node/router/runtime/PrefetchLink.js +8 -4
- package/dist/esm-node/router/runtime/plugin.js +4 -3
- package/dist/esm-node/router/runtime/plugin.node.js +11 -4
- package/dist/esm-node/router/runtime/utils.js +3 -3
- package/dist/esm-node/ssr/cli/index.js +122 -123
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +2 -2
- package/dist/esm-node/ssr/index.js +105 -107
- package/dist/esm-node/ssr/index.node.js +37 -38
- package/dist/esm-node/ssr/prefetch.js +37 -39
- package/dist/esm-node/ssr/react/prerender/util.js +4 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +8 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +8 -6
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +2 -1
- package/dist/esm-node/state/cli/index.js +70 -72
- package/dist/esm-node/state/runtime/plugin.js +40 -42
- package/package.json +13 -10
package/dist/cjs/ssr/index.js
CHANGED
|
@@ -28,128 +28,126 @@ const _withCallback = require("./react/withCallback");
|
|
|
28
28
|
const _utils = require("./utils");
|
|
29
29
|
const _utils1 = require("./serverRender/utils");
|
|
30
30
|
_export_star._(require("./react"), exports);
|
|
31
|
-
const ssr = (config) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(0,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
children: /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
72
|
-
context: hydrateContext
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
SSRApp = (0, _hoistnonreactstatics.default)(SSRApp, App);
|
|
76
|
-
ModernHydrate(/* @__PURE__ */ (0, _jsxruntime.jsx)(SSRApp, {}));
|
|
77
|
-
}, loadableReadyOptions);
|
|
78
|
-
} else {
|
|
79
|
-
(0, _component.loadableReady)(() => {
|
|
80
|
-
ModernHydrate(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
31
|
+
const ssr = (config) => ({
|
|
32
|
+
name: "@modern-js/plugin-ssr",
|
|
33
|
+
setup: () => {
|
|
34
|
+
const mockResp = (0, _utils.mockResponse)();
|
|
35
|
+
if (config.inlineScript === false) {
|
|
36
|
+
window._SSR_DATA = (0, _runtimebrowser.parsedJSONFromElement)(_utils1.SSR_DATA_JSON_ID);
|
|
37
|
+
window._ROUTER_DATA = (0, _runtimebrowser.parsedJSONFromElement)(_utils1.ROUTER_DATA_JSON_ID);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
client: async ({ App, context, ModernRender, ModernHydrate }) => {
|
|
41
|
+
var _window__SSR_DATA, _window;
|
|
42
|
+
const hydrateContext = {
|
|
43
|
+
...context,
|
|
44
|
+
get routes() {
|
|
45
|
+
return context.routes;
|
|
46
|
+
},
|
|
47
|
+
_hydration: true
|
|
48
|
+
};
|
|
49
|
+
const callback = () => {
|
|
50
|
+
delete hydrateContext._hydration;
|
|
51
|
+
};
|
|
52
|
+
const renderLevel = ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : _window__SSR_DATA.renderLevel) || _types.RenderLevel.CLIENT_RENDER;
|
|
53
|
+
if ((0, _utils.isReact18)() && config.mode === "stream") {
|
|
54
|
+
return streamSSRHydrate();
|
|
55
|
+
}
|
|
56
|
+
return stringSSRHydrate();
|
|
57
|
+
function stringSSRHydrate() {
|
|
58
|
+
if (renderLevel === _types.RenderLevel.CLIENT_RENDER || renderLevel === _types.RenderLevel.SERVER_PREFETCH) {
|
|
59
|
+
ModernRender(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
60
|
+
context
|
|
61
|
+
}));
|
|
62
|
+
} else if (renderLevel === _types.RenderLevel.SERVER_RENDER) {
|
|
63
|
+
const loadableReadyOptions = {
|
|
64
|
+
chunkLoadingGlobal: config.chunkLoadingGlobal
|
|
65
|
+
};
|
|
66
|
+
if ((0, _utils.isReact18)()) {
|
|
67
|
+
(0, _component.loadableReady)(() => {
|
|
68
|
+
let SSRApp = () => /* @__PURE__ */ (0, _jsxruntime.jsx)(_withCallback.WithCallback, {
|
|
69
|
+
callback,
|
|
70
|
+
children: /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
81
71
|
context: hydrateContext
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
SSRApp = (0, _hoistnonreactstatics.default)(SSRApp, App);
|
|
75
|
+
ModernHydrate(/* @__PURE__ */ (0, _jsxruntime.jsx)(SSRApp, {}));
|
|
76
|
+
}, loadableReadyOptions);
|
|
85
77
|
} else {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
context
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function streamSSRHydrate() {
|
|
93
|
-
if (renderLevel === _types.RenderLevel.SERVER_RENDER) {
|
|
94
|
-
let SSRApp = () => /* @__PURE__ */ (0, _jsxruntime.jsx)(_withCallback.WithCallback, {
|
|
95
|
-
callback,
|
|
96
|
-
children: /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
78
|
+
(0, _component.loadableReady)(() => {
|
|
79
|
+
ModernHydrate(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
97
80
|
context: hydrateContext
|
|
98
|
-
})
|
|
99
|
-
});
|
|
100
|
-
SSRApp = (0, _hoistnonreactstatics.default)(SSRApp, App);
|
|
101
|
-
ModernHydrate(/* @__PURE__ */ (0, _jsxruntime.jsx)(SSRApp, {}));
|
|
102
|
-
} else {
|
|
103
|
-
ModernRender(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
104
|
-
context
|
|
105
|
-
}));
|
|
81
|
+
}), callback);
|
|
82
|
+
}, loadableReadyOptions);
|
|
106
83
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var _window__SSR_DATA, _window__SSR_DATA_context;
|
|
111
|
-
const request = window === null || window === void 0 ? void 0 : (_window__SSR_DATA = window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_context = _window__SSR_DATA.context) === null || _window__SSR_DATA_context === void 0 ? void 0 : _window__SSR_DATA_context.request;
|
|
112
|
-
if (!request) {
|
|
113
|
-
context.ssrContext = {
|
|
114
|
-
...context.ssrContext,
|
|
115
|
-
response: mockResp,
|
|
116
|
-
request: (0, _utils.formatClient)({})
|
|
117
|
-
};
|
|
118
|
-
return next({
|
|
84
|
+
} else {
|
|
85
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
86
|
+
ModernRender(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
119
87
|
context
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function streamSSRHydrate() {
|
|
92
|
+
if (renderLevel === _types.RenderLevel.SERVER_RENDER) {
|
|
93
|
+
let SSRApp = () => /* @__PURE__ */ (0, _jsxruntime.jsx)(_withCallback.WithCallback, {
|
|
94
|
+
callback,
|
|
95
|
+
children: /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
96
|
+
context: hydrateContext
|
|
97
|
+
})
|
|
120
98
|
});
|
|
99
|
+
SSRApp = (0, _hoistnonreactstatics.default)(SSRApp, App);
|
|
100
|
+
ModernHydrate(/* @__PURE__ */ (0, _jsxruntime.jsx)(SSRApp, {}));
|
|
101
|
+
} else {
|
|
102
|
+
ModernRender(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
103
|
+
context
|
|
104
|
+
}));
|
|
121
105
|
}
|
|
122
|
-
|
|
123
|
-
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
init({ context }, next) {
|
|
109
|
+
var _window__SSR_DATA_context, _window__SSR_DATA, _window;
|
|
110
|
+
const request = (_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_context = _window__SSR_DATA.context) === null || _window__SSR_DATA_context === void 0 ? void 0 : _window__SSR_DATA_context.request;
|
|
111
|
+
if (!request) {
|
|
112
|
+
context.ssrContext = {
|
|
113
|
+
...context.ssrContext,
|
|
114
|
+
response: mockResp,
|
|
115
|
+
request: (0, _utils.formatClient)({})
|
|
116
|
+
};
|
|
124
117
|
return next({
|
|
125
118
|
context
|
|
126
119
|
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
}
|
|
120
|
+
}
|
|
121
|
+
context.ssrContext.response = mockResp;
|
|
122
|
+
context.ssrContext.request = (0, _utils.formatClient)(request);
|
|
123
|
+
return next({
|
|
124
|
+
context
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
pickContext: ({ context, pickedContext }, next) => {
|
|
128
|
+
var _window__SSR_DATA_context, _window__SSR_DATA, _window;
|
|
129
|
+
const request = (_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_context = _window__SSR_DATA.context) === null || _window__SSR_DATA_context === void 0 ? void 0 : _window__SSR_DATA_context.request;
|
|
130
|
+
const { initialData } = context;
|
|
131
|
+
if (!request) {
|
|
141
132
|
return next({
|
|
142
133
|
context,
|
|
143
134
|
pickedContext: {
|
|
144
135
|
...pickedContext,
|
|
145
|
-
initialData
|
|
146
|
-
request,
|
|
147
|
-
response: mockResp
|
|
136
|
+
initialData
|
|
148
137
|
}
|
|
149
138
|
});
|
|
150
139
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
140
|
+
return next({
|
|
141
|
+
context,
|
|
142
|
+
pickedContext: {
|
|
143
|
+
...pickedContext,
|
|
144
|
+
initialData,
|
|
145
|
+
request,
|
|
146
|
+
response: mockResp
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
155
153
|
const _default = ssr;
|
|
@@ -22,42 +22,41 @@ const _interop_require_default = require("@swc/helpers/_/_interop_require_defaul
|
|
|
22
22
|
const _utils = require("./utils");
|
|
23
23
|
const _serverRender = /* @__PURE__ */ _interop_require_default._(require("./serverRender"));
|
|
24
24
|
_export_star._(require("./react"), exports);
|
|
25
|
-
const ssr = (config = {}) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
25
|
+
const ssr = (config = {}) => ({
|
|
26
|
+
name: "@modern-js/plugin-ssr",
|
|
27
|
+
setup: () => {
|
|
28
|
+
return {
|
|
29
|
+
server: async ({ App, context }) => {
|
|
30
|
+
const html = await (0, _serverRender.default)({
|
|
31
|
+
context,
|
|
32
|
+
App,
|
|
33
|
+
config
|
|
34
|
+
});
|
|
35
|
+
return html;
|
|
36
|
+
},
|
|
37
|
+
init({ context }, next) {
|
|
38
|
+
const { request } = context.ssrContext;
|
|
39
|
+
context.ssrContext.request = (0, _utils.formatServer)(request);
|
|
40
|
+
context.ssrContext.mode = config.mode;
|
|
41
|
+
return next({
|
|
42
|
+
context
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
pickContext: ({ context, pickedContext }, next) => {
|
|
46
|
+
var _context;
|
|
47
|
+
const { request, response } = (_context = context) === null || _context === void 0 ? void 0 : _context.ssrContext;
|
|
48
|
+
const { initialData } = context;
|
|
49
|
+
return next({
|
|
50
|
+
context,
|
|
51
|
+
pickedContext: {
|
|
52
|
+
...pickedContext,
|
|
53
|
+
initialData,
|
|
54
|
+
request,
|
|
55
|
+
response
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
63
62
|
const _default = ssr;
|
package/dist/cjs/ssr/prefetch.js
CHANGED
|
@@ -12,48 +12,46 @@ const _jsxruntime = require("react/jsx-runtime");
|
|
|
12
12
|
const _server = require("react-dom/server");
|
|
13
13
|
const _runtimenode = require("@modern-js/utils/runtime-node");
|
|
14
14
|
const _server1 = require("@loadable/server");
|
|
15
|
-
const prefetch = async (App, context) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
].filter(Boolean)
|
|
26
|
-
});
|
|
27
|
-
(0, _server.renderToStaticMarkup)(extractor.collectChunks(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
28
|
-
context
|
|
29
|
-
})));
|
|
30
|
-
} else {
|
|
31
|
-
(0, _server.renderToStaticMarkup)(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
32
|
-
context
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
if (!context.loaderManager.hasPendingLoaders()) {
|
|
36
|
-
return {
|
|
37
|
-
initialData: context.initialData,
|
|
38
|
-
i18nData: context.__i18nData__
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const loadersData = await context.loaderManager.awaitPendingLoaders();
|
|
42
|
-
Object.keys(loadersData).forEach((id) => {
|
|
43
|
-
const data = loadersData[id];
|
|
44
|
-
if (data._error) {
|
|
45
|
-
ssrContext.logger.error("App Prefetch Loader", data._error);
|
|
46
|
-
ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
|
|
47
|
-
delete data._error;
|
|
48
|
-
}
|
|
15
|
+
const prefetch = async (App, context) => (0, _runtimenode.run)(context.ssrContext.request.headers, async () => {
|
|
16
|
+
var _context_store, _context;
|
|
17
|
+
const { ssrContext } = context;
|
|
18
|
+
const { loadableStats } = ssrContext;
|
|
19
|
+
if (loadableStats) {
|
|
20
|
+
const extractor = new _server1.ChunkExtractor({
|
|
21
|
+
stats: loadableStats,
|
|
22
|
+
entrypoints: [
|
|
23
|
+
ssrContext.entryName
|
|
24
|
+
].filter(Boolean)
|
|
49
25
|
});
|
|
26
|
+
(0, _server.renderToStaticMarkup)(extractor.collectChunks(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
27
|
+
context
|
|
28
|
+
})));
|
|
29
|
+
} else {
|
|
30
|
+
(0, _server.renderToStaticMarkup)(/* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
31
|
+
context
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (!context.loaderManager.hasPendingLoaders()) {
|
|
50
35
|
return {
|
|
51
|
-
loadersData,
|
|
52
36
|
initialData: context.initialData,
|
|
53
|
-
i18nData: context.__i18nData__
|
|
54
|
-
// todo: move to plugin state
|
|
55
|
-
storeState: context === null || context === void 0 ? void 0 : (_context_store = context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
|
|
37
|
+
i18nData: context.__i18nData__
|
|
56
38
|
};
|
|
39
|
+
}
|
|
40
|
+
const loadersData = await context.loaderManager.awaitPendingLoaders();
|
|
41
|
+
Object.keys(loadersData).forEach((id) => {
|
|
42
|
+
const data = loadersData[id];
|
|
43
|
+
if (data._error) {
|
|
44
|
+
ssrContext.logger.error("App Prefetch Loader", data._error);
|
|
45
|
+
ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
|
|
46
|
+
delete data._error;
|
|
47
|
+
}
|
|
57
48
|
});
|
|
58
|
-
|
|
49
|
+
return {
|
|
50
|
+
loadersData,
|
|
51
|
+
initialData: context.initialData,
|
|
52
|
+
i18nData: context.__i18nData__,
|
|
53
|
+
// todo: move to plugin state
|
|
54
|
+
storeState: (_context = context) === null || _context === void 0 ? void 0 : (_context_store = _context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
|
|
55
|
+
};
|
|
56
|
+
});
|
|
59
57
|
const _default = prefetch;
|
|
@@ -55,8 +55,9 @@ const aggKeysFromPropsList = function aggKeysFromPropsList2(propsList, propName)
|
|
|
55
55
|
}, {});
|
|
56
56
|
const res = propsList.filter((props) => usefulObject(props[propName])).reduce((result, next) => {
|
|
57
57
|
REQUEST_META.forEach((key) => {
|
|
58
|
+
var _prop;
|
|
58
59
|
const prop = next[propName];
|
|
59
|
-
if ((prop === null ||
|
|
60
|
+
if (((_prop = prop) === null || _prop === void 0 ? void 0 : _prop.hasOwnProperty(key)) && usefulArray(prop[key])) {
|
|
60
61
|
result[key] = unique(result[key].concat(prop[key]));
|
|
61
62
|
}
|
|
62
63
|
});
|
|
@@ -79,8 +80,9 @@ const aggMatchesFromPropsList = function aggMatchesFromPropsList2(propsList, pro
|
|
|
79
80
|
}, {});
|
|
80
81
|
const res = propsList.filter((props) => usefulObject(props[propName])).reduce((result, next) => {
|
|
81
82
|
REQUEST_META.forEach((key) => {
|
|
83
|
+
var _prop;
|
|
82
84
|
const prop = next[propName];
|
|
83
|
-
if ((prop === null ||
|
|
85
|
+
if (((_prop = prop) === null || _prop === void 0 ? void 0 : _prop.hasOwnProperty(key)) && usefulObject(prop[key])) {
|
|
84
86
|
result[key] = Object.assign(result[key], prop[key]);
|
|
85
87
|
}
|
|
86
88
|
});
|
|
@@ -31,6 +31,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
31
31
|
function injectCss(headTemplate2) {
|
|
32
32
|
return headTemplate2.replace(_utils.CSS_CHUNKS_PLACEHOLDER, getCssChunks());
|
|
33
33
|
function getCssChunks() {
|
|
34
|
+
var _matches;
|
|
34
35
|
const { routeManifest, routerContext, routes } = context;
|
|
35
36
|
if (!routeManifest || !routerContext || !routes) {
|
|
36
37
|
return "";
|
|
@@ -38,7 +39,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
38
39
|
const { routeAssets } = routeManifest;
|
|
39
40
|
const cssChunks = [];
|
|
40
41
|
const matches = (0, _router.matchRoutes)(routes, routerContext.location, routerContext.basename);
|
|
41
|
-
matches === null ||
|
|
42
|
+
(_matches = matches) === null || _matches === void 0 ? void 0 : _matches.forEach((match, index) => {
|
|
42
43
|
if (!index) {
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
@@ -48,7 +49,8 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
48
49
|
if (routeManifest2) {
|
|
49
50
|
const { referenceCssAssets = [] } = routeManifest2;
|
|
50
51
|
const _cssChunks = referenceCssAssets.filter((asset) => {
|
|
51
|
-
|
|
52
|
+
var _asset;
|
|
53
|
+
return ((_asset = asset) === null || _asset === void 0 ? void 0 : _asset.endsWith(".css")) && !headTemplate2.includes(asset);
|
|
52
54
|
});
|
|
53
55
|
cssChunks.push(..._cssChunks);
|
|
54
56
|
}
|
|
@@ -23,6 +23,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
23
23
|
const chunkVec = [];
|
|
24
24
|
const forUserPipe = (stream) => {
|
|
25
25
|
return new Promise((resolve) => {
|
|
26
|
+
var _ssrContext;
|
|
26
27
|
let renderToPipeableStream;
|
|
27
28
|
try {
|
|
28
29
|
({ renderToPipeableStream } = require("react-dom/server"));
|
|
@@ -30,11 +31,11 @@ function renderToPipe(rootElement, context, options) {
|
|
|
30
31
|
}
|
|
31
32
|
const { pipe } = renderToPipeableStream(rootElement, {
|
|
32
33
|
...options,
|
|
33
|
-
nonce: ssrContext === null ||
|
|
34
|
+
nonce: (_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.nonce,
|
|
34
35
|
onShellReady() {
|
|
35
|
-
var _options_onShellReady;
|
|
36
|
+
var _options_onShellReady, _options;
|
|
36
37
|
const { shellAfter, shellBefore } = (0, _template.getTemplates)(context, _types.RenderLevel.SERVER_RENDER);
|
|
37
|
-
options === null ||
|
|
38
|
+
(_options = options) === null || _options === void 0 ? void 0 : (_options_onShellReady = _options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(_options);
|
|
38
39
|
const injectableTransform = new _stream.Transform({
|
|
39
40
|
transform(chunk, _encoding, callback) {
|
|
40
41
|
try {
|
|
@@ -62,18 +63,18 @@ function renderToPipe(rootElement, context, options) {
|
|
|
62
63
|
resolve(pipe(injectableTransform).pipe(stream));
|
|
63
64
|
},
|
|
64
65
|
onShellError(error) {
|
|
65
|
-
var _options_onShellError;
|
|
66
|
+
var _options_onShellError, _options;
|
|
66
67
|
ssrContext.metrics.emitCounter("app.render.streaming.shell.error", 1);
|
|
67
68
|
const { shellAfter, shellBefore } = (0, _template.getTemplates)(context, _types.RenderLevel.CLIENT_RENDER);
|
|
68
69
|
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
69
70
|
resolve(fallbackHtml);
|
|
70
|
-
options === null ||
|
|
71
|
+
(_options = options) === null || _options === void 0 ? void 0 : (_options_onShellError = _options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(_options, error);
|
|
71
72
|
},
|
|
72
73
|
onError(error) {
|
|
73
|
-
var _options_onError;
|
|
74
|
+
var _options_onError, _options;
|
|
74
75
|
ssrContext.logger.error("An error occurs during streaming SSR", error);
|
|
75
76
|
ssrContext.metrics.emitCounter("app.render.streaming.error", 1);
|
|
76
|
-
options === null ||
|
|
77
|
+
(_options = options) === null || _options === void 0 ? void 0 : (_options_onError = _options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(_options, error);
|
|
77
78
|
}
|
|
78
79
|
});
|
|
79
80
|
});
|
|
@@ -28,14 +28,15 @@ function renderToPipe(rootElement, context, options) {
|
|
|
28
28
|
}
|
|
29
29
|
const { shellAfter, shellBefore } = (0, _template.getTemplates)(context, _types.RenderLevel.SERVER_RENDER);
|
|
30
30
|
try {
|
|
31
|
+
var _ssrContext;
|
|
31
32
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
32
33
|
...options,
|
|
33
|
-
nonce: ssrContext === null ||
|
|
34
|
+
nonce: (_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.nonce,
|
|
34
35
|
onError(error) {
|
|
35
|
-
var _options_onError;
|
|
36
|
-
ssrContext === null ||
|
|
37
|
-
ssrContext === null ||
|
|
38
|
-
options === null ||
|
|
36
|
+
var _ssrContext2, _ssrContext12, _options_onError, _options;
|
|
37
|
+
(_ssrContext2 = ssrContext) === null || _ssrContext2 === void 0 ? void 0 : _ssrContext2.logger.error("An error occurs during streaming SSR", error);
|
|
38
|
+
(_ssrContext12 = ssrContext) === null || _ssrContext12 === void 0 ? void 0 : _ssrContext12.metrics.emitCounter("app.render.streaming.error", 1);
|
|
39
|
+
(_options = options) === null || _options === void 0 ? void 0 : (_options_onError = _options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(_options, error);
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
const reader = readableOriginal.getReader();
|
|
@@ -66,7 +67,8 @@ function renderToPipe(rootElement, context, options) {
|
|
|
66
67
|
});
|
|
67
68
|
return injectableStream;
|
|
68
69
|
} catch (err) {
|
|
69
|
-
|
|
70
|
+
var _ssrContext1;
|
|
71
|
+
(_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.metrics.emitCounter("app.render.streaming.shell.error", 1);
|
|
70
72
|
const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = (0, _template.getTemplates)(context, _types.RenderLevel.CLIENT_RENDER);
|
|
71
73
|
const fallbackHtml = `${shellBefore2}${shellAfter2}`;
|
|
72
74
|
return fallbackHtml;
|
|
@@ -11,10 +11,11 @@ Object.defineProperty(exports, "toHtml", {
|
|
|
11
11
|
const _server = require("@loadable/server");
|
|
12
12
|
const _utils = require("../utils");
|
|
13
13
|
const extname = (uri) => {
|
|
14
|
+
var _uri;
|
|
14
15
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
15
16
|
return "";
|
|
16
17
|
}
|
|
17
|
-
return `.${uri === null ||
|
|
18
|
+
return `.${(_uri = uri) === null || _uri === void 0 ? void 0 : _uri.split(".").pop()}` || "";
|
|
18
19
|
};
|
|
19
20
|
const toHtml = (jsx, renderer, next) => {
|
|
20
21
|
const { stats, result: { chunksMap }, config = {}, nonce } = renderer;
|