@modern-js/runtime 2.43.0 → 2.45.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/dist/cjs/ssr/cli/index.js +3 -7
- package/dist/cjs/ssr/prefetch.js +1 -2
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.share.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +36 -10
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +32 -30
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +3 -3
- package/dist/cjs/ssr/serverRender/renderToStream/template.js +3 -3
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +0 -2
- package/dist/cjs/ssr/serverRender/renderToString/index.js +0 -1
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +4 -7
- package/dist/cjs/ssr/serverRender/tracker.js +8 -20
- package/dist/cjs/ssr/serverRender/utils.js +6 -0
- package/dist/esm/ssr/cli/index.js +5 -8
- package/dist/esm/ssr/prefetch.js +1 -2
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.share.js +5 -3
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +168 -33
- package/dist/esm/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +34 -30
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +23 -13
- package/dist/esm/ssr/serverRender/renderToStream/template.js +37 -11
- package/dist/esm/ssr/serverRender/renderToString/entry.js +0 -2
- package/dist/esm/ssr/serverRender/renderToString/index.js +0 -1
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +5 -8
- package/dist/esm/ssr/serverRender/tracker.js +8 -20
- package/dist/esm/ssr/serverRender/utils.js +5 -0
- package/dist/esm-node/ssr/cli/index.js +3 -7
- package/dist/esm-node/ssr/prefetch.js +1 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.share.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +37 -11
- package/dist/esm-node/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +32 -30
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +3 -3
- package/dist/esm-node/ssr/serverRender/renderToStream/template.js +3 -3
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +0 -2
- package/dist/esm-node/ssr/serverRender/renderToString/index.js +0 -1
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +5 -8
- package/dist/esm-node/ssr/serverRender/tracker.js +8 -20
- package/dist/esm-node/ssr/serverRender/utils.js +5 -0
- package/dist/types/ssr/serverRender/renderToStream/buildTemplate.after.d.ts +1 -1
- package/dist/types/ssr/serverRender/renderToStream/buildTemplate.share.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToStream/bulidTemplate.before.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToStream/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.worker.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToStream/template.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToString/entry.d.ts +0 -1
- package/dist/types/ssr/serverRender/tracker.d.ts +1 -1
- package/dist/types/ssr/serverRender/types.d.ts +1 -1
- package/dist/types/ssr/serverRender/utils.d.ts +1 -0
- package/package.json +10 -10
|
@@ -120,24 +120,20 @@ const ssrPlugin = () => ({
|
|
|
120
120
|
},
|
|
121
121
|
modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
|
|
122
122
|
if (ssrConfigMap.get(entrypoint.entryName)) {
|
|
123
|
-
var _bundlerConfigs_find_output, _bundlerConfigs_find
|
|
123
|
+
var _bundlerConfigs_find_output, _bundlerConfigs_find;
|
|
124
124
|
const chunkLoadingGlobal = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : (_bundlerConfigs_find = bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
|
|
125
125
|
const config = api.useResolvedConfigContext();
|
|
126
126
|
const { enableInlineScripts, enableInlineStyles } = config.output;
|
|
127
127
|
const { crossorigin, scriptLoading } = config.html;
|
|
128
|
-
const disablePrerender = typeof ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) === "object" ? Boolean(config.server.ssr.disablePrerender) : false;
|
|
129
|
-
const unsafeHeaders = typeof ((_config_server1 = config.server) === null || _config_server1 === void 0 ? void 0 : _config_server1.ssr) === "object" ? config.server.ssr.unsafeHeaders : void 0;
|
|
130
128
|
plugins.push({
|
|
131
129
|
name: PLUGIN_IDENTIFIER,
|
|
132
130
|
options: JSON.stringify({
|
|
131
|
+
scriptLoading,
|
|
133
132
|
...ssrConfigMap.get(entrypoint.entryName) || {},
|
|
134
133
|
crossorigin,
|
|
135
|
-
scriptLoading,
|
|
136
134
|
chunkLoadingGlobal,
|
|
137
|
-
disablePrerender,
|
|
138
135
|
enableInlineScripts: typeof enableInlineScripts === "function" ? void 0 : enableInlineScripts,
|
|
139
|
-
enableInlineStyles: typeof enableInlineStyles === "function" ? void 0 : enableInlineStyles
|
|
140
|
-
unsafeHeaders
|
|
136
|
+
enableInlineStyles: typeof enableInlineStyles === "function" ? void 0 : enableInlineStyles
|
|
141
137
|
})
|
|
142
138
|
});
|
|
143
139
|
}
|
|
@@ -54,8 +54,7 @@ const prefetch = async (App, context, config, tracker) => run(context.ssrContext
|
|
|
54
54
|
Object.keys(loadersData).forEach((id) => {
|
|
55
55
|
const data = loadersData[id];
|
|
56
56
|
if (data._error) {
|
|
57
|
-
ssrContext.logger.error("App
|
|
58
|
-
ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
|
|
57
|
+
ssrContext.logger.error("App Load use-loader", data._error);
|
|
59
58
|
delete data._error;
|
|
60
59
|
}
|
|
61
60
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const HEAD_REG_EXP = /<head(.|\n)*>(.|\n)*<\/head>/;
|
|
2
2
|
function buildTemplate(template, callbacks) {
|
|
3
|
-
return callbacks.reduce((
|
|
3
|
+
return callbacks.reduce((promise, buildTemplateCb) => promise.then((template2) => buildTemplateCb(template2)), Promise.resolve(template));
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
6
|
HEAD_REG_EXP,
|
|
@@ -2,9 +2,26 @@ import ReactHelmet from "react-helmet";
|
|
|
2
2
|
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
3
3
|
import helmetReplace from "../helmet";
|
|
4
4
|
import { CHUNK_CSS_PLACEHOLDER } from "../constants";
|
|
5
|
-
import { safeReplace } from "../utils";
|
|
5
|
+
import { checkIsNode, safeReplace } from "../utils";
|
|
6
6
|
import { HEAD_REG_EXP, buildTemplate } from "./buildTemplate.share";
|
|
7
|
-
|
|
7
|
+
const readAsset = async (chunk) => {
|
|
8
|
+
const fs = await import("fs/promises");
|
|
9
|
+
const path = await import("path");
|
|
10
|
+
const filepath = path.join(__dirname, chunk);
|
|
11
|
+
return fs.readFile(filepath, "utf-8");
|
|
12
|
+
};
|
|
13
|
+
const checkIsInline = (chunk, enableInline) => {
|
|
14
|
+
if (process.env.NODE_ENV === "production") {
|
|
15
|
+
if (enableInline instanceof RegExp) {
|
|
16
|
+
return enableInline.test(chunk);
|
|
17
|
+
} else {
|
|
18
|
+
return Boolean(enableInline);
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function getHeadTemplate(beforeEntryTemplate, context, pluginConfig) {
|
|
8
25
|
const callbacks = [
|
|
9
26
|
(headTemplate2) => {
|
|
10
27
|
const helmetData = ReactHelmet.renderStatic();
|
|
@@ -18,9 +35,10 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
18
35
|
return "";
|
|
19
36
|
}
|
|
20
37
|
return buildTemplate(headTemplate, callbacks);
|
|
21
|
-
function injectCss(headTemplate2) {
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
async function injectCss(headTemplate2) {
|
|
39
|
+
const css = await getCssChunks();
|
|
40
|
+
return safeReplace(headTemplate2, CHUNK_CSS_PLACEHOLDER, css);
|
|
41
|
+
async function getCssChunks() {
|
|
24
42
|
const { routeManifest, routerContext, routes } = context;
|
|
25
43
|
if (!routeManifest || !routerContext || !routes) {
|
|
26
44
|
return "";
|
|
@@ -42,15 +60,23 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
});
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
const { enableInlineStyles } = pluginConfig;
|
|
64
|
+
const styles = await Promise.all(cssChunks.map(async (chunk) => {
|
|
65
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
66
|
+
if (checkIsNode() && checkIsInline(chunk, enableInlineStyles)) {
|
|
67
|
+
return readAsset(chunk).then((content) => `<style>${content}</style>`).catch((_) => {
|
|
68
|
+
return link;
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
return link;
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
return `${styles.join("")}`;
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
77
|
}
|
|
52
|
-
function buildShellBeforeTemplate(beforeAppTemplate, context) {
|
|
53
|
-
const headTemplate = getHeadTemplate(beforeAppTemplate, context);
|
|
78
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, context, pluginConfig) {
|
|
79
|
+
const headTemplate = await getHeadTemplate(beforeAppTemplate, context, pluginConfig);
|
|
54
80
|
return beforeAppTemplate.replace(HEAD_REG_EXP, headTemplate);
|
|
55
81
|
}
|
|
56
82
|
export {
|
|
@@ -3,7 +3,7 @@ import { run } from "@modern-js/runtime-utils/node";
|
|
|
3
3
|
import { time } from "@modern-js/runtime-utils/time";
|
|
4
4
|
import { SSRErrors, SSRTimings } from "../tracker";
|
|
5
5
|
import renderToPipe from "./renderToPipe";
|
|
6
|
-
const render = ({ App, context }) => {
|
|
6
|
+
const render = ({ App, context, config }) => {
|
|
7
7
|
const { ssrContext } = context;
|
|
8
8
|
if (!ssrContext) {
|
|
9
9
|
throw new Error('The "ssrContext" must not be undefined, but received undefined');
|
|
@@ -16,7 +16,7 @@ const render = ({ App, context }) => {
|
|
|
16
16
|
})
|
|
17
17
|
});
|
|
18
18
|
const { tracker } = ssrContext;
|
|
19
|
-
const pipe = renderToPipe(rootElement, context, {
|
|
19
|
+
const pipe = renderToPipe(rootElement, context, config, {
|
|
20
20
|
onShellReady() {
|
|
21
21
|
const cost = end();
|
|
22
22
|
tracker.trackTiming(SSRTimings.RENDER_SHELL, cost);
|
|
@@ -7,7 +7,7 @@ var ShellChunkStatus;
|
|
|
7
7
|
ShellChunkStatus2[ShellChunkStatus2["START"] = 0] = "START";
|
|
8
8
|
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
9
9
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
10
|
-
function renderToPipe(rootElement, context, options) {
|
|
10
|
+
function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
11
11
|
let shellChunkStatus = 0;
|
|
12
12
|
const { ssrContext } = context;
|
|
13
13
|
const chunkVec = [];
|
|
@@ -22,41 +22,43 @@ function renderToPipe(rootElement, context, options) {
|
|
|
22
22
|
...options,
|
|
23
23
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
24
24
|
onShellReady() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
26
|
+
var _options_onShellReady;
|
|
27
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
28
|
+
const injectableTransform = new Transform({
|
|
29
|
+
transform(chunk, _encoding, callback) {
|
|
30
|
+
try {
|
|
31
|
+
if (shellChunkStatus !== 1) {
|
|
32
|
+
chunkVec.push(chunk.toString());
|
|
33
|
+
let concatedChunk = chunkVec.join("");
|
|
34
|
+
if (concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
35
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
36
|
+
shellChunkStatus = 1;
|
|
37
|
+
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
this.push(chunk);
|
|
41
|
+
}
|
|
42
|
+
callback();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (e instanceof Error) {
|
|
45
|
+
callback(e);
|
|
46
|
+
} else {
|
|
47
|
+
callback(new Error("Received unkown error when streaming"));
|
|
38
48
|
}
|
|
39
|
-
} else {
|
|
40
|
-
this.push(chunk);
|
|
41
|
-
}
|
|
42
|
-
callback();
|
|
43
|
-
} catch (e) {
|
|
44
|
-
if (e instanceof Error) {
|
|
45
|
-
callback(e);
|
|
46
|
-
} else {
|
|
47
|
-
callback(new Error("Received unkown error when streaming"));
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
+
});
|
|
52
|
+
resolve(pipe(injectableTransform).pipe(stream));
|
|
51
53
|
});
|
|
52
|
-
resolve(pipe(injectableTransform).pipe(stream));
|
|
53
54
|
},
|
|
54
55
|
onShellError(error) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
57
|
+
var _options_onShellError;
|
|
58
|
+
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
59
|
+
resolve(fallbackHtml);
|
|
60
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
61
|
+
});
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
64
|
});
|
|
@@ -7,7 +7,7 @@ var ShellChunkStatus;
|
|
|
7
7
|
ShellChunkStatus2[ShellChunkStatus2["START"] = 0] = "START";
|
|
8
8
|
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
9
9
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
10
|
-
function renderToPipe(rootElement, context, options) {
|
|
10
|
+
function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
11
11
|
let shellChunkStatus = 0;
|
|
12
12
|
const chunkVec = [];
|
|
13
13
|
const { ssrContext } = context;
|
|
@@ -17,7 +17,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
17
17
|
({ renderToReadableStream } = require("react-dom/server"));
|
|
18
18
|
} catch (e) {
|
|
19
19
|
}
|
|
20
|
-
const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.SERVER_RENDER);
|
|
20
|
+
const { shellAfter, shellBefore } = await getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig);
|
|
21
21
|
try {
|
|
22
22
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
23
23
|
...options,
|
|
@@ -56,7 +56,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
56
56
|
return injectableStream;
|
|
57
57
|
} catch (err) {
|
|
58
58
|
ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.tracker.trackError(SSRErrors.RENDER_SHELL, err);
|
|
59
|
-
const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = getTemplates(context, RenderLevel.CLIENT_RENDER);
|
|
59
|
+
const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = await getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig);
|
|
60
60
|
const fallbackHtml = `${shellBefore2}${shellAfter2}`;
|
|
61
61
|
return fallbackHtml;
|
|
62
62
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { buildShellAfterTemplate } from "./buildTemplate.after";
|
|
2
2
|
import { buildShellBeforeTemplate } from "./bulidTemplate.before";
|
|
3
3
|
const HTML_SEPARATOR = "<!--<?- html ?>-->";
|
|
4
|
-
const getTemplates = (context, renderLevel) => {
|
|
4
|
+
const getTemplates = async (context, renderLevel, pluginConfig) => {
|
|
5
5
|
const { ssrContext } = context;
|
|
6
6
|
const [beforeAppTemplate = "", afterAppHtmlTemplate = ""] = ssrContext.template.split(HTML_SEPARATOR) || [];
|
|
7
|
-
const builtBeforeTemplate = buildShellBeforeTemplate(beforeAppTemplate, context);
|
|
8
|
-
const builtAfterTemplate = buildShellAfterTemplate(afterAppHtmlTemplate, {
|
|
7
|
+
const builtBeforeTemplate = await buildShellBeforeTemplate(beforeAppTemplate, context, pluginConfig);
|
|
8
|
+
const builtAfterTemplate = await buildShellAfterTemplate(afterAppHtmlTemplate, {
|
|
9
9
|
context,
|
|
10
10
|
renderLevel
|
|
11
11
|
});
|
|
@@ -128,7 +128,6 @@ class Entry {
|
|
|
128
128
|
constructor(options) {
|
|
129
129
|
_define_property(this, "entryName", void 0);
|
|
130
130
|
_define_property(this, "result", void 0);
|
|
131
|
-
_define_property(this, "metrics", void 0);
|
|
132
131
|
_define_property(this, "tracker", void 0);
|
|
133
132
|
_define_property(this, "template", void 0);
|
|
134
133
|
_define_property(this, "App", void 0);
|
|
@@ -144,7 +143,6 @@ class Entry {
|
|
|
144
143
|
this.pluginConfig = config;
|
|
145
144
|
this.routeManifest = ctx.routeManifest;
|
|
146
145
|
this.tracker = ctx.tracker;
|
|
147
|
-
this.metrics = ctx.metrics;
|
|
148
146
|
this.htmlModifiers = ctx.htmlModifiers;
|
|
149
147
|
this.nonce = nonce;
|
|
150
148
|
this.result = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { ChunkExtractor } from "@loadable/server";
|
|
3
|
-
import { attributesToString } from "../utils";
|
|
3
|
+
import { attributesToString, checkIsNode } from "../utils";
|
|
4
4
|
const extname = (uri) => {
|
|
5
5
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
6
6
|
return "";
|
|
@@ -25,10 +25,6 @@ const readAsset = async (chunk) => {
|
|
|
25
25
|
const filepath = path.resolve(__dirname, chunk.filename);
|
|
26
26
|
return fs.readFile(filepath, "utf-8");
|
|
27
27
|
};
|
|
28
|
-
const checkIsNode = () => {
|
|
29
|
-
var _process_release;
|
|
30
|
-
return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
|
|
31
|
-
};
|
|
32
28
|
class LoadableCollector {
|
|
33
29
|
get existsAssets() {
|
|
34
30
|
var _routeManifest_routeAssets_entryName, _routeManifest_routeAssets;
|
|
@@ -76,7 +72,8 @@ class LoadableCollector {
|
|
|
76
72
|
const { scriptLoading = "defer", enableInlineScripts } = config;
|
|
77
73
|
const scriptLoadingAtr = {
|
|
78
74
|
defer: scriptLoading === "defer" ? true : void 0,
|
|
79
|
-
type: scriptLoading === "module" ? "module" : void 0
|
|
75
|
+
type: scriptLoading === "module" ? "module" : void 0,
|
|
76
|
+
async: scriptLoading === "async" ? true : void 0
|
|
80
77
|
};
|
|
81
78
|
const attributes = attributesToString(this.generateAttributes({
|
|
82
79
|
nonce,
|
|
@@ -88,7 +85,7 @@ class LoadableCollector {
|
|
|
88
85
|
return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
|
|
89
86
|
}).map(async (chunk) => {
|
|
90
87
|
const script = `<script${attributes} src="${chunk.url}"></script>`;
|
|
91
|
-
if (checkIsInline(chunk, enableInlineScripts)
|
|
88
|
+
if (checkIsNode() && checkIsInline(chunk, enableInlineScripts)) {
|
|
92
89
|
return readAsset(chunk).then((content) => `<script>${content}</script>`).catch((_) => {
|
|
93
90
|
return script;
|
|
94
91
|
});
|
|
@@ -107,7 +104,7 @@ class LoadableCollector {
|
|
|
107
104
|
return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
|
|
108
105
|
}).map(async (chunk) => {
|
|
109
106
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
110
|
-
if (checkIsInline(chunk, enableInlineStyles)
|
|
107
|
+
if (checkIsNode() && checkIsInline(chunk, enableInlineStyles)) {
|
|
111
108
|
return readAsset(chunk).then((content) => `<style>${content}</style>`).catch((_) => {
|
|
112
109
|
return link;
|
|
113
110
|
});
|
|
@@ -16,69 +16,57 @@ var SSRErrors;
|
|
|
16
16
|
const errors = {
|
|
17
17
|
[0]: {
|
|
18
18
|
reporter: "App Prerender",
|
|
19
|
-
logger: "App Prerender"
|
|
20
|
-
metrics: "app.prerender.error"
|
|
19
|
+
logger: "App Prerender"
|
|
21
20
|
},
|
|
22
21
|
[1]: {
|
|
23
22
|
reporter: "App run useLoader",
|
|
24
|
-
logger: "App run useLoader"
|
|
25
|
-
metrics: "app.useloader.error"
|
|
23
|
+
logger: "App run useLoader"
|
|
26
24
|
},
|
|
27
25
|
[2]: {
|
|
28
26
|
reporter: "App Render To HTML",
|
|
29
|
-
logger: "App Render To HTML"
|
|
30
|
-
metrics: "app.render.html.error"
|
|
27
|
+
logger: "App Render To HTML"
|
|
31
28
|
},
|
|
32
29
|
[3]: {
|
|
33
30
|
reporter: "App Render To Streaming",
|
|
34
|
-
logger: "An error occurs during streaming SSR"
|
|
35
|
-
metrics: "app.render.streaming.error"
|
|
31
|
+
logger: "An error occurs during streaming SSR"
|
|
36
32
|
},
|
|
37
|
-
[4]: {
|
|
38
|
-
metrics: "app.render.streaming.shell.error"
|
|
39
|
-
}
|
|
33
|
+
[4]: {}
|
|
40
34
|
};
|
|
41
35
|
const timings = {
|
|
42
36
|
[0]: {
|
|
43
37
|
reporter: "ssr-prerender",
|
|
44
38
|
serverTiming: "ssr-prerender",
|
|
45
|
-
metrics: "app.prerender.cost",
|
|
46
39
|
logger: "App Prerender cost = %d ms"
|
|
47
40
|
},
|
|
48
41
|
[1]: {
|
|
49
42
|
reporter: "ssr-render-html",
|
|
50
43
|
serverTiming: "ssr-render-html",
|
|
51
|
-
metrics: "app.render.html.cost",
|
|
52
44
|
logger: "App Render To HTML cost = %d ms"
|
|
53
45
|
},
|
|
54
46
|
[2]: {
|
|
55
47
|
reporter: "ssr-render-shell",
|
|
56
|
-
metrics: "app.render.shell.cost",
|
|
57
48
|
logger: "App Render To Shell cost = %d ms"
|
|
58
49
|
},
|
|
59
50
|
[3]: {
|
|
60
51
|
reporter: "use-loader",
|
|
61
52
|
serverTiming: "use-loader",
|
|
62
|
-
metrics: "app.useloader.cost",
|
|
63
53
|
logger: "App run useLoader cost = %d ms"
|
|
64
54
|
}
|
|
65
55
|
};
|
|
66
|
-
function createSSRTracker({ reporter, serverTiming,
|
|
56
|
+
function createSSRTracker({ reporter, serverTiming, logger }) {
|
|
67
57
|
const tracker = {
|
|
68
58
|
get sessionId() {
|
|
69
59
|
return reporter.sessionId;
|
|
70
60
|
},
|
|
71
61
|
trackError(key, e) {
|
|
72
|
-
const { reporter: reporterContent,
|
|
62
|
+
const { reporter: reporterContent, logger: loggerContent } = errors[key];
|
|
73
63
|
reporterContent && reporter.reportError(`SSR Error - ${reporterContent}`, e);
|
|
74
|
-
metricsContent && metrics.emitCounter(metricsContent, 1);
|
|
75
64
|
loggerContent && logger.error(loggerContent, e);
|
|
76
65
|
},
|
|
77
66
|
trackTiming(key, cost) {
|
|
78
|
-
const { reporter: reporterName, serverTiming: serverTimingName, logger: loggerName
|
|
67
|
+
const { reporter: reporterName, serverTiming: serverTimingName, logger: loggerName } = timings[key];
|
|
79
68
|
reporterName && reporter.reportTiming(reporterName, cost);
|
|
80
69
|
serverTimingName && serverTiming.addServeTiming(serverTimingName, cost);
|
|
81
|
-
metricsName && metrics.emitTimer(metricsName, cost);
|
|
82
70
|
loggerName && logger.debug(loggerName, cost);
|
|
83
71
|
}
|
|
84
72
|
};
|
|
@@ -6,7 +6,12 @@ function attributesToString(attributes) {
|
|
|
6
6
|
function safeReplace(source, searchValue, replaceValue) {
|
|
7
7
|
return source.replace(searchValue, () => replaceValue);
|
|
8
8
|
}
|
|
9
|
+
function checkIsNode() {
|
|
10
|
+
var _process_release;
|
|
11
|
+
return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
|
|
12
|
+
}
|
|
9
13
|
export {
|
|
10
14
|
attributesToString,
|
|
15
|
+
checkIsNode,
|
|
11
16
|
safeReplace
|
|
12
17
|
};
|
|
@@ -3,5 +3,5 @@ type BuildShellAfterTemplateOptions = {
|
|
|
3
3
|
context: RuntimeContext;
|
|
4
4
|
renderLevel: RenderLevel;
|
|
5
5
|
};
|
|
6
|
-
export declare function buildShellAfterTemplate(afterAppTemplate: string, options: BuildShellAfterTemplateOptions): string
|
|
6
|
+
export declare function buildShellAfterTemplate(afterAppTemplate: string, options: BuildShellAfterTemplateOptions): Promise<string>;
|
|
7
7
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const HEAD_REG_EXP: RegExp;
|
|
2
|
-
export type BuildTemplateCb = (headTemplate: string) => string
|
|
3
|
-
export declare function buildTemplate(template: string, callbacks: BuildTemplateCb[]): string
|
|
2
|
+
export type BuildTemplateCb = (headTemplate: string) => string | Promise<string>;
|
|
3
|
+
export declare function buildTemplate(template: string, callbacks: BuildTemplateCb[]): Promise<string>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RuntimeContext } from '../types';
|
|
2
|
-
export declare function buildShellBeforeTemplate(beforeAppTemplate: string, context: RuntimeContext): string
|
|
1
|
+
import { RuntimeContext, SSRPluginConfig } from '../types';
|
|
2
|
+
export declare function buildShellBeforeTemplate(beforeAppTemplate: string, context: RuntimeContext, pluginConfig: SSRPluginConfig): Promise<string>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ServerRenderOptions } from '../types';
|
|
3
|
-
export declare const render: ({ App, context }: ServerRenderOptions) => Promise<import("./renderToPipe").Pipe<import("stream").Writable>>;
|
|
3
|
+
export declare const render: ({ App, context, config }: ServerRenderOptions) => Promise<import("./renderToPipe").Pipe<import("stream").Writable>>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="react" />
|
|
3
3
|
import { Writable } from 'stream';
|
|
4
4
|
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
|
|
5
|
-
import { RuntimeContext } from '../types';
|
|
5
|
+
import { RuntimeContext, SSRPluginConfig } from '../types';
|
|
6
6
|
export type Pipe<T extends Writable> = (output: T) => Promise<T | string>;
|
|
7
|
-
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, options?: RenderToPipeableStreamOptions): Pipe<Writable>;
|
|
7
|
+
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, pluginConfig: SSRPluginConfig, options?: RenderToPipeableStreamOptions): Pipe<Writable>;
|
|
8
8
|
export default renderToPipe;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="react" />
|
|
3
3
|
import type { Writable } from 'stream';
|
|
4
4
|
import type { RenderToReadableStreamOptions } from 'react-dom/server';
|
|
5
|
-
import { RuntimeContext } from '../types';
|
|
5
|
+
import { RuntimeContext, SSRPluginConfig } from '../types';
|
|
6
6
|
export type Pipe<T extends Writable> = (output: T) => Promise<T | string>;
|
|
7
|
-
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, options?: RenderToReadableStreamOptions): Promise<string | ReadableStream<any>>;
|
|
7
|
+
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, pluginConfig: SSRPluginConfig, options?: RenderToReadableStreamOptions): Promise<string | ReadableStream<any>>;
|
|
8
8
|
export default renderToPipe;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RenderLevel, RuntimeContext } from '../types';
|
|
1
|
+
import { RenderLevel, RuntimeContext, SSRPluginConfig } from '../types';
|
|
2
2
|
export type InjectTemplate = {
|
|
3
3
|
shellBefore: string;
|
|
4
4
|
shellAfter: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const getTemplates: (context: RuntimeContext, renderLevel: RenderLevel) => InjectTemplate
|
|
6
|
+
export declare const getTemplates: (context: RuntimeContext, renderLevel: RenderLevel, pluginConfig: SSRPluginConfig) => Promise<InjectTemplate>;
|
|
@@ -13,7 +13,7 @@ export declare enum SSRErrors {
|
|
|
13
13
|
RENDER_STREAM = 3,
|
|
14
14
|
RENDER_SHELL = 4
|
|
15
15
|
}
|
|
16
|
-
export declare function createSSRTracker({ reporter, serverTiming,
|
|
16
|
+
export declare function createSSRTracker({ reporter, serverTiming, logger, }: BaseSSRServerContext): {
|
|
17
17
|
readonly sessionId: string | undefined;
|
|
18
18
|
trackError(key: SSRErrors, e: Error): void;
|
|
19
19
|
trackTiming(key: SSRTimings, cost: number): void;
|
|
@@ -30,7 +30,7 @@ export type ModernSSRReactComponent = React.ComponentType<any>;
|
|
|
30
30
|
export { RuntimeContext };
|
|
31
31
|
export type SSRPluginConfig = {
|
|
32
32
|
crossorigin?: boolean | 'anonymous' | 'use-credentials';
|
|
33
|
-
scriptLoading?: 'defer' | 'blocking' | 'module';
|
|
33
|
+
scriptLoading?: 'defer' | 'blocking' | 'module' | 'async';
|
|
34
34
|
enableInlineStyles?: boolean | RegExp;
|
|
35
35
|
enableInlineScripts?: boolean | RegExp;
|
|
36
36
|
disablePrerender?: boolean;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.45.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -171,10 +171,10 @@
|
|
|
171
171
|
"react-side-effect": "^2.1.1",
|
|
172
172
|
"styled-components": "^5.3.1",
|
|
173
173
|
"@swc/helpers": "0.5.3",
|
|
174
|
-
"@modern-js/plugin": "2.
|
|
175
|
-
"@modern-js/
|
|
176
|
-
"@modern-js/utils": "2.
|
|
177
|
-
"@modern-js/
|
|
174
|
+
"@modern-js/plugin": "2.45.0",
|
|
175
|
+
"@modern-js/types": "2.45.0",
|
|
176
|
+
"@modern-js/utils": "2.45.0",
|
|
177
|
+
"@modern-js/runtime-utils": "2.45.0"
|
|
178
178
|
},
|
|
179
179
|
"peerDependencies": {
|
|
180
180
|
"react": ">=17",
|
|
@@ -195,11 +195,11 @@
|
|
|
195
195
|
"ts-jest": "^29.1.0",
|
|
196
196
|
"typescript": "^5",
|
|
197
197
|
"webpack": "^5.89.0",
|
|
198
|
-
"@modern-js/app-tools": "2.
|
|
199
|
-
"@modern-js/
|
|
200
|
-
"@
|
|
201
|
-
"@
|
|
202
|
-
"@scripts/
|
|
198
|
+
"@modern-js/app-tools": "2.45.0",
|
|
199
|
+
"@modern-js/core": "2.45.0",
|
|
200
|
+
"@modern-js/server-core": "2.45.0",
|
|
201
|
+
"@scripts/build": "2.45.0",
|
|
202
|
+
"@scripts/jest-config": "2.45.0"
|
|
203
203
|
},
|
|
204
204
|
"sideEffects": false,
|
|
205
205
|
"publishConfig": {
|