@modern-js/runtime 2.34.0 → 2.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/compatible.js +9 -10
- package/dist/cjs/core/loader/useLoader.js +8 -8
- package/dist/cjs/core/plugin.js +2 -3
- package/dist/cjs/document/Html.js +3 -4
- package/dist/cjs/document/cli/index.js +4 -6
- package/dist/cjs/router/cli/index.js +1 -2
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +9 -11
- package/dist/cjs/router/runtime/PrefetchLink.js +5 -9
- package/dist/cjs/router/runtime/index.js +5 -1
- package/dist/cjs/router/runtime/plugin.js +5 -7
- package/dist/cjs/router/runtime/plugin.node.js +8 -9
- package/dist/cjs/router/runtime/server.js +1 -1
- package/dist/cjs/router/runtime/utils.js +7 -7
- package/dist/cjs/router/runtime/withRouter.js +1 -1
- package/dist/cjs/ssr/cli/index.js +9 -11
- package/dist/cjs/ssr/index.js +3 -3
- package/dist/cjs/ssr/index.node.js +3 -2
- package/dist/cjs/ssr/prefetch.js +4 -4
- package/dist/cjs/ssr/react/prerender/util.js +2 -4
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +6 -3
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -7
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +14 -5
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +5 -13
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +5 -8
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +5 -5
- package/dist/cjs/ssr/serverRender/renderToString/index.js +3 -3
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +29 -18
- package/dist/cjs/ssr/serverRender/tracker.js +14 -0
- package/dist/esm/core/compatible.js +9 -10
- package/dist/esm/core/loader/useLoader.js +8 -8
- package/dist/esm/core/plugin.js +2 -3
- package/dist/esm/document/Html.js +3 -4
- package/dist/esm/document/cli/index.js +4 -5
- package/dist/esm/router/cli/index.js +1 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +4 -6
- package/dist/esm/router/runtime/PrefetchLink.js +5 -9
- package/dist/esm/router/runtime/index.js +3 -2
- package/dist/esm/router/runtime/plugin.js +4 -6
- package/dist/esm/router/runtime/plugin.node.js +6 -7
- package/dist/esm/router/runtime/server.js +1 -1
- package/dist/esm/router/runtime/utils.js +6 -6
- package/dist/esm/router/runtime/withRouter.js +1 -1
- package/dist/esm/ssr/cli/index.js +9 -11
- package/dist/esm/ssr/index.js +1 -1
- package/dist/esm/ssr/index.node.js +3 -2
- package/dist/esm/ssr/prefetch.js +3 -3
- package/dist/esm/ssr/react/prerender/util.js +2 -4
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -2
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -5
- package/dist/esm/ssr/serverRender/renderToStream/index.js +14 -5
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +5 -13
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +6 -7
- package/dist/esm/ssr/serverRender/renderToString/entry.js +4 -4
- package/dist/esm/ssr/serverRender/renderToString/index.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +32 -18
- package/dist/esm/ssr/serverRender/tracker.js +11 -0
- package/dist/esm-node/core/compatible.js +9 -10
- package/dist/esm-node/core/loader/useLoader.js +8 -8
- package/dist/esm-node/core/plugin.js +2 -3
- package/dist/esm-node/document/Html.js +3 -4
- package/dist/esm-node/document/cli/index.js +4 -6
- package/dist/esm-node/router/cli/index.js +1 -2
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +4 -6
- package/dist/esm-node/router/runtime/PrefetchLink.js +5 -9
- package/dist/esm-node/router/runtime/index.js +3 -2
- package/dist/esm-node/router/runtime/plugin.js +4 -6
- package/dist/esm-node/router/runtime/plugin.node.js +6 -7
- package/dist/esm-node/router/runtime/server.js +1 -1
- package/dist/esm-node/router/runtime/utils.js +6 -6
- package/dist/esm-node/router/runtime/withRouter.js +1 -1
- package/dist/esm-node/ssr/cli/index.js +9 -11
- package/dist/esm-node/ssr/index.js +1 -1
- package/dist/esm-node/ssr/index.node.js +3 -2
- package/dist/esm-node/ssr/prefetch.js +3 -3
- package/dist/esm-node/ssr/react/prerender/util.js +2 -4
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/index.js +13 -4
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +5 -13
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +5 -8
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +4 -4
- package/dist/esm-node/ssr/serverRender/renderToString/index.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +29 -18
- package/dist/esm-node/ssr/serverRender/tracker.js +14 -0
- package/dist/types/router/runtime/PrefetchLink.d.ts +1 -1
- package/dist/types/router/runtime/hooks.d.ts +1 -1
- package/dist/types/router/runtime/index.d.ts +4 -3
- package/dist/types/router/runtime/server.d.ts +1 -1
- package/dist/types/router/runtime/types.d.ts +2 -2
- package/dist/types/router/runtime/utils.d.ts +1 -1
- package/dist/types/router/runtime/withRouter.d.ts +1 -1
- package/dist/types/runtimeContext.d.ts +1 -1
- package/dist/types/ssr/serverRender/renderToString/entry.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToString/loadable.d.ts +1 -0
- package/dist/types/ssr/serverRender/renderToString/type.d.ts +0 -10
- package/dist/types/ssr/serverRender/tracker.d.ts +5 -2
- package/dist/types/ssr/serverRender/types.d.ts +12 -1
- package/package.json +10 -9
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
3
|
-
import { run } from "@modern-js/utils/
|
|
3
|
+
import { run } from "@modern-js/runtime-utils/node";
|
|
4
4
|
import { ChunkExtractor } from "@loadable/server";
|
|
5
5
|
const prefetch = async (App, context, config) => run(context.ssrContext.request.headers, async () => {
|
|
6
|
-
var _context_store
|
|
6
|
+
var _context_store;
|
|
7
7
|
const { ssrContext } = context;
|
|
8
8
|
const { loadableStats } = ssrContext;
|
|
9
9
|
if (!config.disablePrerender) {
|
|
@@ -43,7 +43,7 @@ const prefetch = async (App, context, config) => run(context.ssrContext.request.
|
|
|
43
43
|
initialData: context.initialData,
|
|
44
44
|
i18nData: context.__i18nData__,
|
|
45
45
|
// todo: move to plugin state
|
|
46
|
-
storeState:
|
|
46
|
+
storeState: context === null || context === void 0 ? void 0 : (_context_store = context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
|
|
47
47
|
};
|
|
48
48
|
});
|
|
49
49
|
export default prefetch;
|
|
@@ -27,9 +27,8 @@ export const aggKeysFromPropsList = function aggKeysFromPropsList2(propsList, pr
|
|
|
27
27
|
}, {});
|
|
28
28
|
const res = propsList.filter((props) => usefulObject(props[propName])).reduce((result, next) => {
|
|
29
29
|
REQUEST_META.forEach((key) => {
|
|
30
|
-
var _prop;
|
|
31
30
|
const prop = next[propName];
|
|
32
|
-
if ((
|
|
31
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.hasOwnProperty(key)) && usefulArray(prop[key])) {
|
|
33
32
|
result[key] = unique(result[key].concat(prop[key]));
|
|
34
33
|
}
|
|
35
34
|
});
|
|
@@ -52,9 +51,8 @@ export const aggMatchesFromPropsList = function aggMatchesFromPropsList2(propsLi
|
|
|
52
51
|
}, {});
|
|
53
52
|
const res = propsList.filter((props) => usefulObject(props[propName])).reduce((result, next) => {
|
|
54
53
|
REQUEST_META.forEach((key) => {
|
|
55
|
-
var _prop;
|
|
56
54
|
const prop = next[propName];
|
|
57
|
-
if ((
|
|
55
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.hasOwnProperty(key)) && usefulObject(prop[key])) {
|
|
58
56
|
result[key] = Object.assign(result[key], prop[key]);
|
|
59
57
|
}
|
|
60
58
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { serializeJson } from "@modern-js/utils/
|
|
1
|
+
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
2
2
|
import { attributesToString } from "../utils";
|
|
3
3
|
import { buildTemplate } from "./buildTemplate.share";
|
|
4
4
|
export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
@@ -11,7 +11,7 @@ export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
11
11
|
return template.replace("<!--<?- SSRDataScript ?>-->", ssrDataScript);
|
|
12
12
|
function buildSSRDataScript() {
|
|
13
13
|
const { context: { ssrContext, initialData, __i18nData__ }, renderLevel } = options;
|
|
14
|
-
const { request, enableUnsafeCtx, nonce } = ssrContext;
|
|
14
|
+
const { request, enableUnsafeCtx, nonce, tracker } = ssrContext;
|
|
15
15
|
const unsafeContext = {
|
|
16
16
|
headers: request.headers
|
|
17
17
|
};
|
|
@@ -21,6 +21,9 @@ export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
21
21
|
i18nData: __i18nData__
|
|
22
22
|
},
|
|
23
23
|
context: {
|
|
24
|
+
reporter: {
|
|
25
|
+
sessionId: tracker.sessionId
|
|
26
|
+
},
|
|
24
27
|
request: {
|
|
25
28
|
params: request.params,
|
|
26
29
|
query: request.query,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ReactHelmet from "react-helmet";
|
|
2
|
-
import { matchRoutes } from "@modern-js/utils/
|
|
2
|
+
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
3
3
|
import helmetReplace from "../helmet";
|
|
4
4
|
import { CSS_CHUNKS_PLACEHOLDER } from "../utils";
|
|
5
5
|
import { HEAD_REG_EXP, buildTemplate } from "./buildTemplate.share";
|
|
@@ -20,7 +20,6 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
20
20
|
function injectCss(headTemplate2) {
|
|
21
21
|
return headTemplate2.replace(CSS_CHUNKS_PLACEHOLDER, getCssChunks());
|
|
22
22
|
function getCssChunks() {
|
|
23
|
-
var _matches;
|
|
24
23
|
const { routeManifest, routerContext, routes } = context;
|
|
25
24
|
if (!routeManifest || !routerContext || !routes) {
|
|
26
25
|
return "";
|
|
@@ -28,7 +27,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
28
27
|
const { routeAssets } = routeManifest;
|
|
29
28
|
const cssChunks = [];
|
|
30
29
|
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
31
|
-
|
|
30
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
|
|
32
31
|
if (!index) {
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
@@ -37,10 +36,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
37
36
|
const routeManifest2 = routeAssets[routeId];
|
|
38
37
|
if (routeManifest2) {
|
|
39
38
|
const { referenceCssAssets = [] } = routeManifest2;
|
|
40
|
-
const _cssChunks = referenceCssAssets.filter((asset) =>
|
|
41
|
-
var _asset;
|
|
42
|
-
return ((_asset = asset) === null || _asset === void 0 ? void 0 : _asset.endsWith(".css")) && !headTemplate2.includes(asset);
|
|
43
|
-
});
|
|
39
|
+
const _cssChunks = referenceCssAssets.filter((asset) => (asset === null || asset === void 0 ? void 0 : asset.endsWith(".css")) && !headTemplate2.includes(asset));
|
|
44
40
|
cssChunks.push(..._cssChunks);
|
|
45
41
|
}
|
|
46
42
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createElement } from "react";
|
|
2
|
-
import { run } from "@modern-js/utils/
|
|
3
|
-
import { time } from "@modern-js/utils/
|
|
2
|
+
import { run } from "@modern-js/runtime-utils/node";
|
|
3
|
+
import { time } from "@modern-js/runtime-utils/time";
|
|
4
4
|
import { PreRender } from "../../react/prerender";
|
|
5
|
+
import { SSRErrors, SSRTimings } from "../tracker";
|
|
5
6
|
import renderToPipe from "./renderToPipe";
|
|
6
7
|
export const render = ({ App, context }) => {
|
|
7
8
|
const { ssrContext } = context;
|
|
@@ -15,17 +16,25 @@ export const render = ({ App, context }) => {
|
|
|
15
16
|
ssr: true
|
|
16
17
|
})
|
|
17
18
|
});
|
|
19
|
+
const { tracker } = ssrContext;
|
|
18
20
|
const pipe = renderToPipe(rootElement, context, {
|
|
19
21
|
onShellReady() {
|
|
20
22
|
const cacheConfig = PreRender.config();
|
|
21
23
|
if (cacheConfig) {
|
|
22
24
|
ssrContext.cacheConfig = cacheConfig;
|
|
23
25
|
}
|
|
26
|
+
const cost = end();
|
|
27
|
+
tracker.trackTiming(SSRTimings.SSR_RENDER_SHELL, cost);
|
|
24
28
|
},
|
|
25
29
|
onAllReady() {
|
|
26
30
|
const cost = end();
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
tracker.trackTiming(SSRTimings.SSR_RENDER_TOTAL, cost);
|
|
32
|
+
},
|
|
33
|
+
onShellError(e) {
|
|
34
|
+
tracker.trackError(SSRErrors.RENDER_SHELL, e);
|
|
35
|
+
},
|
|
36
|
+
onError(error) {
|
|
37
|
+
tracker.trackError(SSRErrors.RENDER_STREAM, error);
|
|
29
38
|
}
|
|
30
39
|
});
|
|
31
40
|
return pipe;
|
|
@@ -13,7 +13,6 @@ function renderToPipe(rootElement, context, options) {
|
|
|
13
13
|
const chunkVec = [];
|
|
14
14
|
const forUserPipe = (stream) => {
|
|
15
15
|
return new Promise((resolve) => {
|
|
16
|
-
var _ssrContext;
|
|
17
16
|
let renderToPipeableStream;
|
|
18
17
|
try {
|
|
19
18
|
({ renderToPipeableStream } = require("react-dom/server"));
|
|
@@ -21,11 +20,11 @@ function renderToPipe(rootElement, context, options) {
|
|
|
21
20
|
}
|
|
22
21
|
const { pipe } = renderToPipeableStream(rootElement, {
|
|
23
22
|
...options,
|
|
24
|
-
nonce:
|
|
23
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
25
24
|
onShellReady() {
|
|
26
|
-
var _options_onShellReady
|
|
25
|
+
var _options_onShellReady;
|
|
27
26
|
const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.SERVER_RENDER);
|
|
28
|
-
|
|
27
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
29
28
|
const injectableTransform = new Transform({
|
|
30
29
|
transform(chunk, _encoding, callback) {
|
|
31
30
|
try {
|
|
@@ -53,18 +52,11 @@ function renderToPipe(rootElement, context, options) {
|
|
|
53
52
|
resolve(pipe(injectableTransform).pipe(stream));
|
|
54
53
|
},
|
|
55
54
|
onShellError(error) {
|
|
56
|
-
var _options_onShellError
|
|
57
|
-
ssrContext.metrics.emitCounter("app.render.streaming.shell.error", 1);
|
|
55
|
+
var _options_onShellError;
|
|
58
56
|
const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.CLIENT_RENDER);
|
|
59
57
|
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
60
58
|
resolve(fallbackHtml);
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
onError(error) {
|
|
64
|
-
var _options_onError, _options;
|
|
65
|
-
ssrContext.logger.error("An error occurs during streaming SSR", error);
|
|
66
|
-
ssrContext.metrics.emitCounter("app.render.streaming.error", 1);
|
|
67
|
-
(_options = options) === null || _options === void 0 ? void 0 : (_options_onError = _options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(_options, error);
|
|
59
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
68
60
|
}
|
|
69
61
|
});
|
|
70
62
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RenderLevel } from "../types";
|
|
2
2
|
import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
3
|
+
import { SSRErrors } from "../tracker";
|
|
3
4
|
import { getTemplates } from "./template";
|
|
4
5
|
var ShellChunkStatus;
|
|
5
6
|
(function(ShellChunkStatus2) {
|
|
@@ -18,15 +19,12 @@ function renderToPipe(rootElement, context, options) {
|
|
|
18
19
|
}
|
|
19
20
|
const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.SERVER_RENDER);
|
|
20
21
|
try {
|
|
21
|
-
var _ssrContext;
|
|
22
22
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
23
23
|
...options,
|
|
24
|
-
nonce:
|
|
24
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
25
25
|
onError(error) {
|
|
26
|
-
var
|
|
27
|
-
(
|
|
28
|
-
(_ssrContext12 = ssrContext) === null || _ssrContext12 === void 0 ? void 0 : _ssrContext12.metrics.emitCounter("app.render.streaming.error", 1);
|
|
29
|
-
(_options = options) === null || _options === void 0 ? void 0 : (_options_onError = _options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(_options, error);
|
|
26
|
+
var _options_onError;
|
|
27
|
+
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
30
28
|
}
|
|
31
29
|
});
|
|
32
30
|
const reader = readableOriginal.getReader();
|
|
@@ -57,8 +55,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
57
55
|
});
|
|
58
56
|
return injectableStream;
|
|
59
57
|
} catch (err) {
|
|
60
|
-
|
|
61
|
-
(_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.metrics.emitCounter("app.render.streaming.shell.error", 1);
|
|
58
|
+
ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.tracker.trackError(SSRErrors.RENDER_SHELL, err);
|
|
62
59
|
const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = getTemplates(context, RenderLevel.CLIENT_RENDER);
|
|
63
60
|
const fallbackHtml = `${shellBefore2}${shellAfter2}`;
|
|
64
61
|
return fallbackHtml;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { serializeJson } from "@modern-js/utils/
|
|
3
|
+
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
4
4
|
import ReactHelmet from "react-helmet";
|
|
5
|
-
import { time } from "@modern-js/utils/
|
|
5
|
+
import { time } from "@modern-js/runtime-utils/time";
|
|
6
6
|
import { serializeErrors } from "../../../router/runtime/utils";
|
|
7
7
|
import helmetReplace from "../helmet";
|
|
8
8
|
import { RenderLevel } from "../types";
|
|
9
9
|
import prefetch from "../../prefetch";
|
|
10
10
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID, attributesToString } from "../utils";
|
|
11
|
-
import { SSRErrors, SSRTimings
|
|
11
|
+
import { SSRErrors, SSRTimings } from "../tracker";
|
|
12
12
|
import { createLoadableCollector } from "./loadable";
|
|
13
13
|
import { createRender } from "./render";
|
|
14
14
|
import { createStyledCollector } from "./styledComponent";
|
|
@@ -141,7 +141,7 @@ class Entry {
|
|
|
141
141
|
this.entryName = entryName;
|
|
142
142
|
this.App = options.App;
|
|
143
143
|
this.pluginConfig = config;
|
|
144
|
-
this.tracker =
|
|
144
|
+
this.tracker = ctx.tracker;
|
|
145
145
|
this.metrics = ctx.metrics;
|
|
146
146
|
this.htmlModifiers = ctx.htmlModifiers;
|
|
147
147
|
this.nonce = nonce;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { run } from "@modern-js/utils/
|
|
2
|
-
import { time } from "@modern-js/utils/
|
|
1
|
+
import { run } from "@modern-js/runtime-utils/node";
|
|
2
|
+
import { time } from "@modern-js/runtime-utils/time";
|
|
3
3
|
import { PreRender } from "../../react/prerender";
|
|
4
4
|
import { SSRTimings } from "../tracker";
|
|
5
5
|
import SSREntry from "./entry";
|
|
@@ -2,11 +2,10 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
|
2
2
|
import { ChunkExtractor } from "@loadable/server";
|
|
3
3
|
import { attributesToString, getLoadableScripts } from "../utils";
|
|
4
4
|
const extname = (uri) => {
|
|
5
|
-
var _uri;
|
|
6
5
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
7
6
|
return "";
|
|
8
7
|
}
|
|
9
|
-
return `.${
|
|
8
|
+
return `.${uri === null || uri === void 0 ? void 0 : uri.split(".").pop()}` || "";
|
|
10
9
|
};
|
|
11
10
|
class LoadableCollector {
|
|
12
11
|
collect(comopnent) {
|
|
@@ -30,35 +29,47 @@ class LoadableCollector {
|
|
|
30
29
|
const { extractor } = this;
|
|
31
30
|
const chunks = extractor.getChunkAssets(extractor.chunks);
|
|
32
31
|
chunksMap.js = (chunksMap.js || "") + getLoadableScripts(extractor);
|
|
32
|
+
const attributes = this.generateAttributes();
|
|
33
33
|
for (const v of chunks) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const { crossorigin, scriptLoading = "defer" } = config;
|
|
37
|
-
if (crossorigin) {
|
|
38
|
-
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
39
|
-
}
|
|
40
|
-
switch (scriptLoading) {
|
|
41
|
-
case "defer":
|
|
42
|
-
attributes.defer = true;
|
|
43
|
-
break;
|
|
44
|
-
case "module":
|
|
45
|
-
attributes.type = "module";
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
34
|
+
if (!v.url) {
|
|
35
|
+
continue;
|
|
48
36
|
}
|
|
37
|
+
const fileType = extname(v.url).slice(1);
|
|
49
38
|
if (fileType === "js") {
|
|
50
39
|
const jsChunkReg = new RegExp(`<script .*src="${v.url}".*>`);
|
|
51
40
|
if (!jsChunkReg.test(template)) {
|
|
41
|
+
const { scriptLoading = "defer" } = config;
|
|
42
|
+
switch (scriptLoading) {
|
|
43
|
+
case "defer":
|
|
44
|
+
attributes.defer = true;
|
|
45
|
+
break;
|
|
46
|
+
case "module":
|
|
47
|
+
attributes.type = "module";
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
}
|
|
52
51
|
attributes.nonce = nonce;
|
|
53
52
|
const attrsStr = attributesToString(attributes);
|
|
54
53
|
chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
|
|
55
54
|
}
|
|
56
55
|
} else if (fileType === "css") {
|
|
57
|
-
const
|
|
58
|
-
|
|
56
|
+
const cssChunkReg = new RegExp(`<link .*href="${v.url}".*>`);
|
|
57
|
+
if (!cssChunkReg.test(template)) {
|
|
58
|
+
const attrsStr = attributesToString(attributes);
|
|
59
|
+
chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
64
|
+
generateAttributes() {
|
|
65
|
+
const { config } = this.options;
|
|
66
|
+
const { crossorigin } = config;
|
|
67
|
+
const attributes = {};
|
|
68
|
+
if (crossorigin) {
|
|
69
|
+
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
70
|
+
}
|
|
71
|
+
return attributes;
|
|
72
|
+
}
|
|
62
73
|
constructor(options) {
|
|
63
74
|
_define_property(this, "options", void 0);
|
|
64
75
|
_define_property(this, "extractor", void 0);
|
|
@@ -3,11 +3,14 @@ export var SSRTimings;
|
|
|
3
3
|
SSRTimings2[SSRTimings2["SSR_RENDER_TOTAL"] = 0] = "SSR_RENDER_TOTAL";
|
|
4
4
|
SSRTimings2[SSRTimings2["SSR_PREFETCH"] = 1] = "SSR_PREFETCH";
|
|
5
5
|
SSRTimings2[SSRTimings2["SSR_RENDER_HTML"] = 2] = "SSR_RENDER_HTML";
|
|
6
|
+
SSRTimings2[SSRTimings2["SSR_RENDER_SHELL"] = 3] = "SSR_RENDER_SHELL";
|
|
6
7
|
})(SSRTimings || (SSRTimings = {}));
|
|
7
8
|
export var SSRErrors;
|
|
8
9
|
(function(SSRErrors2) {
|
|
9
10
|
SSRErrors2[SSRErrors2["PREFETCH"] = 0] = "PREFETCH";
|
|
10
11
|
SSRErrors2[SSRErrors2["RENDER_HTML"] = 1] = "RENDER_HTML";
|
|
12
|
+
SSRErrors2[SSRErrors2["RENDER_STREAM"] = 2] = "RENDER_STREAM";
|
|
13
|
+
SSRErrors2[SSRErrors2["RENDER_SHELL"] = 3] = "RENDER_SHELL";
|
|
11
14
|
})(SSRErrors || (SSRErrors = {}));
|
|
12
15
|
const errors = {
|
|
13
16
|
[SSRErrors.PREFETCH]: {
|
|
@@ -19,6 +22,14 @@ const errors = {
|
|
|
19
22
|
reporter: "SSR Error - App Render To HTML",
|
|
20
23
|
logger: "App Render To HTML",
|
|
21
24
|
metrics: "app.render.html.error"
|
|
25
|
+
},
|
|
26
|
+
[SSRErrors.RENDER_STREAM]: {
|
|
27
|
+
reporter: "SSR Error - App Render To Streaming",
|
|
28
|
+
logger: "An error occurs during streaming SSR",
|
|
29
|
+
metrics: "app.render.streaming.error"
|
|
30
|
+
},
|
|
31
|
+
[SSRErrors.RENDER_SHELL]: {
|
|
32
|
+
metrics: "app.render.streaming.shell.error"
|
|
22
33
|
}
|
|
23
34
|
};
|
|
24
35
|
const timings = {
|
|
@@ -39,6 +50,9 @@ const timings = {
|
|
|
39
50
|
serverTiming: "ssr-render-total",
|
|
40
51
|
metrics: "app.render.cost",
|
|
41
52
|
logger: "App Render Total cost = %d ms"
|
|
53
|
+
},
|
|
54
|
+
[SSRTimings.SSR_RENDER_SHELL]: {
|
|
55
|
+
reporter: "ssr-render-shell"
|
|
42
56
|
}
|
|
43
57
|
};
|
|
44
58
|
export function createSSRTracker({ reporter, serverTiming, metrics, logger }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '@modern-js/utils/
|
|
2
|
+
import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '@modern-js/runtime-utils/router';
|
|
3
3
|
export declare function composeEventHandlers<EventType extends React.SyntheticEvent | Event>(theirHandler: ((event: EventType) => any) | undefined, ourHandler: (event: EventType) => any): (event: EventType) => any;
|
|
4
4
|
/**
|
|
5
5
|
* Modified from https://github.com/remix-run/remix/blob/9a0601bd704d2f3ee622e0ddacab9b611eb0c5bc/packages/remix-react/components.tsx#L218
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useRouteLoaderData as useRouteData } from '@modern-js/utils/
|
|
1
|
+
import { useRouteLoaderData as useRouteData } from '@modern-js/runtime-utils/router';
|
|
2
2
|
import { routerPlugin } from './plugin';
|
|
3
3
|
import type { SingleRouteConfig, RouterConfig } from './types';
|
|
4
4
|
export type { SingleRouteConfig, RouterConfig };
|
|
5
|
+
export { renderRoutes } from './utils';
|
|
5
6
|
export default routerPlugin;
|
|
6
7
|
export { modifyRoutes } from './plugin';
|
|
7
8
|
export * from './withRouter';
|
|
@@ -9,5 +10,5 @@ export { Link, NavLink } from './PrefetchLink';
|
|
|
9
10
|
export type { LinkProps, NavLinkProps } from './PrefetchLink';
|
|
10
11
|
export declare const useRouteLoaderData: typeof useRouteData;
|
|
11
12
|
export type { LoaderFunction, LoaderFunctionArgs } from './types';
|
|
12
|
-
export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, FetcherWithComponents, BrowserRouterProps, HashRouterProps, HistoryRouterProps, FormProps, ScrollRestorationProps, SubmitFunction, ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To } from '@modern-js/utils/
|
|
13
|
-
export { createBrowserRouter, createHashRouter, createMemoryRouter, RouterProvider, BrowserRouter, HashRouter, MemoryRouter, Router, Await, Form, Navigate, Outlet, Route, Routes, ScrollRestoration, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRoutes, useSearchParams, useSubmit, createRoutesFromChildren, createRoutesFromElements, createSearchParams, generatePath, isRouteErrorResponse, matchPath, matchRoutes, renderMatches, resolvePath, createPath, unstable_useBlocker, unstable_usePrompt, defer, json, redirect } from '@modern-js/utils/
|
|
13
|
+
export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, FetcherWithComponents, BrowserRouterProps, HashRouterProps, HistoryRouterProps, FormProps, ScrollRestorationProps, SubmitFunction, ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To } from '@modern-js/runtime-utils/router';
|
|
14
|
+
export { createBrowserRouter, createHashRouter, createMemoryRouter, RouterProvider, BrowserRouter, HashRouter, MemoryRouter, Router, Await, Form, Navigate, Outlet, Route, Routes, ScrollRestoration, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRoutes, useSearchParams, useSubmit, createRoutesFromChildren, createRoutesFromElements, createSearchParams, generatePath, isRouteErrorResponse, matchPath, matchRoutes, renderMatches, resolvePath, createPath, unstable_useBlocker, unstable_usePrompt, defer, json, redirect } from '@modern-js/runtime-utils/router';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '@modern-js/utils/
|
|
1
|
+
export * from '@modern-js/runtime-utils/node/router';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { RouteProps, RouteObject, Params } from '@modern-js/utils/
|
|
2
|
+
import type { RouteProps, RouteObject, Params } from '@modern-js/runtime-utils/router';
|
|
3
3
|
import { PageRoute, NestedRoute } from '@modern-js/types';
|
|
4
|
-
import type { RequestContext } from '@modern-js/utils/
|
|
4
|
+
import type { RequestContext } from '@modern-js/runtime-utils/node';
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
_SERVER_DATA?: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Reporter, NestedRoute, PageRoute, SSRMode } from '@modern-js/types';
|
|
3
|
-
import { type StaticHandlerContext, type Router } from '@modern-js/utils/
|
|
3
|
+
import { type StaticHandlerContext, type Router } from '@modern-js/runtime-utils/remix-router';
|
|
4
4
|
import { RouterConfig } from './types';
|
|
5
5
|
export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[], {
|
|
6
6
|
globalApp,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useLocation, useNavigate } from '@modern-js/utils/
|
|
2
|
+
import { useLocation, useNavigate } from '@modern-js/runtime-utils/router';
|
|
3
3
|
export interface WithRouterProps {
|
|
4
4
|
location: ReturnType<typeof useLocation>;
|
|
5
5
|
params: Record<string, string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Store } from '@modern-js-reduck/store';
|
|
3
|
-
import { type StaticHandlerContext, type Router, type RouterState } from '@modern-js/utils/
|
|
3
|
+
import { type StaticHandlerContext, type Router, type RouterState } from '@modern-js/runtime-utils/remix-router';
|
|
4
4
|
import { createLoaderManager } from './core/loader/loaderManager';
|
|
5
5
|
import { runtime } from './core/plugin';
|
|
6
6
|
import { RouteManifest } from './router/runtime/types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RuntimeContext, ModernSSRReactComponent, SSRPluginConfig } from '../types';
|
|
1
|
+
import { RuntimeContext, ModernSSRReactComponent, SSRPluginConfig, SSRServerContext } from '../types';
|
|
2
2
|
import { SSRTracker } from '../tracker';
|
|
3
|
-
import {
|
|
3
|
+
import { RenderResult } from './type';
|
|
4
4
|
type EntryOptions = {
|
|
5
5
|
ctx: SSRServerContext;
|
|
6
6
|
App: ModernSSRReactComponent;
|
|
@@ -8,6 +8,7 @@ declare class LoadableCollector implements Collector {
|
|
|
8
8
|
constructor(options: LoadableCollectorOptions);
|
|
9
9
|
collect(comopnent: ReactElement): ReactElement;
|
|
10
10
|
effect(): void;
|
|
11
|
+
private generateAttributes;
|
|
11
12
|
}
|
|
12
13
|
export interface LoadableCollectorOptions {
|
|
13
14
|
nonce?: string;
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import type { BaseSSRServerContext } from '@modern-js/types';
|
|
2
|
-
import type { BuildHtmlCb } from './buildHtml';
|
|
3
1
|
export declare enum RenderLevel {
|
|
4
2
|
CLIENT_RENDER = 0,
|
|
5
3
|
SERVER_PREFETCH = 1,
|
|
6
4
|
SERVER_RENDER = 2,
|
|
7
5
|
}
|
|
8
|
-
export type SSRServerContext = BaseSSRServerContext & {
|
|
9
|
-
request: BaseSSRServerContext['request'] & {
|
|
10
|
-
userAgent: string;
|
|
11
|
-
cookie: string;
|
|
12
|
-
cookieMap: Record<string, string>;
|
|
13
|
-
};
|
|
14
|
-
htmlModifiers: BuildHtmlCb[];
|
|
15
|
-
};
|
|
16
6
|
export type RenderResult = {
|
|
17
7
|
renderLevel: RenderLevel;
|
|
18
8
|
html?: string;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BaseSSRServerContext } from '@modern-js/types';
|
|
2
2
|
export type SSRTracker = ReturnType<typeof createSSRTracker>;
|
|
3
3
|
export declare enum SSRTimings {
|
|
4
4
|
SSR_RENDER_TOTAL = 0,
|
|
5
5
|
SSR_PREFETCH = 1,
|
|
6
6
|
SSR_RENDER_HTML = 2,
|
|
7
|
+
SSR_RENDER_SHELL = 3,
|
|
7
8
|
}
|
|
8
9
|
export declare enum SSRErrors {
|
|
9
10
|
PREFETCH = 0,
|
|
10
11
|
RENDER_HTML = 1,
|
|
12
|
+
RENDER_STREAM = 2,
|
|
13
|
+
RENDER_SHELL = 3,
|
|
11
14
|
}
|
|
12
15
|
export declare function createSSRTracker({
|
|
13
16
|
reporter,
|
|
14
17
|
serverTiming,
|
|
15
18
|
metrics,
|
|
16
19
|
logger
|
|
17
|
-
}:
|
|
20
|
+
}: BaseSSRServerContext): {
|
|
18
21
|
readonly sessionId: string | undefined;
|
|
19
22
|
trackError(key: SSRErrors, e: Error): void;
|
|
20
23
|
trackTiming(key: SSRTimings, cost: number): void;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ServerUserConfig } from '@modern-js/app-tools';
|
|
3
|
+
import type { BaseSSRServerContext } from '@modern-js/types';
|
|
3
4
|
import type { RuntimeContext } from '../../core';
|
|
4
5
|
import { RenderLevel } from './renderToString/type';
|
|
5
|
-
|
|
6
|
+
import type { BuildHtmlCb } from './renderToString/buildHtml';
|
|
7
|
+
import type { SSRTracker } from './tracker';
|
|
8
|
+
export type SSRServerContext = BaseSSRServerContext & {
|
|
9
|
+
request: BaseSSRServerContext['request'] & {
|
|
10
|
+
userAgent: string;
|
|
11
|
+
cookie: string;
|
|
12
|
+
cookieMap: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
htmlModifiers: BuildHtmlCb[];
|
|
15
|
+
tracker: SSRTracker;
|
|
16
|
+
};
|
|
6
17
|
export type ModernSSRReactComponent = React.ComponentType<any>;
|
|
7
18
|
export { RuntimeContext, RenderLevel };
|
|
8
19
|
export type SSRPluginConfig = {
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.35.1",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -173,9 +173,10 @@
|
|
|
173
173
|
"redux-logger": "^3.0.6",
|
|
174
174
|
"styled-components": "^5.3.1",
|
|
175
175
|
"@swc/helpers": "0.5.1",
|
|
176
|
-
"@modern-js/plugin": "2.
|
|
177
|
-
"@modern-js/types": "2.
|
|
178
|
-
"@modern-js/utils": "2.
|
|
176
|
+
"@modern-js/plugin": "2.35.1",
|
|
177
|
+
"@modern-js/types": "2.35.1",
|
|
178
|
+
"@modern-js/utils": "2.35.1",
|
|
179
|
+
"@modern-js/runtime-utils": "2.35.1"
|
|
179
180
|
},
|
|
180
181
|
"peerDependencies": {
|
|
181
182
|
"react": ">=17",
|
|
@@ -196,11 +197,11 @@
|
|
|
196
197
|
"ts-jest": "^29.1.0",
|
|
197
198
|
"typescript": "^5",
|
|
198
199
|
"webpack": "^5.88.1",
|
|
199
|
-
"@modern-js/app-tools": "2.
|
|
200
|
-
"@modern-js/core": "2.
|
|
201
|
-
"@modern-js/server-core": "2.
|
|
202
|
-
"@scripts/build": "2.
|
|
203
|
-
"@scripts/jest-config": "2.
|
|
200
|
+
"@modern-js/app-tools": "2.35.1",
|
|
201
|
+
"@modern-js/core": "2.35.1",
|
|
202
|
+
"@modern-js/server-core": "2.35.1",
|
|
203
|
+
"@scripts/build": "2.35.1",
|
|
204
|
+
"@scripts/jest-config": "2.35.1"
|
|
204
205
|
},
|
|
205
206
|
"sideEffects": false,
|
|
206
207
|
"publishConfig": {
|