@modern-js/runtime 2.19.1 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/dist/cjs/cli/index.js +6 -10
- package/dist/cjs/core/compatible.js +4 -47
- package/dist/cjs/core/index.js +4 -16
- package/dist/cjs/core/loader/index.js +2 -6
- package/dist/cjs/core/loader/loaderManager.js +2 -6
- package/dist/cjs/core/loader/useLoader.js +2 -6
- package/dist/cjs/document/Body.js +2 -41
- package/dist/cjs/document/Comment.js +2 -6
- package/dist/cjs/document/DocumentContext.js +2 -6
- package/dist/cjs/document/DocumentStructureContext.js +2 -6
- package/dist/cjs/document/Head.js +2 -41
- package/dist/cjs/document/Html.js +2 -6
- package/dist/cjs/document/Links.js +2 -6
- package/dist/cjs/document/Root.js +2 -41
- package/dist/cjs/document/Script.js +2 -6
- package/dist/cjs/document/Scripts.js +2 -6
- package/dist/cjs/document/cli/index.js +9 -10
- package/dist/cjs/document/index.js +12 -24
- package/dist/cjs/exports/head.js +3 -19
- package/dist/cjs/exports/loadable.js +3 -19
- package/dist/cjs/exports/styled.js +3 -19
- package/dist/cjs/router/index.js +3 -19
- package/dist/cjs/router/runtime/DefaultNotFound.js +2 -6
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +4 -4
- package/dist/cjs/router/runtime/PrefetchLink.js +9 -48
- package/dist/cjs/router/runtime/index.js +57 -70
- package/dist/cjs/router/runtime/plugin.js +10 -14
- package/dist/cjs/router/runtime/plugin.node.js +11 -54
- package/dist/cjs/router/runtime/server.js +2 -14
- package/dist/cjs/router/runtime/utils.js +9 -12
- package/dist/cjs/router/runtime/withRouter.js +6 -10
- package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +4 -47
- package/dist/cjs/ssr/cli/index.js +3 -7
- package/dist/cjs/ssr/cli/loadable-bundler-plugin.js +5 -21
- package/dist/cjs/ssr/index.js +4 -20
- package/dist/cjs/ssr/index.node.js +4 -20
- package/dist/cjs/ssr/react/nossr/index.js +2 -41
- package/dist/cjs/ssr/react/prerender/index.js +8 -63
- package/dist/cjs/ssr/react/withCallback/index.js +2 -41
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +6 -2
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -9
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +2 -6
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +10 -12
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +11 -11
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +28 -77
- package/dist/cjs/ssr/serverRender/renderToString/index.js +2 -6
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +7 -4
- package/dist/cjs/ssr/serverRender/renderToString/reduce.js +2 -6
- package/dist/cjs/ssr/serverRender/renderToString/template.js +6 -18
- package/dist/cjs/ssr/serverRender/utils.js +7 -1
- package/dist/cjs/ssr/utils.js +2 -6
- package/dist/cjs/state/index.js +3 -19
- package/dist/cjs/state/plugins.js +4 -8
- package/dist/cjs/state/runtime/index.js +4 -20
- package/dist/cjs/state/runtime/plugin.js +4 -20
- package/dist/esm/cli/index.js +3 -132
- package/dist/esm/core/compatible.js +7 -233
- package/dist/esm/core/loader/loaderManager.js +7 -212
- package/dist/esm/core/loader/useLoader.js +4 -117
- package/dist/esm/core/plugin.js +3 -132
- package/dist/esm/document/cli/index.js +12 -198
- package/dist/esm/document/constants.js +1 -13
- package/dist/esm/router/cli/index.js +2 -52
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +2 -59
- package/dist/esm/router/runtime/PrefetchLink.js +7 -251
- package/dist/esm/router/runtime/index.js +6 -4
- package/dist/esm/router/runtime/plugin.js +3 -53
- package/dist/esm/router/runtime/plugin.node.js +10 -252
- package/dist/esm/router/runtime/server.js +1 -1
- package/dist/esm/router/runtime/utils.js +8 -151
- package/dist/esm/router/runtime/withRouter.js +3 -53
- package/dist/esm/ssr/cli/index.js +1 -1
- package/dist/esm/ssr/cli/loadable-bundler-plugin.js +6 -108
- package/dist/esm/ssr/index.js +5 -184
- package/dist/esm/ssr/index.node.js +5 -184
- package/dist/esm/ssr/prefetch.js +4 -133
- package/dist/esm/ssr/react/nossr/index.js +1 -58
- package/dist/esm/ssr/react/prerender/index.js +7 -145
- package/dist/esm/ssr/serverRender/index.js +3 -132
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +7 -30
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -73
- package/dist/esm/ssr/serverRender/renderToStream/index.js +3 -132
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +13 -71
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +18 -197
- package/dist/esm/ssr/serverRender/renderToStream/template.js +1 -58
- package/dist/esm/ssr/serverRender/renderToString/entry.js +19 -188
- package/dist/esm/ssr/serverRender/renderToString/index.js +3 -132
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +8 -5
- package/dist/esm/ssr/serverRender/renderToString/template.js +4 -93
- package/dist/esm/ssr/serverRender/time.js +1 -58
- package/dist/esm/ssr/serverRender/time.worker.js +1 -58
- package/dist/esm/ssr/serverRender/utils.js +7 -0
- package/dist/esm/ssr/utils.js +2 -86
- package/dist/esm/state/runtime/plugin.js +3 -110
- package/dist/esm-node/document/cli/index.js +5 -2
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm-node/router/runtime/PrefetchLink.js +1 -1
- package/dist/esm-node/router/runtime/index.js +6 -4
- package/dist/esm-node/router/runtime/plugin.js +1 -1
- package/dist/esm-node/router/runtime/plugin.node.js +3 -3
- package/dist/esm-node/router/runtime/server.js +1 -1
- package/dist/esm-node/router/runtime/utils.js +3 -2
- package/dist/esm-node/router/runtime/withRouter.js +1 -1
- package/dist/esm-node/ssr/cli/index.js +1 -1
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +1 -13
- package/dist/esm-node/ssr/react/prerender/index.js +1 -13
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +6 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +10 -12
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +11 -11
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +12 -18
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +8 -5
- package/dist/esm-node/ssr/serverRender/renderToString/template.js +1 -13
- package/dist/esm-node/ssr/serverRender/utils.js +5 -0
- package/dist/types/cli/index.d.ts +0 -2
- package/dist/types/core/loader/loaderManager.d.ts +0 -1
- package/dist/types/core/loader/useLoader.d.ts +0 -5
- package/dist/types/core/plugin.d.ts +1 -6
- package/dist/types/document/cli/index.d.ts +0 -2
- package/dist/types/router/cli/index.d.ts +0 -2
- package/dist/types/router/runtime/DeferredDataScripts.d.ts +0 -1
- package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +0 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +1 -3
- package/dist/types/router/runtime/hooks.d.ts +1 -1
- package/dist/types/router/runtime/index.d.ts +3 -4
- package/dist/types/router/runtime/server.d.ts +1 -1
- package/dist/types/router/runtime/types.d.ts +1 -3
- package/dist/types/router/runtime/utils.d.ts +1 -3
- package/dist/types/router/runtime/withRouter.d.ts +1 -1
- package/dist/types/runtimeContext.d.ts +1 -1
- package/dist/types/ssr/cli/index.d.ts +0 -2
- package/dist/types/ssr/serverRender/renderToStream/type.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToString/entry.d.ts +1 -0
- package/dist/types/ssr/serverRender/renderToString/type.d.ts +1 -0
- package/dist/types/ssr/serverRender/utils.d.ts +2 -1
- package/dist/types/state/cli/index.d.ts +0 -2
- package/dist/types/state/types.d.ts +0 -1
- package/package.json +28 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRouteLoaderData as useRouteData } from "
|
|
1
|
+
import { useRouteLoaderData as useRouteData } from "@modern-js/utils/runtime/router";
|
|
2
2
|
import { routerPlugin } from "./plugin";
|
|
3
3
|
export default routerPlugin;
|
|
4
4
|
export { modifyRoutes } from "./plugin";
|
|
@@ -61,6 +61,8 @@ export {
|
|
|
61
61
|
resolvePath,
|
|
62
62
|
createPath,
|
|
63
63
|
unstable_useBlocker,
|
|
64
|
-
unstable_usePrompt
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
unstable_usePrompt,
|
|
65
|
+
defer,
|
|
66
|
+
json,
|
|
67
|
+
redirect
|
|
68
|
+
} from "@modern-js/utils/runtime/router";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "
|
|
2
|
+
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "@modern-js/utils/runtime/router";
|
|
3
3
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
4
4
|
import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
|
|
5
5
|
import { modifyRoutes as modifyRoutesHook } from "./hooks";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { createStaticHandler } from "@modern-js/utils/runtime/router";
|
|
4
|
-
import { createStaticRouter, StaticRouterProvider } from "
|
|
3
|
+
import { createStaticHandler } from "@modern-js/utils/runtime/remix-router";
|
|
4
|
+
import { createStaticRouter, StaticRouterProvider } from "@modern-js/utils/runtime-node/router";
|
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
|
-
import { createRoutesFromElements } from "
|
|
6
|
+
import { createRoutesFromElements } from "@modern-js/utils/runtime/router";
|
|
7
7
|
import { RuntimeReactContext } from "../../core";
|
|
8
8
|
import { renderRoutes, urlJoin } from "./utils";
|
|
9
9
|
import { installGlobals } from "./fetch";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "@modern-js/utils/runtime-node/router";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Route } from "
|
|
3
|
-
import { ErrorResponse
|
|
2
|
+
import { Route, isRouteErrorResponse } from "@modern-js/utils/runtime/router";
|
|
3
|
+
import { ErrorResponse } from "@modern-js/utils/runtime/remix-router";
|
|
4
|
+
import { renderNestedRoute } from "@modern-js/utils/runtime/nested-routes";
|
|
4
5
|
import { DefaultNotFound } from "./DefaultNotFound";
|
|
5
6
|
import DeferredDataScripts from "./DeferredDataScripts";
|
|
6
7
|
export function getRouteComponents(routes, { globalApp, ssrMode, props }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useLocation, useNavigate, useParams } from "
|
|
2
|
+
import { useLocation, useNavigate, useParams } from "@modern-js/utils/runtime/router";
|
|
3
3
|
export const withRouter = (Component) => {
|
|
4
4
|
return (props) => {
|
|
5
5
|
const location = useLocation();
|
|
@@ -58,7 +58,7 @@ export default () => {
|
|
|
58
58
|
source: {
|
|
59
59
|
alias: {
|
|
60
60
|
// ensure that all packages use the same storage in @modern-js/utils/runtime-node
|
|
61
|
-
"@modern-js/utils/runtime-node": require.resolve("@modern-js/utils/runtime-node"),
|
|
61
|
+
"@modern-js/utils/runtime-node$": require.resolve("@modern-js/utils/runtime-node"),
|
|
62
62
|
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
|
|
63
63
|
},
|
|
64
64
|
globalVars: (values, { target }) => {
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
14
2
|
import path from "path";
|
|
15
3
|
import { fs } from "@modern-js/utils";
|
|
16
4
|
class LoadablePlugin {
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
14
2
|
import withSideEffect from "react-side-effect";
|
|
15
3
|
import React, { createElement } from "react";
|
|
16
4
|
import { getOutermostProperty, aggKeysFromPropsList, exist, aggMatchesFromPropsList } from "./util";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { serializeJson } from "@modern-js/utils/runtime-node";
|
|
2
|
+
import { attributesToString } from "../utils";
|
|
2
3
|
import { buildTemplate } from "./buildTemplate.share";
|
|
3
4
|
export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
4
5
|
const callbacks = [
|
|
@@ -10,7 +11,7 @@ export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
10
11
|
return template.replace("<!--<?- SSRDataScript ?>-->", ssrDataScript);
|
|
11
12
|
function buildSSRDataScript() {
|
|
12
13
|
const { context: { ssrContext, initialData, __i18nData__ }, renderLevel } = options;
|
|
13
|
-
const { request, enableUnsafeCtx } = ssrContext;
|
|
14
|
+
const { request, enableUnsafeCtx, nonce } = ssrContext;
|
|
14
15
|
const unsafeContext = {
|
|
15
16
|
headers: request.headers
|
|
16
17
|
};
|
|
@@ -31,8 +32,11 @@ export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
31
32
|
},
|
|
32
33
|
renderLevel
|
|
33
34
|
};
|
|
35
|
+
const attrsStr = attributesToString({
|
|
36
|
+
nonce
|
|
37
|
+
});
|
|
34
38
|
return `
|
|
35
|
-
<script>window._SSR_DATA = ${serializeJson(SSRData)}</script>
|
|
39
|
+
<script${attrsStr}>window._SSR_DATA = ${serializeJson(SSRData)}</script>
|
|
36
40
|
`;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ReactHelmet from "react-helmet";
|
|
2
|
-
import { matchRoutes } from "
|
|
2
|
+
import { matchRoutes } from "@modern-js/utils/runtime/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";
|
|
@@ -4,13 +4,13 @@ import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
|
4
4
|
import { getTemplates } from "./template";
|
|
5
5
|
var ShellChunkStatus;
|
|
6
6
|
(function(ShellChunkStatus2) {
|
|
7
|
-
ShellChunkStatus2[ShellChunkStatus2["
|
|
8
|
-
ShellChunkStatus2[ShellChunkStatus2["
|
|
9
|
-
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 2] = "FINIESH";
|
|
7
|
+
ShellChunkStatus2[ShellChunkStatus2["START"] = 0] = "START";
|
|
8
|
+
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
10
9
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
11
10
|
function renderToPipe(rootElement, context, options) {
|
|
12
|
-
let shellChunkStatus = ShellChunkStatus.
|
|
11
|
+
let shellChunkStatus = ShellChunkStatus.START;
|
|
13
12
|
const { ssrContext } = context;
|
|
13
|
+
const chunkVec = [];
|
|
14
14
|
const forUserPipe = (stream) => {
|
|
15
15
|
return new Promise((resolve) => {
|
|
16
16
|
let renderToPipeableStream;
|
|
@@ -20,6 +20,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
20
20
|
}
|
|
21
21
|
const { pipe } = renderToPipeableStream(rootElement, {
|
|
22
22
|
...options,
|
|
23
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
23
24
|
onShellReady() {
|
|
24
25
|
var _options_onShellReady;
|
|
25
26
|
const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.SERVER_RENDER);
|
|
@@ -28,16 +29,13 @@ function renderToPipe(rootElement, context, options) {
|
|
|
28
29
|
transform(chunk, _encoding, callback) {
|
|
29
30
|
try {
|
|
30
31
|
if (shellChunkStatus !== ShellChunkStatus.FINIESH) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
if (shellChunkStatus === ShellChunkStatus.START && concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
37
|
-
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, shellAfter);
|
|
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, "");
|
|
38
36
|
shellChunkStatus = ShellChunkStatus.FINIESH;
|
|
37
|
+
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
|
|
39
38
|
}
|
|
40
|
-
this.push(concatedChunk);
|
|
41
39
|
} else {
|
|
42
40
|
this.push(chunk);
|
|
43
41
|
}
|
|
@@ -3,12 +3,12 @@ import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
|
3
3
|
import { getTemplates } from "./template";
|
|
4
4
|
var ShellChunkStatus;
|
|
5
5
|
(function(ShellChunkStatus2) {
|
|
6
|
-
ShellChunkStatus2[ShellChunkStatus2["
|
|
7
|
-
ShellChunkStatus2[ShellChunkStatus2["
|
|
8
|
-
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 2] = "FINIESH";
|
|
6
|
+
ShellChunkStatus2[ShellChunkStatus2["START"] = 0] = "START";
|
|
7
|
+
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
9
8
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
10
9
|
function renderToPipe(rootElement, context, options) {
|
|
11
|
-
let shellChunkStatus = ShellChunkStatus.
|
|
10
|
+
let shellChunkStatus = ShellChunkStatus.START;
|
|
11
|
+
const chunkVec = [];
|
|
12
12
|
const { ssrContext } = context;
|
|
13
13
|
const forUserPipe = async () => {
|
|
14
14
|
let renderToReadableStream;
|
|
@@ -20,6 +20,7 @@ function renderToPipe(rootElement, context, options) {
|
|
|
20
20
|
try {
|
|
21
21
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
22
22
|
...options,
|
|
23
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
23
24
|
onError(error) {
|
|
24
25
|
var _options_onError;
|
|
25
26
|
ssrContext.logger.error("An error occurs during streaming SSR", error);
|
|
@@ -37,14 +38,13 @@ function renderToPipe(rootElement, context, options) {
|
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
if (shellChunkStatus !== ShellChunkStatus.FINIESH) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (shellChunkStatus === ShellChunkStatus.START && concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
46
|
-
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, shellAfter);
|
|
41
|
+
const chunk = new TextDecoder().decode(value);
|
|
42
|
+
chunkVec.push(chunk);
|
|
43
|
+
let concatedChunk = chunkVec.join("");
|
|
44
|
+
if (concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
45
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
47
46
|
shellChunkStatus = ShellChunkStatus.FINIESH;
|
|
47
|
+
controller.enqueue(encodeForWebStream(`${shellBefore}${concatedChunk}${shellAfter}`));
|
|
48
48
|
}
|
|
49
49
|
controller.enqueue(encodeForWebStream(concatedChunk));
|
|
50
50
|
} else {
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
14
2
|
import React from "react";
|
|
15
3
|
import ReactDomServer from "react-dom/server";
|
|
16
4
|
import { serializeJson } from "@modern-js/utils/runtime-node";
|
|
@@ -20,7 +8,7 @@ import helmetReplace from "../helmet";
|
|
|
20
8
|
import { RenderLevel } from "../types";
|
|
21
9
|
import { time } from "../time";
|
|
22
10
|
import prefetch from "../../prefetch";
|
|
23
|
-
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../utils";
|
|
11
|
+
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID, attributesToString } from "../utils";
|
|
24
12
|
import { toFragments } from "./template";
|
|
25
13
|
import { reduce } from "./reduce";
|
|
26
14
|
import * as loadableRenderer from "./loadable";
|
|
@@ -111,7 +99,8 @@ class Entry {
|
|
|
111
99
|
host: this.host,
|
|
112
100
|
result: this.result,
|
|
113
101
|
entryName: this.entryName,
|
|
114
|
-
config: this.pluginConfig
|
|
102
|
+
config: this.pluginConfig,
|
|
103
|
+
nonce: this.nonce
|
|
115
104
|
};
|
|
116
105
|
html = reduce(App, renderContext, [
|
|
117
106
|
styledComponentRenderer.toHtml,
|
|
@@ -131,11 +120,14 @@ class Entry {
|
|
|
131
120
|
getSSRDataScript(templateData, routerData) {
|
|
132
121
|
const useInlineScript = this.pluginConfig.inlineScript !== false;
|
|
133
122
|
const ssrData = serializeJson(templateData);
|
|
134
|
-
|
|
123
|
+
const attrsStr = attributesToString({
|
|
124
|
+
nonce: this.nonce
|
|
125
|
+
});
|
|
126
|
+
let ssrDataScripts = useInlineScript ? `<script${attrsStr}>window._SSR_DATA = ${ssrData}</script>` : `<script type="application/json" id="${SSR_DATA_JSON_ID}">${ssrData}</script>`;
|
|
135
127
|
if (routerData) {
|
|
136
128
|
const serializedRouterData = serializeJson(routerData);
|
|
137
129
|
ssrDataScripts += useInlineScript ? `
|
|
138
|
-
<script>window._ROUTER_DATA = ${serializedRouterData}</script>` : `
|
|
130
|
+
<script${attrsStr}>window._ROUTER_DATA = ${serializedRouterData}</script>` : `
|
|
139
131
|
<script type="application/json" id="${ROUTER_DATA_JSON_ID}">${serializedRouterData}</script>`;
|
|
140
132
|
}
|
|
141
133
|
return {
|
|
@@ -151,8 +143,9 @@ class Entry {
|
|
|
151
143
|
_define_property(this, "fragments", void 0);
|
|
152
144
|
_define_property(this, "pluginConfig", void 0);
|
|
153
145
|
_define_property(this, "host", void 0);
|
|
146
|
+
_define_property(this, "nonce", void 0);
|
|
154
147
|
const { ctx, config } = options;
|
|
155
|
-
const { entryName, template, request: { host } } = ctx;
|
|
148
|
+
const { entryName, template, request: { host }, nonce } = ctx;
|
|
156
149
|
this.fragments = toFragments(template, entryName);
|
|
157
150
|
this.entryName = entryName;
|
|
158
151
|
this.host = host;
|
|
@@ -160,6 +153,7 @@ class Entry {
|
|
|
160
153
|
this.pluginConfig = config;
|
|
161
154
|
this.metrics = ctx.metrics;
|
|
162
155
|
this.logger = ctx.logger;
|
|
156
|
+
this.nonce = nonce;
|
|
163
157
|
this.result = {
|
|
164
158
|
renderLevel: RenderLevel.CLIENT_RENDER,
|
|
165
159
|
html: "",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChunkExtractor } from "@loadable/server";
|
|
2
2
|
import { isCrossOrigin } from "../../utils";
|
|
3
|
-
import { getLoadableScripts } from "../utils";
|
|
3
|
+
import { attributesToString, getLoadableScripts } from "../utils";
|
|
4
4
|
const extname = (uri) => {
|
|
5
5
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
6
6
|
return "";
|
|
@@ -8,7 +8,7 @@ const extname = (uri) => {
|
|
|
8
8
|
return `.${uri === null || uri === void 0 ? void 0 : uri.split(".").pop()}` || "";
|
|
9
9
|
};
|
|
10
10
|
export const toHtml = (jsx, renderer, next) => {
|
|
11
|
-
const { stats, result: { chunksMap }, host, config = {} } = renderer;
|
|
11
|
+
const { stats, result: { chunksMap }, host, config = {}, nonce } = renderer;
|
|
12
12
|
if (!stats || chunksMap.js) {
|
|
13
13
|
return next(jsx);
|
|
14
14
|
}
|
|
@@ -24,12 +24,15 @@ export const toHtml = (jsx, renderer, next) => {
|
|
|
24
24
|
for (const v of chunks) {
|
|
25
25
|
const fileType = extname(v.url).slice(1);
|
|
26
26
|
if (fileType === "js") {
|
|
27
|
-
const
|
|
27
|
+
const attributes = {
|
|
28
|
+
nonce
|
|
29
|
+
};
|
|
28
30
|
const { crossorigin } = config;
|
|
29
31
|
if (crossorigin && isCrossOrigin(v.url, host)) {
|
|
30
|
-
|
|
32
|
+
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
const attrsStr = attributesToString(attributes);
|
|
35
|
+
chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
|
|
33
36
|
} else if (fileType === "css") {
|
|
34
37
|
chunksMap[fileType] += `<link href="${v.url}" rel="stylesheet" />`;
|
|
35
38
|
}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
14
2
|
const VARIABLE_REG_EXP = /<!--<\?([-=+])\s*(.*?)\s*\?>-->/;
|
|
15
3
|
const VARIABLE_SPLITTER = /(<!--<\?.*?\?>-->)/;
|
|
16
4
|
const ENCODE_HTML_RULES = {
|
|
@@ -9,3 +9,8 @@ export function getLoadableScripts(extractor) {
|
|
|
9
9
|
}
|
|
10
10
|
return scripts.split("</script>").slice(0, 2).map((i) => `${i}</script>`).join("");
|
|
11
11
|
}
|
|
12
|
+
export function attributesToString(attributes) {
|
|
13
|
+
return Object.entries(attributes).reduce((str, [key, value]) => {
|
|
14
|
+
return value === void 0 ? str : `${str} ${key}="${value}"`;
|
|
15
|
+
}, "");
|
|
16
|
+
}
|
|
@@ -35,7 +35,6 @@ type ManagerOption = {
|
|
|
35
35
|
* Create loaders manager. It's returned instance will add to context
|
|
36
36
|
* @param initialDataMap used to initialing loader data
|
|
37
37
|
*/
|
|
38
|
-
|
|
39
38
|
export declare const createLoaderManager: (initialDataMap: Record<string, LoaderResult>, managerOptions?: ManagerOption) => {
|
|
40
39
|
hasPendingLoaders: () => boolean;
|
|
41
40
|
awaitPendingLoaders: () => Promise<Record<string, LoaderResult>>;
|
|
@@ -7,28 +7,23 @@ export interface LoaderOptions<Params = any, TData = any, TError extends Error =
|
|
|
7
7
|
/**
|
|
8
8
|
* Revoke when loader ended with error
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
onError?: (error: TError) => void;
|
|
12
11
|
/**
|
|
13
12
|
* initialData to display once loader is ready.
|
|
14
13
|
*/
|
|
15
|
-
|
|
16
14
|
initialData?: TData;
|
|
17
15
|
/**
|
|
18
16
|
* whether skip loader
|
|
19
17
|
* if true, the loader will not exec.
|
|
20
18
|
*/
|
|
21
|
-
|
|
22
19
|
skip?: boolean;
|
|
23
20
|
/**
|
|
24
21
|
* User params, it will pass to loader's second parameter.
|
|
25
22
|
*/
|
|
26
|
-
|
|
27
23
|
params?: Params;
|
|
28
24
|
/**
|
|
29
25
|
* whether loader can exec on build phase.
|
|
30
26
|
*/
|
|
31
|
-
|
|
32
27
|
static?: boolean;
|
|
33
28
|
}
|
|
34
29
|
declare const useLoader: <TData = any, Params = any, E = any>(loaderFn: LoaderFn<Params, TData>, options?: LoaderOptions<Params, any, any>) => {
|
|
@@ -30,16 +30,12 @@ declare const runtimeHooks: {
|
|
|
30
30
|
}, TRuntimeContext>;
|
|
31
31
|
};
|
|
32
32
|
/** All hooks of runtime plugin. */
|
|
33
|
-
|
|
34
33
|
export type RuntimeHooks = typeof runtimeHooks;
|
|
35
34
|
/** All hook callbacks of runtime plugin. */
|
|
36
|
-
|
|
37
35
|
export type RuntimeHookCallbacks = ToThreads<RuntimeHooks>;
|
|
38
36
|
/** All apis for runtime plugin. */
|
|
39
|
-
|
|
40
37
|
export type PluginAPI = CommonAPI<RuntimeHooks>;
|
|
41
38
|
/** Plugin options of a runtime plugin. */
|
|
42
|
-
|
|
43
39
|
export type Plugin = PluginOptions<RuntimeHooks, Setup<RuntimeHooks>>;
|
|
44
40
|
export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
|
|
45
41
|
hoc: import("@modern-js/plugin").Pipeline<{
|
|
@@ -71,7 +67,6 @@ export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
|
|
|
71
67
|
/**
|
|
72
68
|
* register init hook. It would be revoked both ssr and csr.
|
|
73
69
|
*/
|
|
74
|
-
|
|
75
70
|
declare const registerInit: (App: React.ComponentType, _init: (context: RuntimeContext) => any | Promise<any>) => void;
|
|
76
71
|
export declare const runtime: import("@modern-js/plugin").Manager<{
|
|
77
72
|
hoc: import("@modern-js/plugin").Pipeline<{
|
|
@@ -178,7 +173,7 @@ export declare const createPlugin: (setup?: Setup<{
|
|
|
178
173
|
context: RuntimeContext;
|
|
179
174
|
pickedContext: TRuntimeContext;
|
|
180
175
|
}, TRuntimeContext>;
|
|
181
|
-
}, Record<string, never
|
|
176
|
+
}, Record<string, never>>> | undefined) => import("@modern-js/plugin").Plugin<{
|
|
182
177
|
hoc: import("@modern-js/plugin").Pipeline<{
|
|
183
178
|
App: React.ComponentType<any>;
|
|
184
179
|
}, React.ComponentType<any>>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
|
2
2
|
import { Entrypoint } from '@modern-js/types/cli';
|
|
3
3
|
export declare const getDocumenByEntryName: (entrypoints: Entrypoint[], entryName: string, fallbackDir?: string) => string | undefined;
|
|
4
|
-
|
|
5
4
|
declare const _default: () => CliPlugin<AppTools>;
|
|
6
|
-
|
|
7
5
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '
|
|
2
|
+
import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '@modern-js/utils/runtime/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
|
|
@@ -9,7 +9,6 @@ export declare function composeEventHandlers<EventType extends React.SyntheticEv
|
|
|
9
9
|
* Copyright 2021 Remix Software Inc.
|
|
10
10
|
* https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/LICENSE.md
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Defines the prefetching behavior of the link:
|
|
15
14
|
*
|
|
@@ -17,7 +16,6 @@ export declare function composeEventHandlers<EventType extends React.SyntheticEv
|
|
|
17
16
|
* - "render": Fetched when the link is rendered
|
|
18
17
|
* - "none": Never fetched
|
|
19
18
|
*/
|
|
20
|
-
|
|
21
19
|
type PrefetchBehavior = 'intent' | 'render' | 'none';
|
|
22
20
|
export interface LinkProps extends RouterLinkProps {
|
|
23
21
|
prefetch?: PrefetchBehavior;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRouteLoaderData as useRouteData } from '
|
|
1
|
+
import { useRouteLoaderData as useRouteData } from '@modern-js/utils/runtime/router';
|
|
2
2
|
import { routerPlugin } from './plugin';
|
|
3
3
|
import type { SingleRouteConfig, RouterConfig } from './types';
|
|
4
4
|
export type { SingleRouteConfig, RouterConfig };
|
|
@@ -8,6 +8,5 @@ export * from './withRouter';
|
|
|
8
8
|
export { Link, NavLink } from './PrefetchLink';
|
|
9
9
|
export type { LinkProps, NavLinkProps } from './PrefetchLink';
|
|
10
10
|
export declare const useRouteLoaderData: typeof useRouteData;
|
|
11
|
-
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, LoaderFunction, LoaderFunctionArgs, 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 '
|
|
12
|
-
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 } from '
|
|
13
|
-
export { defer, json, redirect } from '@modern-js/utils/runtime/router';
|
|
11
|
+
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, LoaderFunction, LoaderFunctionArgs, 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/runtime/router';
|
|
12
|
+
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/runtime/router';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from '@modern-js/utils/runtime-node/router';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { RouteProps, RouteObject } from '
|
|
2
|
+
import type { RouteProps, RouteObject } from '@modern-js/utils/runtime/router';
|
|
3
3
|
import { PageRoute, NestedRoute } from '@modern-js/types';
|
|
4
4
|
declare global {
|
|
5
5
|
interface Window {
|
|
@@ -18,12 +18,10 @@ export type SingleRouteConfig = RouteProps & {
|
|
|
18
18
|
/**
|
|
19
19
|
* layout component
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
21
|
layout?: React.ComponentType;
|
|
23
22
|
/**
|
|
24
23
|
* component would be rendered when route macthed.
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
25
|
component?: React.ComponentType;
|
|
28
26
|
};
|
|
29
27
|
export type RouterConfig = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type NestedRoute, type PageRoute, type SSRMode } from '@modern-js/types';
|
|
3
|
-
import { type
|
|
3
|
+
import { type StaticHandlerContext, type Router } from '@modern-js/utils/runtime/remix-router';
|
|
4
4
|
import { RouterConfig } from './types';
|
|
5
5
|
export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[], {
|
|
6
6
|
globalApp,
|
|
@@ -27,11 +27,9 @@ export declare function standardSlash(str: string): string;
|
|
|
27
27
|
* forked from https://github.com/remix-run/remix/blob/main/packages/remix-server-runtime/errors.ts
|
|
28
28
|
* license at https://github.com/remix-run/remix/blob/main/LICENSE.md
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
export declare function serializeErrors(errors: StaticHandlerContext['errors']): StaticHandlerContext['errors'];
|
|
32
31
|
/**
|
|
33
32
|
* forked from https://github.com/remix-run/remix/blob/main/packages/remix-react/errors.ts
|
|
34
33
|
* license at https://github.com/remix-run/remix/blob/main/LICENSE.md
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
35
|
export declare function deserializeErrors(errors: Router['state']['errors']): Router['state']['errors'];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useLocation, useNavigate } from '
|
|
2
|
+
import { useLocation, useNavigate } from '@modern-js/utils/runtime/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 } from '@modern-js/utils/runtime/router';
|
|
3
|
+
import type { StaticHandlerContext } from '@modern-js/utils/runtime/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';
|
|
@@ -14,6 +14,7 @@ export default class Entry {
|
|
|
14
14
|
private readonly fragments;
|
|
15
15
|
private readonly pluginConfig;
|
|
16
16
|
private readonly host;
|
|
17
|
+
private readonly nonce?;
|
|
17
18
|
constructor(options: EntryOptions);
|
|
18
19
|
renderToHtml(context: RuntimeContext): Promise<string>;
|
|
19
20
|
private prefetch;
|