@modern-js/runtime 2.35.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 +1 -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 +1 -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 +2 -2
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -7
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +3 -3
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +5 -6
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -6
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +4 -4
- package/dist/cjs/ssr/serverRender/renderToString/index.js +3 -3
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +29 -18
- 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 +2 -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 +1 -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 +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -5
- package/dist/esm/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +5 -6
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +5 -5
- package/dist/esm/ssr/serverRender/renderToString/entry.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/index.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +32 -18
- 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 +2 -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 +1 -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 +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +5 -6
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -6
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToString/index.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +29 -18
- 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 +3 -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/loadable.d.ts +1 -0
- package/package.json +10 -9
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "buildShellAfterTemplate", {
|
|
|
8
8
|
return buildShellAfterTemplate;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _node = require("@modern-js/runtime-utils/node");
|
|
12
12
|
const _utils = require("../utils");
|
|
13
13
|
const _buildTemplateshare = require("./buildTemplate.share");
|
|
14
14
|
function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
@@ -49,7 +49,7 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
49
49
|
nonce
|
|
50
50
|
});
|
|
51
51
|
return `
|
|
52
|
-
<script${attrsStr}>window._SSR_DATA = ${(0,
|
|
52
|
+
<script${attrsStr}>window._SSR_DATA = ${(0, _node.serializeJson)(SSRData)}</script>
|
|
53
53
|
`;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "buildShellBeforeTemplate", {
|
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
12
|
const _reacthelmet = /* @__PURE__ */ _interop_require_default._(require("react-helmet"));
|
|
13
|
-
const _router = require("@modern-js/utils/
|
|
13
|
+
const _router = require("@modern-js/runtime-utils/router");
|
|
14
14
|
const _helmet = /* @__PURE__ */ _interop_require_default._(require("../helmet"));
|
|
15
15
|
const _utils = require("../utils");
|
|
16
16
|
const _buildTemplateshare = require("./buildTemplate.share");
|
|
@@ -31,7 +31,6 @@ 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;
|
|
35
34
|
const { routeManifest, routerContext, routes } = context;
|
|
36
35
|
if (!routeManifest || !routerContext || !routes) {
|
|
37
36
|
return "";
|
|
@@ -39,7 +38,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
39
38
|
const { routeAssets } = routeManifest;
|
|
40
39
|
const cssChunks = [];
|
|
41
40
|
const matches = (0, _router.matchRoutes)(routes, routerContext.location, routerContext.basename);
|
|
42
|
-
|
|
41
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
|
|
43
42
|
if (!index) {
|
|
44
43
|
return;
|
|
45
44
|
}
|
|
@@ -48,10 +47,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
48
47
|
const routeManifest2 = routeAssets[routeId];
|
|
49
48
|
if (routeManifest2) {
|
|
50
49
|
const { referenceCssAssets = [] } = routeManifest2;
|
|
51
|
-
const _cssChunks = referenceCssAssets.filter((asset) =>
|
|
52
|
-
var _asset;
|
|
53
|
-
return ((_asset = asset) === null || _asset === void 0 ? void 0 : _asset.endsWith(".css")) && !headTemplate2.includes(asset);
|
|
54
|
-
});
|
|
50
|
+
const _cssChunks = referenceCssAssets.filter((asset) => (asset === null || asset === void 0 ? void 0 : asset.endsWith(".css")) && !headTemplate2.includes(asset));
|
|
55
51
|
cssChunks.push(..._cssChunks);
|
|
56
52
|
}
|
|
57
53
|
}
|
|
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "render", {
|
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
12
|
const _react = require("react");
|
|
13
|
-
const
|
|
14
|
-
const _time = require("@modern-js/utils/
|
|
13
|
+
const _node = require("@modern-js/runtime-utils/node");
|
|
14
|
+
const _time = require("@modern-js/runtime-utils/time");
|
|
15
15
|
const _prerender = require("../../react/prerender");
|
|
16
16
|
const _tracker = require("../tracker");
|
|
17
17
|
const _renderToPipe = /* @__PURE__ */ _interop_require_default._(require("./renderToPipe"));
|
|
@@ -20,7 +20,7 @@ const render = ({ App, context }) => {
|
|
|
20
20
|
if (!ssrContext) {
|
|
21
21
|
throw new Error('The "ssrContext" must not be undefined, but received undefined');
|
|
22
22
|
}
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, _node.run)(ssrContext.request.headers, async () => {
|
|
24
24
|
const end = (0, _time.time)();
|
|
25
25
|
const rootElement = (0, _react.createElement)(App, {
|
|
26
26
|
context: Object.assign(context || {}, {
|
|
@@ -23,7 +23,6 @@ function renderToPipe(rootElement, context, options) {
|
|
|
23
23
|
const chunkVec = [];
|
|
24
24
|
const forUserPipe = (stream) => {
|
|
25
25
|
return new Promise((resolve) => {
|
|
26
|
-
var _ssrContext;
|
|
27
26
|
let renderToPipeableStream;
|
|
28
27
|
try {
|
|
29
28
|
({ renderToPipeableStream } = require("react-dom/server"));
|
|
@@ -31,11 +30,11 @@ function renderToPipe(rootElement, context, options) {
|
|
|
31
30
|
}
|
|
32
31
|
const { pipe } = renderToPipeableStream(rootElement, {
|
|
33
32
|
...options,
|
|
34
|
-
nonce:
|
|
33
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
35
34
|
onShellReady() {
|
|
36
|
-
var _options_onShellReady
|
|
35
|
+
var _options_onShellReady;
|
|
37
36
|
const { shellAfter, shellBefore } = (0, _template.getTemplates)(context, _types.RenderLevel.SERVER_RENDER);
|
|
38
|
-
|
|
37
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
39
38
|
const injectableTransform = new _stream.Transform({
|
|
40
39
|
transform(chunk, _encoding, callback) {
|
|
41
40
|
try {
|
|
@@ -63,11 +62,11 @@ function renderToPipe(rootElement, context, options) {
|
|
|
63
62
|
resolve(pipe(injectableTransform).pipe(stream));
|
|
64
63
|
},
|
|
65
64
|
onShellError(error) {
|
|
66
|
-
var _options_onShellError
|
|
65
|
+
var _options_onShellError;
|
|
67
66
|
const { shellAfter, shellBefore } = (0, _template.getTemplates)(context, _types.RenderLevel.CLIENT_RENDER);
|
|
68
67
|
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
69
68
|
resolve(fallbackHtml);
|
|
70
|
-
|
|
69
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
71
70
|
}
|
|
72
71
|
});
|
|
73
72
|
});
|
|
@@ -29,13 +29,12 @@ function renderToPipe(rootElement, context, options) {
|
|
|
29
29
|
}
|
|
30
30
|
const { shellAfter, shellBefore } = (0, _template.getTemplates)(context, _types.RenderLevel.SERVER_RENDER);
|
|
31
31
|
try {
|
|
32
|
-
var _ssrContext;
|
|
33
32
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
34
33
|
...options,
|
|
35
|
-
nonce:
|
|
34
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
36
35
|
onError(error) {
|
|
37
|
-
var _options_onError
|
|
38
|
-
|
|
36
|
+
var _options_onError;
|
|
37
|
+
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
39
38
|
}
|
|
40
39
|
});
|
|
41
40
|
const reader = readableOriginal.getReader();
|
|
@@ -66,8 +65,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
66
65
|
});
|
|
67
66
|
return injectableStream;
|
|
68
67
|
} catch (err) {
|
|
69
|
-
|
|
70
|
-
(_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.tracker.trackError(_tracker.SSRErrors.RENDER_SHELL, err);
|
|
68
|
+
ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.tracker.trackError(_tracker.SSRErrors.RENDER_SHELL, err);
|
|
71
69
|
const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = (0, _template.getTemplates)(context, _types.RenderLevel.CLIENT_RENDER);
|
|
72
70
|
const fallbackHtml = `${shellBefore2}${shellAfter2}`;
|
|
73
71
|
return fallbackHtml;
|
|
@@ -11,9 +11,9 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _define_property = require("@swc/helpers/_/_define_property");
|
|
12
12
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
13
13
|
const _react = /* @__PURE__ */ _interop_require_default._(require("react"));
|
|
14
|
-
const
|
|
14
|
+
const _node = require("@modern-js/runtime-utils/node");
|
|
15
15
|
const _reacthelmet = /* @__PURE__ */ _interop_require_default._(require("react-helmet"));
|
|
16
|
-
const _time = require("@modern-js/utils/
|
|
16
|
+
const _time = require("@modern-js/runtime-utils/time");
|
|
17
17
|
const _utils = require("../../../router/runtime/utils");
|
|
18
18
|
const _helmet = /* @__PURE__ */ _interop_require_default._(require("../helmet"));
|
|
19
19
|
const _types = require("../types");
|
|
@@ -123,13 +123,13 @@ class Entry {
|
|
|
123
123
|
}
|
|
124
124
|
getSSRDataScript(templateData, routerData) {
|
|
125
125
|
const useInlineScript = this.pluginConfig.inlineScript !== false;
|
|
126
|
-
const ssrData = (0,
|
|
126
|
+
const ssrData = (0, _node.serializeJson)(templateData);
|
|
127
127
|
const attrsStr = (0, _utils1.attributesToString)({
|
|
128
128
|
nonce: this.nonce
|
|
129
129
|
});
|
|
130
130
|
let ssrDataScripts = useInlineScript ? `<script${attrsStr}>window._SSR_DATA = ${ssrData}</script>` : `<script type="application/json" id="${_utils1.SSR_DATA_JSON_ID}">${ssrData}</script>`;
|
|
131
131
|
if (routerData) {
|
|
132
|
-
const serializedRouterData = (0,
|
|
132
|
+
const serializedRouterData = (0, _node.serializeJson)(routerData);
|
|
133
133
|
ssrDataScripts += useInlineScript ? `
|
|
134
134
|
<script${attrsStr}>window._ROUTER_DATA = ${serializedRouterData}</script>` : `
|
|
135
135
|
<script type="application/json" id="${_utils1.ROUTER_DATA_JSON_ID}">${serializedRouterData}</script>`;
|
|
@@ -9,14 +9,14 @@ Object.defineProperty(exports, "render", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
-
const
|
|
13
|
-
const _time = require("@modern-js/utils/
|
|
12
|
+
const _node = require("@modern-js/runtime-utils/node");
|
|
13
|
+
const _time = require("@modern-js/runtime-utils/time");
|
|
14
14
|
const _prerender = require("../../react/prerender");
|
|
15
15
|
const _tracker = require("../tracker");
|
|
16
16
|
const _entry = /* @__PURE__ */ _interop_require_default._(require("./entry"));
|
|
17
17
|
const render = ({ App, context, config }) => {
|
|
18
18
|
const ssrContext = context.ssrContext;
|
|
19
|
-
return (0,
|
|
19
|
+
return (0, _node.run)(ssrContext.request.headers, async () => {
|
|
20
20
|
const entry = new _entry.default({
|
|
21
21
|
ctx: ssrContext,
|
|
22
22
|
App,
|
|
@@ -12,11 +12,10 @@ const _define_property = require("@swc/helpers/_/_define_property");
|
|
|
12
12
|
const _server = require("@loadable/server");
|
|
13
13
|
const _utils = require("../utils");
|
|
14
14
|
const extname = (uri) => {
|
|
15
|
-
var _uri;
|
|
16
15
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
17
16
|
return "";
|
|
18
17
|
}
|
|
19
|
-
return `.${
|
|
18
|
+
return `.${uri === null || uri === void 0 ? void 0 : uri.split(".").pop()}` || "";
|
|
20
19
|
};
|
|
21
20
|
class LoadableCollector {
|
|
22
21
|
collect(comopnent) {
|
|
@@ -40,35 +39,47 @@ class LoadableCollector {
|
|
|
40
39
|
const { extractor } = this;
|
|
41
40
|
const chunks = extractor.getChunkAssets(extractor.chunks);
|
|
42
41
|
chunksMap.js = (chunksMap.js || "") + (0, _utils.getLoadableScripts)(extractor);
|
|
42
|
+
const attributes = this.generateAttributes();
|
|
43
43
|
for (const v of chunks) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const { crossorigin, scriptLoading = "defer" } = config;
|
|
47
|
-
if (crossorigin) {
|
|
48
|
-
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
49
|
-
}
|
|
50
|
-
switch (scriptLoading) {
|
|
51
|
-
case "defer":
|
|
52
|
-
attributes.defer = true;
|
|
53
|
-
break;
|
|
54
|
-
case "module":
|
|
55
|
-
attributes.type = "module";
|
|
56
|
-
break;
|
|
57
|
-
default:
|
|
44
|
+
if (!v.url) {
|
|
45
|
+
continue;
|
|
58
46
|
}
|
|
47
|
+
const fileType = extname(v.url).slice(1);
|
|
59
48
|
if (fileType === "js") {
|
|
60
49
|
const jsChunkReg = new RegExp(`<script .*src="${v.url}".*>`);
|
|
61
50
|
if (!jsChunkReg.test(template)) {
|
|
51
|
+
const { scriptLoading = "defer" } = config;
|
|
52
|
+
switch (scriptLoading) {
|
|
53
|
+
case "defer":
|
|
54
|
+
attributes.defer = true;
|
|
55
|
+
break;
|
|
56
|
+
case "module":
|
|
57
|
+
attributes.type = "module";
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
}
|
|
62
61
|
attributes.nonce = nonce;
|
|
63
62
|
const attrsStr = (0, _utils.attributesToString)(attributes);
|
|
64
63
|
chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
|
|
65
64
|
}
|
|
66
65
|
} else if (fileType === "css") {
|
|
67
|
-
const
|
|
68
|
-
|
|
66
|
+
const cssChunkReg = new RegExp(`<link .*href="${v.url}".*>`);
|
|
67
|
+
if (!cssChunkReg.test(template)) {
|
|
68
|
+
const attrsStr = (0, _utils.attributesToString)(attributes);
|
|
69
|
+
chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
|
|
70
|
+
}
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
}
|
|
74
|
+
generateAttributes() {
|
|
75
|
+
const { config } = this.options;
|
|
76
|
+
const { crossorigin } = config;
|
|
77
|
+
const attributes = {};
|
|
78
|
+
if (crossorigin) {
|
|
79
|
+
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
80
|
+
}
|
|
81
|
+
return attributes;
|
|
82
|
+
}
|
|
72
83
|
constructor(options) {
|
|
73
84
|
_define_property._(this, "options", void 0);
|
|
74
85
|
_define_property._(this, "extractor", void 0);
|
|
@@ -58,17 +58,16 @@ export var createApp = function(param) {
|
|
|
58
58
|
var context = _param.context, props = _object_without_properties(_param, [
|
|
59
59
|
"context"
|
|
60
60
|
]);
|
|
61
|
-
var _contextValue;
|
|
62
61
|
var contextValue = context;
|
|
63
|
-
if (!(
|
|
62
|
+
if (!(contextValue === null || contextValue === void 0 ? void 0 : contextValue.runner)) {
|
|
64
63
|
contextValue = getInitialContext(runner);
|
|
65
64
|
runner.init({
|
|
66
65
|
context: contextValue
|
|
67
66
|
}, {
|
|
68
67
|
onLast: function(param3) {
|
|
69
68
|
var context1 = param3.context;
|
|
70
|
-
var _App_init
|
|
71
|
-
return
|
|
69
|
+
var _App_init;
|
|
70
|
+
return _$App === null || _$App === void 0 ? void 0 : (_App_init = _$App.init) === null || _App_init === void 0 ? void 0 : _App_init.call(_$App, context1);
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
73
|
}
|
|
@@ -87,7 +86,7 @@ export var createApp = function(param) {
|
|
|
87
86
|
};
|
|
88
87
|
export var bootstrap = function() {
|
|
89
88
|
var _ref = _async_to_generator(function(BootApp, id, root, ReactDOM) {
|
|
90
|
-
var App, runner, context, runInit, isBrowser, _ssrData_data,
|
|
89
|
+
var App, runner, context, runInit, isBrowser, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate, isRedirectResponse, initialData1;
|
|
91
90
|
return _ts_generator(this, function(_state) {
|
|
92
91
|
switch (_state.label) {
|
|
93
92
|
case 0:
|
|
@@ -106,8 +105,8 @@ export var bootstrap = function() {
|
|
|
106
105
|
}, {
|
|
107
106
|
onLast: function(param) {
|
|
108
107
|
var context1 = param.context;
|
|
109
|
-
var _App_init
|
|
110
|
-
return
|
|
108
|
+
var _App_init;
|
|
109
|
+
return App === null || App === void 0 ? void 0 : (_App_init = App.init) === null || _App_init === void 0 ? void 0 : _App_init.call(App, context1);
|
|
111
110
|
}
|
|
112
111
|
});
|
|
113
112
|
};
|
|
@@ -131,7 +130,7 @@ export var bootstrap = function() {
|
|
|
131
130
|
2
|
|
132
131
|
];
|
|
133
132
|
ssrData = window._SSR_DATA;
|
|
134
|
-
loadersData = (
|
|
133
|
+
loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
135
134
|
initialLoadersState = Object.keys(loadersData).reduce(function(res, key) {
|
|
136
135
|
var loaderData = loadersData[key];
|
|
137
136
|
if (loaderData.loading !== false) {
|
|
@@ -145,9 +144,9 @@ export var bootstrap = function() {
|
|
|
145
144
|
skipStatic: true
|
|
146
145
|
})
|
|
147
146
|
}, ssrData ? {
|
|
148
|
-
ssrContext:
|
|
147
|
+
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
149
148
|
} : {}));
|
|
150
|
-
context.initialData =
|
|
149
|
+
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
151
150
|
return [
|
|
152
151
|
4,
|
|
153
152
|
runInit(context)
|
|
@@ -19,7 +19,7 @@ var useLoader = function(loaderFn) {
|
|
|
19
19
|
delete options._cache;
|
|
20
20
|
}
|
|
21
21
|
var load = useCallback(function(params) {
|
|
22
|
-
var _unlistenLoaderChangeRef_current,
|
|
22
|
+
var _unlistenLoaderChangeRef_current, _window__SSR_DATA_data_loadersData_id, _window__SSR_DATA_data, _window__SSR_DATA, _window, _loaderRef_current;
|
|
23
23
|
if (typeof params === "undefined") {
|
|
24
24
|
var _loaderRef_current1;
|
|
25
25
|
return (_loaderRef_current1 = loaderRef.current) === null || _loaderRef_current1 === void 0 ? void 0 : _loaderRef_current1.load();
|
|
@@ -38,7 +38,7 @@ var useLoader = function(loaderFn) {
|
|
|
38
38
|
params: params
|
|
39
39
|
}));
|
|
40
40
|
loaderRef.current = loaderManager.get(id);
|
|
41
|
-
(_unlistenLoaderChangeRef_current =
|
|
41
|
+
(_unlistenLoaderChangeRef_current = unlistenLoaderChangeRef.current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(unlistenLoaderChangeRef);
|
|
42
42
|
if (isSSRRender) {
|
|
43
43
|
return void 0;
|
|
44
44
|
}
|
|
@@ -52,12 +52,12 @@ var useLoader = function(loaderFn) {
|
|
|
52
52
|
unlistenLoaderChangeRef.current = (_loaderRef_current = loaderRef.current) === null || _loaderRef_current === void 0 ? void 0 : _loaderRef_current.onChange(function(_status, _result) {
|
|
53
53
|
setResult(_result);
|
|
54
54
|
if (_status === LoaderStatus.fulfilled) {
|
|
55
|
-
var _options_onSuccess
|
|
56
|
-
|
|
55
|
+
var _options_onSuccess;
|
|
56
|
+
options === null || options === void 0 ? void 0 : (_options_onSuccess = options.onSuccess) === null || _options_onSuccess === void 0 ? void 0 : _options_onSuccess.call(options, _result.data);
|
|
57
57
|
}
|
|
58
58
|
if (_status === LoaderStatus.rejected) {
|
|
59
|
-
var _options_onError
|
|
60
|
-
|
|
59
|
+
var _options_onError;
|
|
60
|
+
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, _result.error);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
return res;
|
|
@@ -66,8 +66,8 @@ var useLoader = function(loaderFn) {
|
|
|
66
66
|
]);
|
|
67
67
|
useEffect(function() {
|
|
68
68
|
return function() {
|
|
69
|
-
var _unlistenLoaderChangeRef_current
|
|
70
|
-
(_unlistenLoaderChangeRef_current =
|
|
69
|
+
var _unlistenLoaderChangeRef_current;
|
|
70
|
+
(_unlistenLoaderChangeRef_current = unlistenLoaderChangeRef.current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(unlistenLoaderChangeRef);
|
|
71
71
|
};
|
|
72
72
|
}, []);
|
|
73
73
|
useMemo(function() {
|
package/dist/esm/core/plugin.js
CHANGED
|
@@ -23,7 +23,6 @@ var registerInit = function(App, _init) {
|
|
|
23
23
|
var originalInit = App.init;
|
|
24
24
|
App.init = function() {
|
|
25
25
|
var _ref = _async_to_generator(function(context) {
|
|
26
|
-
var _originalInit, _$_init;
|
|
27
26
|
return _ts_generator(this, function(_state) {
|
|
28
27
|
switch (_state.label) {
|
|
29
28
|
case 0:
|
|
@@ -33,8 +32,8 @@ var registerInit = function(App, _init) {
|
|
|
33
32
|
return [
|
|
34
33
|
4,
|
|
35
34
|
Promise.all([
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
originalInit === null || originalInit === void 0 ? void 0 : originalInit(context),
|
|
36
|
+
_init === null || _init === void 0 ? void 0 : _init(context)
|
|
38
37
|
])
|
|
39
38
|
];
|
|
40
39
|
case 1:
|
|
@@ -11,8 +11,7 @@ function findTargetChild(tag, children) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function getEleType(ele) {
|
|
14
|
-
|
|
15
|
-
return typeof ((_ele = ele) === null || _ele === void 0 ? void 0 : _ele.type) === "function" ? ele.type.name : (_ele1 = ele) === null || _ele1 === void 0 ? void 0 : _ele1.type;
|
|
14
|
+
return typeof (ele === null || ele === void 0 ? void 0 : ele.type) === "function" ? ele.type.name : ele === null || ele === void 0 ? void 0 : ele.type;
|
|
16
15
|
}
|
|
17
16
|
function findTargetElement(tag, children) {
|
|
18
17
|
if (children.length === 0) {
|
|
@@ -23,11 +22,11 @@ function findTargetElement(tag, children) {
|
|
|
23
22
|
try {
|
|
24
23
|
for (var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
25
24
|
var item = _step.value;
|
|
26
|
-
var _item_props
|
|
25
|
+
var _item_props;
|
|
27
26
|
if (tag === getEleType(item)) {
|
|
28
27
|
return item;
|
|
29
28
|
}
|
|
30
|
-
if (
|
|
29
|
+
if (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.children) {
|
|
31
30
|
nextChildren = nextChildren.concat(item.props.children);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
@@ -57,7 +57,7 @@ export var documentPlugin = function() {
|
|
|
57
57
|
}
|
|
58
58
|
return function() {
|
|
59
59
|
var _ref2 = _async_to_generator(function(param) {
|
|
60
|
-
var htmlWebpackPlugin,
|
|
60
|
+
var htmlWebpackPlugin, config, documentParams, tempTsConfigFile, userTsConfigFilePath, tsConfig, err, htmlOutputFile, Document, HTMLElement, html, partialsByEntrypoint, scripts, partialsContent, links, metas, nonce, nonceAttr, finalHtml;
|
|
61
61
|
return _ts_generator(this, function(_state2) {
|
|
62
62
|
switch (_state2.label) {
|
|
63
63
|
case 0:
|
|
@@ -96,7 +96,7 @@ export var documentPlugin = function() {
|
|
|
96
96
|
4
|
|
97
97
|
];
|
|
98
98
|
case 4:
|
|
99
|
-
if (
|
|
99
|
+
if (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.compilerOptions) {
|
|
100
100
|
tsConfig.compilerOptions.jsx = "react-jsx";
|
|
101
101
|
} else {
|
|
102
102
|
tsConfig.compilerOptions = {
|
|
@@ -168,7 +168,7 @@ export var documentPlugin = function() {
|
|
|
168
168
|
partialsHead: "",
|
|
169
169
|
partialsBody: ""
|
|
170
170
|
};
|
|
171
|
-
if (
|
|
171
|
+
if (partialsByEntrypoint === null || partialsByEntrypoint === void 0 ? void 0 : partialsByEntrypoint[entryName]) {
|
|
172
172
|
partialsContent.partialsTop = partialsByEntrypoint[entryName].top.join("\n");
|
|
173
173
|
partialsContent.partialsHead = partialsByEntrypoint[entryName].head.join("\n");
|
|
174
174
|
partialsContent.partialsBody = partialsByEntrypoint[entryName].body.join("\n");
|
|
@@ -222,8 +222,7 @@ export var documentPlugin = function() {
|
|
|
222
222
|
return {
|
|
223
223
|
tools: {
|
|
224
224
|
htmlPlugin: function(options, entry) {
|
|
225
|
-
var
|
|
226
|
-
var hackParameters = typeof ((_options = options) === null || _options === void 0 ? void 0 : _options.templateParameters) === "function" ? (_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.templateParameters({}, {}, {}, {}) : _object_spread({}, (_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.templateParameters);
|
|
225
|
+
var hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : _object_spread({}, options === null || options === void 0 ? void 0 : options.templateParameters);
|
|
227
226
|
var templateContent = documentEntry(
|
|
228
227
|
entry.entryName,
|
|
229
228
|
// options,
|
|
@@ -47,13 +47,12 @@ export var routerPlugin = function() {
|
|
|
47
47
|
},
|
|
48
48
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
49
49
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
50
|
-
var _runtimeConfig;
|
|
51
50
|
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
52
51
|
var userConfig = api.useResolvedConfigContext();
|
|
53
52
|
var packageName = api.useAppContext().packageName;
|
|
54
53
|
var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
55
54
|
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
56
|
-
if (
|
|
55
|
+
if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
|
|
57
56
|
if (!isV5(userConfig)) {
|
|
58
57
|
imports.push({
|
|
59
58
|
value: "@modern-js/runtime/plugins",
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { Suspense, useEffect, useRef, useMemo, useContext } from "react";
|
|
4
|
-
import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "@modern-js/utils/
|
|
5
|
-
import { serializeJson } from "@modern-js/utils/
|
|
4
|
+
import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "@modern-js/runtime-utils/router";
|
|
5
|
+
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
6
6
|
import { JSX_SHELL_STREAM_END_MARK } from "../../common";
|
|
7
7
|
import { serializeErrors } from "./utils";
|
|
8
8
|
var 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}}))};";
|
|
9
9
|
var resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
|
|
10
10
|
var preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};";
|
|
11
11
|
var DeferredDataScripts = function(props) {
|
|
12
|
-
var _props;
|
|
13
12
|
var context = useContext(DataRouterContext);
|
|
14
13
|
var staticContext = (context || {}).staticContext;
|
|
15
14
|
var hydratedRef = useRef(false);
|
|
@@ -38,9 +37,8 @@ var DeferredDataScripts = function(props) {
|
|
|
38
37
|
var deferredKeys = deferredData.deferredKeys;
|
|
39
38
|
var deferredKeyPromiseStr = deferredKeys.map(function(key) {
|
|
40
39
|
if (pendingKeys.has(key)) {
|
|
41
|
-
var _props2;
|
|
42
40
|
deferredDataScripts.push(/* @__PURE__ */ _jsx(DeferredDataScript, {
|
|
43
|
-
nonce:
|
|
41
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
44
42
|
data: deferredData.data[key],
|
|
45
43
|
dataKey: key,
|
|
46
44
|
routeId: routeId
|
|
@@ -76,7 +74,7 @@ var DeferredDataScripts = function(props) {
|
|
|
76
74
|
children: [
|
|
77
75
|
!hydratedRef.current && /* @__PURE__ */ _jsx("script", {
|
|
78
76
|
async: true,
|
|
79
|
-
nonce:
|
|
77
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
80
78
|
suppressHydrationWarning: true,
|
|
81
79
|
dangerouslySetInnerHTML: {
|
|
82
80
|
__html: deferredScripts[0]
|
|
@@ -5,12 +5,11 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
7
7
|
import React, { useContext, useMemo } from "react";
|
|
8
|
-
import { Link as RouterLink, matchRoutes, useResolvedPath, useHref, useMatches, NavLink as RouterNavLink } from "@modern-js/utils/
|
|
8
|
+
import { Link as RouterLink, matchRoutes, useResolvedPath, useHref, useMatches, NavLink as RouterNavLink } from "@modern-js/runtime-utils/router";
|
|
9
9
|
import { RuntimeReactContext } from "../../core";
|
|
10
10
|
export function composeEventHandlers(theirHandler, ourHandler) {
|
|
11
11
|
return function(event) {
|
|
12
|
-
|
|
13
|
-
(_theirHandler = theirHandler) === null || _theirHandler === void 0 ? void 0 : _theirHandler(event);
|
|
12
|
+
theirHandler === null || theirHandler === void 0 ? void 0 : theirHandler(event);
|
|
14
13
|
if (!event.defaultPrevented) {
|
|
15
14
|
ourHandler(event);
|
|
16
15
|
}
|
|
@@ -99,8 +98,7 @@ function _loadRouteModule() {
|
|
|
99
98
|
return [
|
|
100
99
|
4,
|
|
101
100
|
Promise.all(chunkIds.map(function(chunkId) {
|
|
102
|
-
|
|
103
|
-
return (_$__webpack_chunk_load__ = __webpack_chunk_load__) === null || _$__webpack_chunk_load__ === void 0 ? void 0 : _$__webpack_chunk_load__(String(chunkId));
|
|
101
|
+
return __webpack_chunk_load__ === null || __webpack_chunk_load__ === void 0 ? void 0 : __webpack_chunk_load__(String(chunkId));
|
|
104
102
|
}))
|
|
105
103
|
];
|
|
106
104
|
case 2:
|
|
@@ -154,8 +152,7 @@ var PrefetchPageLinks = function(param) {
|
|
|
154
152
|
var routeAssets = (routeManifest || {}).routeAssets;
|
|
155
153
|
var matches = Array.isArray(routes) ? matchRoutes(routes, pathname) : [];
|
|
156
154
|
if (Array.isArray(matches) && routeAssets) {
|
|
157
|
-
|
|
158
|
-
(_matches = matches) === null || _matches === void 0 ? void 0 : _matches.forEach(function(match) {
|
|
155
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach(function(match) {
|
|
159
156
|
return loadRouteModule(match.route, routeAssets);
|
|
160
157
|
});
|
|
161
158
|
}
|
|
@@ -173,8 +170,7 @@ var PrefetchDataLinks = function(param) {
|
|
|
173
170
|
var currentMatches = useMatches();
|
|
174
171
|
var basename = useHref("/");
|
|
175
172
|
var dataHrefs = useMemo(function() {
|
|
176
|
-
|
|
177
|
-
return (_matches = matches) === null || _matches === void 0 ? void 0 : _matches.filter(function(match, index) {
|
|
173
|
+
return matches === null || matches === void 0 ? void 0 : matches.filter(function(match, index) {
|
|
178
174
|
if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
|
|
179
175
|
return false;
|
|
180
176
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
export { renderRoutes } from "./utils";
|
|
4
4
|
export default routerPlugin;
|
|
@@ -66,4 +66,4 @@ export {
|
|
|
66
66
|
defer,
|
|
67
67
|
json,
|
|
68
68
|
redirect
|
|
69
|
-
} from "@modern-js/utils/
|
|
69
|
+
} from "@modern-js/runtime-utils/router";
|
|
@@ -3,9 +3,9 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useContext, useMemo } from "react";
|
|
6
|
-
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "@modern-js/utils/
|
|
6
|
+
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "@modern-js/runtime-utils/router";
|
|
7
7
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
8
|
-
import { parsedJSONFromElement } from "@modern-js/utils/
|
|
8
|
+
import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
|
|
9
9
|
import { RuntimeReactContext } from "../../core";
|
|
10
10
|
import { modifyRoutes as modifyRoutesHook } from "./hooks";
|
|
11
11
|
import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
|
|
@@ -56,7 +56,6 @@ export var routerPlugin = function(param) {
|
|
|
56
56
|
},
|
|
57
57
|
hoc: function(param2, next) {
|
|
58
58
|
var App = param2.App;
|
|
59
|
-
var _routesConfig;
|
|
60
59
|
if (!finalRouteConfig && !createRoutes) {
|
|
61
60
|
return next({
|
|
62
61
|
App: App
|
|
@@ -71,8 +70,7 @@ export var routerPlugin = function(param) {
|
|
|
71
70
|
var runtimeContext = useContext(RuntimeReactContext);
|
|
72
71
|
var getBlockNavState = runtimeContext.unstable_getBlockNavState;
|
|
73
72
|
return useMemo(function() {
|
|
74
|
-
|
|
75
|
-
if ((_hydrationData = hydrationData) === null || _hydrationData === void 0 ? void 0 : _hydrationData.errors) {
|
|
73
|
+
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
76
74
|
hydrationData = _object_spread_props(_object_spread({}, hydrationData), {
|
|
77
75
|
errors: deserializeErrors(hydrationData.errors)
|
|
78
76
|
});
|
|
@@ -133,7 +131,7 @@ export var routerPlugin = function(param) {
|
|
|
133
131
|
if (App) {
|
|
134
132
|
RouteApp = hoistNonReactStatics(RouteApp, App);
|
|
135
133
|
}
|
|
136
|
-
if (
|
|
134
|
+
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
|
137
135
|
return next({
|
|
138
136
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
139
137
|
});
|