@modern-js/runtime 2.20.0 → 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 +38 -0
- package/dist/cjs/document/cli/index.js +5 -2
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +4 -4
- package/dist/cjs/router/runtime/PrefetchLink.js +7 -7
- package/dist/cjs/router/runtime/index.js +55 -56
- package/dist/cjs/router/runtime/plugin.js +7 -7
- package/dist/cjs/router/runtime/plugin.node.js +7 -7
- package/dist/cjs/router/runtime/server.js +1 -1
- package/dist/cjs/router/runtime/utils.js +6 -5
- package/dist/cjs/router/runtime/withRouter.js +4 -4
- package/dist/cjs/ssr/cli/index.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +6 -2
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- 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 +10 -4
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +7 -4
- package/dist/cjs/ssr/serverRender/utils.js +7 -1
- package/dist/esm/document/cli/index.js +6 -3
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm/router/runtime/PrefetchLink.js +1 -1
- package/dist/esm/router/runtime/index.js +6 -4
- package/dist/esm/router/runtime/plugin.js +1 -1
- package/dist/esm/router/runtime/plugin.node.js +3 -3
- package/dist/esm/router/runtime/server.js +1 -1
- package/dist/esm/router/runtime/utils.js +3 -2
- package/dist/esm/router/runtime/withRouter.js +1 -1
- package/dist/esm/ssr/cli/index.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +6 -2
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +10 -12
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +12 -12
- package/dist/esm/ssr/serverRender/renderToString/entry.js +11 -5
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +8 -5
- package/dist/esm/ssr/serverRender/utils.js +7 -0
- 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/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 +11 -5
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +8 -5
- 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 +27 -20
|
@@ -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 {
|
|
@@ -8,7 +8,7 @@ import helmetReplace from "../helmet";
|
|
|
8
8
|
import { RenderLevel } from "../types";
|
|
9
9
|
import { time } from "../time";
|
|
10
10
|
import prefetch from "../../prefetch";
|
|
11
|
-
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../utils";
|
|
11
|
+
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID, attributesToString } from "../utils";
|
|
12
12
|
import { toFragments } from "./template";
|
|
13
13
|
import { reduce } from "./reduce";
|
|
14
14
|
import * as loadableRenderer from "./loadable";
|
|
@@ -99,7 +99,8 @@ class Entry {
|
|
|
99
99
|
host: this.host,
|
|
100
100
|
result: this.result,
|
|
101
101
|
entryName: this.entryName,
|
|
102
|
-
config: this.pluginConfig
|
|
102
|
+
config: this.pluginConfig,
|
|
103
|
+
nonce: this.nonce
|
|
103
104
|
};
|
|
104
105
|
html = reduce(App, renderContext, [
|
|
105
106
|
styledComponentRenderer.toHtml,
|
|
@@ -119,11 +120,14 @@ class Entry {
|
|
|
119
120
|
getSSRDataScript(templateData, routerData) {
|
|
120
121
|
const useInlineScript = this.pluginConfig.inlineScript !== false;
|
|
121
122
|
const ssrData = serializeJson(templateData);
|
|
122
|
-
|
|
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>`;
|
|
123
127
|
if (routerData) {
|
|
124
128
|
const serializedRouterData = serializeJson(routerData);
|
|
125
129
|
ssrDataScripts += useInlineScript ? `
|
|
126
|
-
<script>window._ROUTER_DATA = ${serializedRouterData}</script>` : `
|
|
130
|
+
<script${attrsStr}>window._ROUTER_DATA = ${serializedRouterData}</script>` : `
|
|
127
131
|
<script type="application/json" id="${ROUTER_DATA_JSON_ID}">${serializedRouterData}</script>`;
|
|
128
132
|
}
|
|
129
133
|
return {
|
|
@@ -139,8 +143,9 @@ class Entry {
|
|
|
139
143
|
_define_property(this, "fragments", void 0);
|
|
140
144
|
_define_property(this, "pluginConfig", void 0);
|
|
141
145
|
_define_property(this, "host", void 0);
|
|
146
|
+
_define_property(this, "nonce", void 0);
|
|
142
147
|
const { ctx, config } = options;
|
|
143
|
-
const { entryName, template, request: { host } } = ctx;
|
|
148
|
+
const { entryName, template, request: { host }, nonce } = ctx;
|
|
144
149
|
this.fragments = toFragments(template, entryName);
|
|
145
150
|
this.entryName = entryName;
|
|
146
151
|
this.host = host;
|
|
@@ -148,6 +153,7 @@ class Entry {
|
|
|
148
153
|
this.pluginConfig = config;
|
|
149
154
|
this.metrics = ctx.metrics;
|
|
150
155
|
this.logger = ctx.logger;
|
|
156
|
+
this.nonce = nonce;
|
|
151
157
|
this.result = {
|
|
152
158
|
renderLevel: RenderLevel.CLIENT_RENDER,
|
|
153
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
|
}
|
|
@@ -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;
|
|
@@ -19,6 +19,7 @@ export interface RenderEntry {
|
|
|
19
19
|
result: RenderResult;
|
|
20
20
|
stats: Record<string, any>;
|
|
21
21
|
config: SSRPluginConfig;
|
|
22
|
+
nonce?: string;
|
|
22
23
|
}
|
|
23
24
|
export type RenderHandler = (jsx: React.ReactElement, renderer: RenderEntry, next: (jsx: React.ReactElement) => string) => string;
|
|
24
25
|
export type RenderResult = {
|
|
@@ -2,4 +2,5 @@ import type { ChunkExtractor } from '@loadable/server';
|
|
|
2
2
|
export declare const CSS_CHUNKS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
|
|
3
3
|
export declare const SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
|
|
4
4
|
export declare const ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
|
|
5
|
-
export declare function getLoadableScripts(extractor: ChunkExtractor): string;
|
|
5
|
+
export declare function getLoadableScripts(extractor: ChunkExtractor): string;
|
|
6
|
+
export declare function attributesToString(attributes: Record<string, any>): string;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.21.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -88,6 +88,11 @@
|
|
|
88
88
|
"jsnext:source": "./src/router/runtime/server.ts",
|
|
89
89
|
"types": "./dist/types/router/runtime/server.d.ts",
|
|
90
90
|
"default": "./dist/esm/router/runtime/server.js"
|
|
91
|
+
},
|
|
92
|
+
"./loadable-bundler-plugin": {
|
|
93
|
+
"jsnext:source": "./src/ssr/cli/loadable-bundler-plugin.ts",
|
|
94
|
+
"types": "./dist/types/ssr/cli/loadable-bundler-plugin.d.ts",
|
|
95
|
+
"default": "./dist/cjs/ssr/cli/loadable-bundler-plugin.js"
|
|
91
96
|
}
|
|
92
97
|
},
|
|
93
98
|
"typesVersions": {
|
|
@@ -130,23 +135,26 @@
|
|
|
130
135
|
],
|
|
131
136
|
"router/server": [
|
|
132
137
|
"./dist/types/router/runtime/server.d.ts"
|
|
138
|
+
],
|
|
139
|
+
"loadable-bundler-plugin": [
|
|
140
|
+
"./dist/types/ssr/cli/loadable-bundler-plugin.d.ts"
|
|
133
141
|
]
|
|
134
142
|
}
|
|
135
143
|
},
|
|
136
144
|
"dependencies": {
|
|
137
|
-
"@babel/core": "^7.
|
|
138
|
-
"@babel/types": "^7.
|
|
145
|
+
"@babel/core": "^7.21.8",
|
|
146
|
+
"@babel/types": "^7.21.5",
|
|
139
147
|
"cookie": "0.5.0",
|
|
140
148
|
"@loadable/babel-plugin": "^5.13.2",
|
|
141
149
|
"@loadable/component": "^5.15.0",
|
|
142
150
|
"@loadable/server": "^5.15.1",
|
|
143
151
|
"@loadable/webpack-plugin": "5.15.2",
|
|
144
|
-
"@modern-js-reduck/plugin-auto-actions": "^1.1.
|
|
145
|
-
"@modern-js-reduck/plugin-devtools": "^1.1.
|
|
146
|
-
"@modern-js-reduck/plugin-effects": "^1.1.
|
|
147
|
-
"@modern-js-reduck/plugin-immutable": "^1.1.
|
|
148
|
-
"@modern-js-reduck/react": "^1.1.
|
|
149
|
-
"@modern-js-reduck/store": "^1.1.
|
|
152
|
+
"@modern-js-reduck/plugin-auto-actions": "^1.1.10",
|
|
153
|
+
"@modern-js-reduck/plugin-devtools": "^1.1.10",
|
|
154
|
+
"@modern-js-reduck/plugin-effects": "^1.1.10",
|
|
155
|
+
"@modern-js-reduck/plugin-immutable": "^1.1.10",
|
|
156
|
+
"@modern-js-reduck/react": "^1.1.10",
|
|
157
|
+
"@modern-js-reduck/store": "^1.1.10",
|
|
150
158
|
"@remix-run/node": "^1.12.0",
|
|
151
159
|
"@types/loadable__component": "^5.13.4",
|
|
152
160
|
"@types/react-helmet": "^6.1.2",
|
|
@@ -157,14 +165,13 @@
|
|
|
157
165
|
"invariant": "^2.2.4",
|
|
158
166
|
"react-helmet": "^6.1.0",
|
|
159
167
|
"react-is": "^18",
|
|
160
|
-
"react-router-dom": "^6.8.1",
|
|
161
168
|
"react-side-effect": "^2.1.1",
|
|
162
169
|
"redux-logger": "^3.0.6",
|
|
163
170
|
"styled-components": "^5.3.1",
|
|
164
171
|
"@swc/helpers": "0.5.1",
|
|
165
|
-
"@modern-js/plugin": "2.
|
|
166
|
-
"@modern-js/types": "2.
|
|
167
|
-
"@modern-js/utils": "2.
|
|
172
|
+
"@modern-js/plugin": "2.21.0",
|
|
173
|
+
"@modern-js/types": "2.21.0",
|
|
174
|
+
"@modern-js/utils": "2.21.0"
|
|
168
175
|
},
|
|
169
176
|
"peerDependencies": {
|
|
170
177
|
"react": ">=17",
|
|
@@ -182,13 +189,13 @@
|
|
|
182
189
|
"jest": "^29",
|
|
183
190
|
"react": "^18",
|
|
184
191
|
"react-dom": "^18",
|
|
185
|
-
"ts-jest": "^29.0
|
|
186
|
-
"typescript": "^
|
|
187
|
-
"@modern-js/app-tools": "2.
|
|
188
|
-
"@modern-js/core": "2.
|
|
189
|
-
"@modern-js/server-core": "2.
|
|
190
|
-
"@scripts/build": "2.
|
|
191
|
-
"@scripts/jest-config": "2.
|
|
192
|
+
"ts-jest": "^29.1.0",
|
|
193
|
+
"typescript": "^5",
|
|
194
|
+
"@modern-js/app-tools": "2.21.0",
|
|
195
|
+
"@modern-js/core": "2.21.0",
|
|
196
|
+
"@modern-js/server-core": "2.21.0",
|
|
197
|
+
"@scripts/build": "2.21.0",
|
|
198
|
+
"@scripts/jest-config": "2.21.0"
|
|
192
199
|
},
|
|
193
200
|
"sideEffects": false,
|
|
194
201
|
"modernConfig": {},
|