@modern-js/runtime 2.5.0 → 2.7.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 +55 -0
- package/dist/cjs/cli/index.js +9 -0
- package/dist/cjs/common.js +6 -0
- package/dist/cjs/core/{app-config.js → appConfig.js} +8 -4
- package/dist/cjs/core/compatible.js +11 -10
- package/dist/cjs/core/index.js +6 -6
- package/dist/cjs/core/loader/index.js +4 -0
- package/dist/cjs/core/loader/loaderManager.js +6 -0
- package/dist/cjs/core/loader/useLoader.js +6 -2
- package/dist/cjs/core/types.js +15 -0
- package/dist/cjs/document/Body.js +6 -8
- package/dist/cjs/document/DocumentContext.js +4 -0
- package/dist/cjs/document/DocumentStructureContext.js +4 -0
- package/dist/cjs/document/Head.js +7 -11
- package/dist/cjs/document/Html.js +24 -22
- package/dist/cjs/document/Links.js +1 -3
- package/dist/cjs/document/Root.js +8 -14
- package/dist/cjs/document/Script.js +5 -7
- package/dist/cjs/document/Scripts.js +1 -3
- package/dist/cjs/document/cli/index.js +8 -2
- package/dist/cjs/exports/head.js +4 -0
- package/dist/cjs/exports/loadable.js +4 -0
- package/dist/cjs/exports/styled.js +4 -0
- package/dist/cjs/router/cli/index.js +3 -7
- package/dist/cjs/router/index.js +4 -0
- package/dist/cjs/router/runtime/DefaultNotFound.js +13 -10
- package/dist/cjs/router/runtime/DeferredDataScripts.js +165 -0
- package/dist/cjs/router/runtime/index.js +116 -3
- package/dist/cjs/router/runtime/plugin.js +18 -6
- package/dist/cjs/router/runtime/plugin.node.js +16 -49
- package/dist/cjs/router/runtime/utils.js +79 -101
- package/dist/cjs/router/runtime/withRouter.js +9 -6
- package/dist/cjs/{runtime-context.js → runtimeContext.js} +3 -3
- package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +4 -0
- package/dist/cjs/ssr/cli/index.js +6 -0
- package/dist/cjs/ssr/index.js +10 -24
- package/dist/cjs/ssr/index.node.js +5 -0
- package/dist/cjs/ssr/prefetch.js +3 -6
- package/dist/cjs/ssr/react/nossr/index.js +4 -0
- package/dist/cjs/ssr/react/prerender/index.js +4 -0
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +7 -13
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -0
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +4 -0
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +22 -7
- package/dist/cjs/ssr/serverRender/renderToStream/template.js +2 -1
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +28 -11
- package/dist/cjs/ssr/serverRender/renderToString/index.js +4 -0
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +1 -1
- package/dist/cjs/ssr/serverRender/time.worker.js +1 -1
- package/dist/cjs/ssr/serverRender/utils.js +1 -1
- package/dist/cjs/ssr/utils.js +16 -4
- package/dist/cjs/state/index.js +4 -0
- package/dist/cjs/state/plugins.js +4 -0
- package/dist/cjs/state/runtime/index.js +4 -0
- package/dist/cjs/state/runtime/plugin.js +5 -7
- package/dist/esm/cli/index.js +5 -1
- package/dist/esm/common.js +3 -1
- package/dist/esm/core/{app-config.js → appConfig.js} +3 -1
- package/dist/esm/core/compatible.js +4 -2
- package/dist/esm/core/index.js +2 -2
- package/dist/esm/core/loader/loaderManager.js +3 -1
- package/dist/esm/core/loader/useLoader.js +1 -1
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/document/cli/index.js +4 -2
- package/dist/esm/router/cli/index.js +1 -5
- package/dist/esm/router/runtime/DeferredDataScripts.js +166 -0
- package/dist/esm/router/runtime/index.js +3 -2
- package/dist/esm/router/runtime/plugin.js +11 -3
- package/dist/esm/router/runtime/plugin.node.js +11 -68
- package/dist/esm/router/runtime/utils.js +138 -81
- package/dist/esm/ssr/cli/index.js +2 -0
- package/dist/esm/ssr/index.node.js +1 -0
- package/dist/esm/ssr/prefetch.js +1 -0
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +37 -10
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -0
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +19 -8
- package/dist/esm/ssr/serverRender/renderToStream/template.js +2 -1
- package/dist/esm/ssr/serverRender/renderToString/entry.js +37 -13
- package/dist/esm/ssr/serverRender/time.worker.js +1 -1
- package/dist/esm/ssr/utils.js +6 -4
- package/dist/esm-node/cli/index.js +5 -0
- package/dist/esm-node/common.js +4 -0
- package/dist/esm-node/core/{app-config.js → appConfig.js} +5 -1
- package/dist/esm-node/core/compatible.js +5 -8
- package/dist/esm-node/core/index.js +2 -2
- package/dist/esm-node/core/loader/loaderManager.js +2 -0
- package/dist/esm-node/core/loader/useLoader.js +1 -1
- package/dist/esm-node/core/types.js +0 -0
- package/dist/esm-node/document/Body.js +6 -8
- package/dist/esm-node/document/Head.js +7 -11
- package/dist/esm-node/document/Html.js +24 -22
- package/dist/esm-node/document/Links.js +1 -3
- package/dist/esm-node/document/Root.js +8 -14
- package/dist/esm-node/document/Script.js +5 -7
- package/dist/esm-node/document/Scripts.js +1 -3
- package/dist/esm-node/document/cli/index.js +4 -2
- package/dist/esm-node/router/cli/index.js +2 -5
- package/dist/esm-node/router/runtime/DefaultNotFound.js +13 -10
- package/dist/esm-node/router/runtime/DeferredDataScripts.js +148 -0
- package/dist/esm-node/router/runtime/index.js +113 -2
- package/dist/esm-node/router/runtime/plugin.js +15 -7
- package/dist/esm-node/router/runtime/plugin.node.js +12 -52
- package/dist/esm-node/router/runtime/utils.js +70 -101
- package/dist/esm-node/router/runtime/withRouter.js +9 -6
- package/dist/esm-node/ssr/cli/index.js +2 -0
- package/dist/esm-node/ssr/index.js +6 -24
- package/dist/esm-node/ssr/index.node.js +1 -0
- package/dist/esm-node/ssr/prefetch.js +3 -6
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +7 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -0
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +22 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/template.js +2 -1
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +24 -11
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +1 -1
- package/dist/esm-node/ssr/serverRender/time.worker.js +1 -1
- package/dist/esm-node/ssr/serverRender/utils.js +1 -1
- package/dist/esm-node/ssr/utils.js +6 -4
- package/dist/esm-node/state/runtime/plugin.js +1 -7
- package/dist/types/common.d.ts +3 -1
- package/dist/types/core/compatible.d.ts +1 -1
- package/dist/types/core/index.d.ts +4 -3
- package/dist/types/core/loader/index.d.ts +1 -2
- package/dist/types/core/loader/useLoader.d.ts +1 -15
- package/dist/types/core/plugin.d.ts +15 -15
- package/dist/types/core/types.d.ts +22 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/runtime/DeferredDataScripts.d.ts +8 -0
- package/dist/types/router/runtime/index.d.ts +4 -2
- package/dist/types/router/runtime/utils.d.ts +23 -4
- package/dist/types/{runtime-context.d.ts → runtimeContext.d.ts} +2 -0
- package/dist/types/ssr/serverRender/renderToStream/buildTemplate.after.d.ts +2 -0
- package/dist/types/ssr/serverRender/renderToString/type.d.ts +1 -0
- package/package.json +14 -15
- package/dist/cjs/ssr/prefetch.worker.js +0 -67
- package/dist/cjs/ssr/serverRender/renderToStream/index.worker.js +0 -64
- package/dist/cjs/ssr/serverRender/renderToString/index.worker.js +0 -58
- package/dist/esm/ssr/prefetch.worker.js +0 -191
- package/dist/esm/ssr/serverRender/renderToStream/index.worker.js +0 -32
- package/dist/esm/ssr/serverRender/renderToString/index.worker.js +0 -167
- package/dist/esm-node/ssr/prefetch.worker.js +0 -46
- package/dist/esm-node/ssr/serverRender/renderToStream/index.worker.js +0 -35
- package/dist/esm-node/ssr/serverRender/renderToString/index.worker.js +0 -29
- package/dist/types/ssr/prefetch.worker.d.ts +0 -13
- package/dist/types/ssr/serverRender/renderToStream/index.worker.d.ts +0 -6
- package/dist/types/ssr/serverRender/renderToString/index.worker.d.ts +0 -6
- /package/dist/esm/{runtime-context.js → runtimeContext.js} +0 -0
- /package/dist/esm-node/{runtime-context.js → runtimeContext.js} +0 -0
- /package/dist/types/core/{app-config.d.ts → appConfig.d.ts} +0 -0
|
@@ -2,7 +2,7 @@ import { buildShellAfterTemplate } from "./buildTemplate.after";
|
|
|
2
2
|
import { buildShellBeforeTemplate } from "./bulidTemplate.before";
|
|
3
3
|
const HTML_SEPARATOR = "<!--<?- html ?>-->";
|
|
4
4
|
const getTemplates = (context, renderLevel) => {
|
|
5
|
-
const { ssrContext } = context;
|
|
5
|
+
const { ssrContext, routerContext } = context;
|
|
6
6
|
const [beforeAppTemplate = "", afterAppHtmlTemplate = ""] = ssrContext.template.split(HTML_SEPARATOR) || [];
|
|
7
7
|
const builtBeforeTemplate = buildShellBeforeTemplate(
|
|
8
8
|
beforeAppTemplate,
|
|
@@ -10,6 +10,7 @@ const getTemplates = (context, renderLevel) => {
|
|
|
10
10
|
);
|
|
11
11
|
const builtAfterTemplate = buildShellAfterTemplate(afterAppHtmlTemplate, {
|
|
12
12
|
ssrContext,
|
|
13
|
+
routerContext,
|
|
13
14
|
renderLevel
|
|
14
15
|
});
|
|
15
16
|
return {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import ReactDomServer from "react-dom/server";
|
|
3
|
-
import
|
|
3
|
+
import { serializeJson } from "@modern-js/utils/serialize";
|
|
4
4
|
import ReactHelmet from "react-helmet";
|
|
5
|
+
import { serializeErrors } from "../../../router/runtime/utils";
|
|
5
6
|
import helmetReplace from "../helmet";
|
|
6
7
|
import {
|
|
7
8
|
RenderLevel
|
|
@@ -13,7 +14,10 @@ import { reduce } from "./reduce";
|
|
|
13
14
|
import * as loadableRenderer from "./loadable";
|
|
14
15
|
import * as styledComponentRenderer from "./styledComponent";
|
|
15
16
|
const buildTemplateData = (context, data, renderLevel) => {
|
|
16
|
-
const { request } = context;
|
|
17
|
+
const { request, enableUnsafeCtx } = context;
|
|
18
|
+
const unsafeContext = {
|
|
19
|
+
headers: request.headers
|
|
20
|
+
};
|
|
17
21
|
return {
|
|
18
22
|
data,
|
|
19
23
|
context: {
|
|
@@ -23,8 +27,7 @@ const buildTemplateData = (context, data, renderLevel) => {
|
|
|
23
27
|
pathname: request.pathname,
|
|
24
28
|
host: request.host,
|
|
25
29
|
url: request.url,
|
|
26
|
-
|
|
27
|
-
cookieMap: request.cookieMap
|
|
30
|
+
...enableUnsafeCtx ? unsafeContext : {}
|
|
28
31
|
}
|
|
29
32
|
},
|
|
30
33
|
renderLevel
|
|
@@ -70,13 +73,18 @@ class Entry {
|
|
|
70
73
|
if ((_c = ssrContext.redirection) == null ? void 0 : _c.url) {
|
|
71
74
|
return "";
|
|
72
75
|
}
|
|
76
|
+
const { routerContext } = context;
|
|
77
|
+
const routerData = routerContext ? {
|
|
78
|
+
loaderData: routerContext.loaderData,
|
|
79
|
+
errors: serializeErrors(routerContext.errors)
|
|
80
|
+
} : void 0;
|
|
73
81
|
let html = "";
|
|
74
82
|
const templateData = buildTemplateData(
|
|
75
83
|
ssrContext,
|
|
76
84
|
prefetchData,
|
|
77
85
|
this.result.renderLevel
|
|
78
86
|
);
|
|
79
|
-
const SSRData = this.getSSRDataScript(templateData);
|
|
87
|
+
const SSRData = this.getSSRDataScript(templateData, routerData);
|
|
80
88
|
for (const fragment of this.fragments) {
|
|
81
89
|
if (fragment.isVariable && fragment.content === "SSRDataScript") {
|
|
82
90
|
html += fragment.getValue(SSRData);
|
|
@@ -133,13 +141,18 @@ class Entry {
|
|
|
133
141
|
}
|
|
134
142
|
return html;
|
|
135
143
|
}
|
|
136
|
-
getSSRDataScript(templateData) {
|
|
144
|
+
getSSRDataScript(templateData, routerData) {
|
|
145
|
+
let ssrDataScripts = `<script>window._SSR_DATA = ${serializeJson(
|
|
146
|
+
templateData
|
|
147
|
+
)}</script>`;
|
|
148
|
+
if (routerData) {
|
|
149
|
+
ssrDataScripts += `
|
|
150
|
+
<script>window._ROUTER_DATA = ${serializeJson(
|
|
151
|
+
routerData
|
|
152
|
+
)}</script>`;
|
|
153
|
+
}
|
|
137
154
|
return {
|
|
138
|
-
SSRDataScript:
|
|
139
|
-
<script>window._SSR_DATA = ${serialize(templateData, {
|
|
140
|
-
isJSON: true
|
|
141
|
-
})}<\/script>
|
|
142
|
-
`
|
|
155
|
+
SSRDataScript: ssrDataScripts
|
|
143
156
|
};
|
|
144
157
|
}
|
|
145
158
|
}
|
|
@@ -36,7 +36,7 @@ const toHtml = (jsx, renderer, next) => {
|
|
|
36
36
|
}
|
|
37
37
|
chunksMap[fileType] += `<script src="${v.url}" ${props.join(
|
|
38
38
|
" "
|
|
39
|
-
)}
|
|
39
|
+
)}></script>`;
|
|
40
40
|
} else if (fileType === "css") {
|
|
41
41
|
chunksMap[fileType] += `<link href="${v.url}" rel="stylesheet" />`;
|
|
42
42
|
}
|
|
@@ -4,7 +4,7 @@ function getLoadableScripts(extractor) {
|
|
|
4
4
|
if (!check(scripts)) {
|
|
5
5
|
return "";
|
|
6
6
|
}
|
|
7
|
-
return scripts.split("
|
|
7
|
+
return scripts.split("</script>").slice(0, 2).map((i) => `${i}</script>`).join("");
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
10
|
getLoadableScripts
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import cookieTool from "cookie";
|
|
1
2
|
const isReact18 = () => process.env.IS_REACT18 === "true";
|
|
2
3
|
const formatServer = (request) => {
|
|
3
4
|
const {
|
|
@@ -7,6 +8,7 @@ const formatServer = (request) => {
|
|
|
7
8
|
} = request.headers || {};
|
|
8
9
|
return {
|
|
9
10
|
cookie,
|
|
11
|
+
cookieMap: cookieTool.parse(cookie || "") || {},
|
|
10
12
|
userAgent,
|
|
11
13
|
referer,
|
|
12
14
|
...request
|
|
@@ -20,15 +22,15 @@ const getQuery = () => window.location.search.substring(1).split("&").reduce((re
|
|
|
20
22
|
return res;
|
|
21
23
|
}, {});
|
|
22
24
|
const formatClient = (request) => {
|
|
23
|
-
var _a
|
|
25
|
+
var _a;
|
|
24
26
|
return {
|
|
25
27
|
params: request.params || {},
|
|
26
28
|
host: request.host || location.host,
|
|
27
29
|
pathname: request.pathname || location.pathname,
|
|
28
30
|
headers: request.headers || {},
|
|
29
|
-
cookieMap:
|
|
30
|
-
cookie:
|
|
31
|
-
userAgent: ((
|
|
31
|
+
cookieMap: cookieTool.parse(document.cookie || "") || {},
|
|
32
|
+
cookie: document.cookie || "",
|
|
33
|
+
userAgent: ((_a = request.headers) == null ? void 0 : _a["user-agent"]) || navigator.userAgent,
|
|
32
34
|
referer: request.referer || document.referrer,
|
|
33
35
|
query: request.query || getQuery(),
|
|
34
36
|
url: location.href
|
|
@@ -42,13 +42,7 @@ const state = (config) => ({
|
|
|
42
42
|
hoc({ App }, next) {
|
|
43
43
|
const getStateApp = (props) => {
|
|
44
44
|
const context = useContext(RuntimeReactContext);
|
|
45
|
-
return /* @__PURE__ */ jsx(Provider, {
|
|
46
|
-
store: context.store,
|
|
47
|
-
config: storeConfig,
|
|
48
|
-
children: /* @__PURE__ */ jsx(App, {
|
|
49
|
-
...props
|
|
50
|
-
})
|
|
51
|
-
});
|
|
45
|
+
return /* @__PURE__ */ jsx(Provider, { store: context.store, config: storeConfig, children: /* @__PURE__ */ jsx(App, { ...props }) });
|
|
52
46
|
};
|
|
53
47
|
return next({
|
|
54
48
|
App: hoistNonReactStatics(getStateApp, App)
|
package/dist/types/common.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export declare const isBrowser: () => boolean;
|
|
|
3
3
|
export interface AppConfig {
|
|
4
4
|
state?: StateConfig | boolean;
|
|
5
5
|
[key: string]: any;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export declare const JSX_SHELL_STREAM_END_MARK = "<!--<?- SHELL_STREAM_END ?>-->";
|
|
8
|
+
export declare const ESCAPED_SHELL_STREAM_END_MARK = "<!--<?- SHELL_STREAM_END ?>-->";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Renderer } from 'react-dom';
|
|
3
3
|
import type { hydrateRoot, createRoot } from 'react-dom/client';
|
|
4
|
-
import { RuntimeContext, TRuntimeContext } from '../
|
|
4
|
+
import { RuntimeContext, TRuntimeContext } from '../runtimeContext';
|
|
5
5
|
import { Plugin } from './plugin';
|
|
6
6
|
export type CreateAppOptions = {
|
|
7
7
|
plugins: Plugin[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { createPlugin, createRuntime, runtime, registerInit } from './plugin';
|
|
2
2
|
export type { Plugin } from './plugin';
|
|
3
|
-
export { defineConfig, getConfig } from './
|
|
3
|
+
export { defineConfig, getConfig } from './appConfig';
|
|
4
4
|
export * from './compatible';
|
|
5
|
-
export type { TRuntimeContext, RuntimeContext } from '../
|
|
6
|
-
export { RuntimeReactContext, ServerRouterContext } from '../
|
|
5
|
+
export type { TRuntimeContext, RuntimeContext } from '../runtimeContext';
|
|
6
|
+
export { RuntimeReactContext, ServerRouterContext } from '../runtimeContext';
|
|
7
7
|
export * from './loader';
|
|
8
|
+
export type { SSRData, SSRContainer } from './types';
|
|
8
9
|
export * from '@modern-js/plugin';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default as useLoader } from './useLoader';
|
|
2
|
-
export type { SSRData, SSRContainer } from './useLoader';
|
|
1
|
+
export { default as useLoader } from './useLoader';
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export interface SSRData {
|
|
3
|
-
loadersData: Record<string, LoaderResult | undefined>;
|
|
4
|
-
initialData?: Record<string, unknown>;
|
|
5
|
-
storeState?: any;
|
|
6
|
-
}
|
|
7
|
-
export interface SSRContainer {
|
|
8
|
-
data?: SSRData;
|
|
9
|
-
}
|
|
10
|
-
declare global {
|
|
11
|
-
interface Window {
|
|
12
|
-
_SSR_DATA?: SSRContainer;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
type LoaderFn<P = any, T = any> = (context: any, params: P) => Promise<T>;
|
|
15
2
|
export interface LoaderOptions<Params = any, TData = any, TError extends Error = any> {
|
|
16
3
|
/**
|
|
17
4
|
* Revoke when loader excuted successfully.
|
|
@@ -44,7 +31,6 @@ export interface LoaderOptions<Params = any, TData = any, TError extends Error =
|
|
|
44
31
|
|
|
45
32
|
static?: boolean;
|
|
46
33
|
}
|
|
47
|
-
type LoaderFn<P = any, T = any> = (context: any, params: P) => Promise<T>;
|
|
48
34
|
declare const useLoader: <TData = any, Params = any, E = any>(loaderFn: LoaderFn<Params, TData>, options?: LoaderOptions<Params, any, any>) => {
|
|
49
35
|
reload: (params?: Params | undefined) => Promise<any> | undefined;
|
|
50
36
|
loading: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { Setup, ToThreads, CommonAPI, PluginOptions } from '@modern-js/plugin';
|
|
3
|
-
import type { RuntimeContext, TRuntimeContext } from '../
|
|
3
|
+
import type { RuntimeContext, TRuntimeContext } from '../runtimeContext';
|
|
4
4
|
export interface AppProps {}
|
|
5
5
|
declare const runtimeHooks: {
|
|
6
6
|
hoc: import("@modern-js/plugin").Pipeline<{
|
|
@@ -13,13 +13,13 @@ declare const runtimeHooks: {
|
|
|
13
13
|
}, JSX.Element>;
|
|
14
14
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
15
15
|
App: React.ComponentType<any>;
|
|
16
|
-
readonly context
|
|
16
|
+
readonly context: RuntimeContext;
|
|
17
17
|
ModernRender: (App: React.ReactElement) => void;
|
|
18
18
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
19
19
|
}, void>;
|
|
20
20
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
21
21
|
App: React.ComponentType<any>;
|
|
22
|
-
readonly context
|
|
22
|
+
readonly context: RuntimeContext;
|
|
23
23
|
}, string>;
|
|
24
24
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
25
25
|
context: RuntimeContext;
|
|
@@ -52,13 +52,13 @@ export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
|
|
|
52
52
|
}, JSX.Element>;
|
|
53
53
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
54
54
|
App: React.ComponentType<any>;
|
|
55
|
-
readonly context
|
|
55
|
+
readonly context: RuntimeContext;
|
|
56
56
|
ModernRender: (App: React.ReactElement) => void;
|
|
57
57
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
58
58
|
}, void>;
|
|
59
59
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
60
60
|
App: React.ComponentType<any>;
|
|
61
|
-
readonly context
|
|
61
|
+
readonly context: RuntimeContext;
|
|
62
62
|
}, string>;
|
|
63
63
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
64
64
|
context: RuntimeContext;
|
|
@@ -84,13 +84,13 @@ export declare const runtime: import("@modern-js/plugin").Manager<{
|
|
|
84
84
|
}, JSX.Element>;
|
|
85
85
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
86
86
|
App: React.ComponentType<any>;
|
|
87
|
-
readonly context
|
|
87
|
+
readonly context: RuntimeContext;
|
|
88
88
|
ModernRender: (App: React.ReactElement) => void;
|
|
89
89
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
90
90
|
}, void>;
|
|
91
91
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
92
92
|
App: React.ComponentType<any>;
|
|
93
|
-
readonly context
|
|
93
|
+
readonly context: RuntimeContext;
|
|
94
94
|
}, string>;
|
|
95
95
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
96
96
|
context: RuntimeContext;
|
|
@@ -111,13 +111,13 @@ export declare const createPlugin: (setup?: Setup<{
|
|
|
111
111
|
}, JSX.Element>;
|
|
112
112
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
113
113
|
App: React.ComponentType<any>;
|
|
114
|
-
readonly context
|
|
114
|
+
readonly context: RuntimeContext;
|
|
115
115
|
ModernRender: (App: React.ReactElement) => void;
|
|
116
116
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
117
117
|
}, void>;
|
|
118
118
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
119
119
|
App: React.ComponentType<any>;
|
|
120
|
-
readonly context
|
|
120
|
+
readonly context: RuntimeContext;
|
|
121
121
|
}, string>;
|
|
122
122
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
123
123
|
context: RuntimeContext;
|
|
@@ -137,13 +137,13 @@ export declare const createPlugin: (setup?: Setup<{
|
|
|
137
137
|
}, JSX.Element>;
|
|
138
138
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
139
139
|
App: React.ComponentType<any>;
|
|
140
|
-
readonly context
|
|
140
|
+
readonly context: RuntimeContext;
|
|
141
141
|
ModernRender: (App: React.ReactElement) => void;
|
|
142
142
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
143
143
|
}, void>;
|
|
144
144
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
145
145
|
App: React.ComponentType<any>;
|
|
146
|
-
readonly context
|
|
146
|
+
readonly context: RuntimeContext;
|
|
147
147
|
}, string>;
|
|
148
148
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
149
149
|
context: RuntimeContext;
|
|
@@ -163,13 +163,13 @@ export declare const createPlugin: (setup?: Setup<{
|
|
|
163
163
|
}, JSX.Element>;
|
|
164
164
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
165
165
|
App: React.ComponentType<any>;
|
|
166
|
-
readonly context
|
|
166
|
+
readonly context: RuntimeContext;
|
|
167
167
|
ModernRender: (App: React.ReactElement) => void;
|
|
168
168
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
169
169
|
}, void>;
|
|
170
170
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
171
171
|
App: React.ComponentType<any>;
|
|
172
|
-
readonly context
|
|
172
|
+
readonly context: RuntimeContext;
|
|
173
173
|
}, string>;
|
|
174
174
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
175
175
|
context: RuntimeContext;
|
|
@@ -189,13 +189,13 @@ export declare const createPlugin: (setup?: Setup<{
|
|
|
189
189
|
}, JSX.Element>;
|
|
190
190
|
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
191
191
|
App: React.ComponentType<any>;
|
|
192
|
-
readonly context
|
|
192
|
+
readonly context: RuntimeContext;
|
|
193
193
|
ModernRender: (App: React.ReactElement) => void;
|
|
194
194
|
ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
|
|
195
195
|
}, void>;
|
|
196
196
|
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
197
197
|
App: React.ComponentType<any>;
|
|
198
|
-
readonly context
|
|
198
|
+
readonly context: RuntimeContext;
|
|
199
199
|
}, string>;
|
|
200
200
|
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
201
201
|
context: RuntimeContext;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LoaderResult } from './loader/loaderManager';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
_SSR_DATA?: SSRContainer;
|
|
5
|
+
_ROUTER_DATA?: RouterSSRData;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface SSRData {
|
|
9
|
+
loadersData: Record<string, LoaderResult | undefined>;
|
|
10
|
+
initialData?: Record<string, unknown>;
|
|
11
|
+
storeState?: any;
|
|
12
|
+
}
|
|
13
|
+
export interface RouteData {
|
|
14
|
+
[routeId: string]: any;
|
|
15
|
+
}
|
|
16
|
+
export interface RouterSSRData {
|
|
17
|
+
loaderData: RouteData;
|
|
18
|
+
errors: RouteData | null;
|
|
19
|
+
}
|
|
20
|
+
export interface SSRContainer {
|
|
21
|
+
data?: SSRData;
|
|
22
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RouterConfig } from './router';
|
|
|
3
3
|
export type { Plugin } from './core';
|
|
4
4
|
export type { AppConfig } from './common';
|
|
5
5
|
export { isBrowser } from './common';
|
|
6
|
-
export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, TRuntimeContext } from './
|
|
6
|
+
export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, TRuntimeContext } from './runtimeContext';
|
|
7
7
|
export type { RuntimeUserConfig } from './config';
|
|
8
8
|
export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, defineConfig, registerInit, useRuntimeContext } from './core';
|
|
9
9
|
export { StateConfig, RouterConfig };
|
|
@@ -3,5 +3,7 @@ import type { SingleRouteConfig, RouterConfig } from './types';
|
|
|
3
3
|
export type { SingleRouteConfig, RouterConfig };
|
|
4
4
|
export default routerPlugin;
|
|
5
5
|
export { modifyRoutes } from './plugin';
|
|
6
|
-
export * from '
|
|
7
|
-
export
|
|
6
|
+
export * from './withRouter';
|
|
7
|
+
export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, FetcherWithComponents, 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 'react-router-dom';
|
|
8
|
+
export { createBrowserRouter, createHashRouter, createMemoryRouter, RouterProvider, BrowserRouter, HashRouter, MemoryRouter, Router, Await, Form, Link, NavLink, 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, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, createRoutesFromChildren, createRoutesFromElements, createSearchParams, generatePath, isRouteErrorResponse, matchPath, matchRoutes, renderMatches, resolvePath } from 'react-router-dom';
|
|
9
|
+
export { defer, json, redirect } from '@modern-js/utils/remix-router';
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type NestedRoute, type PageRoute, type SSRMode } from '@modern-js/types';
|
|
3
|
+
import { type Router, type StaticHandlerContext } from '@modern-js/utils/remix-router';
|
|
3
4
|
import { RouterConfig } from './types';
|
|
4
|
-
export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[],
|
|
5
|
-
|
|
5
|
+
export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[], {
|
|
6
|
+
globalApp,
|
|
7
|
+
ssrMode
|
|
8
|
+
}: {
|
|
9
|
+
globalApp?: React.ComponentType<any>;
|
|
10
|
+
ssrMode?: SSRMode;
|
|
11
|
+
}): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
|
|
12
|
+
export declare function renderRoutes(routesConfig: RouterConfig['routesConfig'], ssrMode?: SSRMode): React.ReactElement<any, string | React.JSXElementConstructor<any>>[] | null;
|
|
6
13
|
export declare function getLocation(serverContext: any): string;
|
|
7
14
|
export declare const urlJoin: (...parts: string[]) => string;
|
|
8
|
-
export declare function standardSlash(str: string): string;
|
|
15
|
+
export declare function standardSlash(str: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* forked from https://github.com/remix-run/remix/blob/main/packages/remix-server-runtime/errors.ts
|
|
18
|
+
* license at https://github.com/remix-run/remix/blob/main/LICENSE.md
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export declare function serializeErrors(errors: StaticHandlerContext['errors']): StaticHandlerContext['errors'];
|
|
22
|
+
/**
|
|
23
|
+
* forked from https://github.com/remix-run/remix/blob/main/packages/remix-react/errors.ts
|
|
24
|
+
* license at https://github.com/remix-run/remix/blob/main/LICENSE.md
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export declare function deserializeErrors(errors: Router['state']['errors']): Router['state']['errors'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Store } from '@modern-js-reduck/store';
|
|
3
|
+
import type { StaticHandlerContext } from '@modern-js/utils/remix-router';
|
|
3
4
|
import { createLoaderManager } from './core/loader/loaderManager';
|
|
4
5
|
import { runtime } from './core/plugin';
|
|
5
6
|
import { SSRServerContext } from './ssr/serverRender/types';
|
|
@@ -9,6 +10,7 @@ export interface BaseRuntimeContext {
|
|
|
9
10
|
runner: ReturnType<typeof runtime.init>;
|
|
10
11
|
ssrContext?: SSRServerContext;
|
|
11
12
|
store?: Store;
|
|
13
|
+
routerContext?: StaticHandlerContext;
|
|
12
14
|
}
|
|
13
15
|
export interface RuntimeContext extends BaseRuntimeContext {
|
|
14
16
|
[key: string]: any;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { StaticHandlerContext } from '@modern-js/utils/remix-router';
|
|
1
2
|
import { RenderLevel, SSRServerContext } from '../types';
|
|
2
3
|
type BuildShellAfterTemplateOptions = {
|
|
3
4
|
ssrContext: SSRServerContext;
|
|
5
|
+
routerContext: StaticHandlerContext;
|
|
4
6
|
renderLevel: RenderLevel;
|
|
5
7
|
};
|
|
6
8
|
export declare function buildShellAfterTemplate(afterAppTemplate: string, options: BuildShellAfterTemplateOptions): string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.7.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14.17.6"
|
|
17
17
|
},
|
|
@@ -133,6 +133,7 @@
|
|
|
133
133
|
"@babel/core": "^7.18.0",
|
|
134
134
|
"@babel/runtime": "^7.18.0",
|
|
135
135
|
"@babel/types": "^7.18.0",
|
|
136
|
+
"cookie": "0.5.0",
|
|
136
137
|
"@loadable/babel-plugin": "^5.13.2",
|
|
137
138
|
"@loadable/component": "^5.15.0",
|
|
138
139
|
"@loadable/server": "^5.15.1",
|
|
@@ -143,31 +144,30 @@
|
|
|
143
144
|
"@modern-js-reduck/plugin-immutable": "^1.1.4",
|
|
144
145
|
"@modern-js-reduck/react": "^1.1.4",
|
|
145
146
|
"@modern-js-reduck/store": "^1.1.4",
|
|
146
|
-
"@remix-run/node": "^1.
|
|
147
|
-
"@remix-run/router": "^1.2.0",
|
|
147
|
+
"@remix-run/node": "^1.12.0",
|
|
148
148
|
"@types/loadable__component": "^5.13.4",
|
|
149
149
|
"@types/react-helmet": "^6.1.2",
|
|
150
150
|
"@types/redux-logger": "^3.0.9",
|
|
151
151
|
"@types/styled-components": "^5.1.14",
|
|
152
|
+
"esbuild": "0.15.7",
|
|
152
153
|
"hoist-non-react-statics": "^3.3.2",
|
|
153
154
|
"invariant": "^2.2.4",
|
|
154
155
|
"react-helmet": "^6.1.0",
|
|
155
156
|
"react-is": "^18",
|
|
156
|
-
"react-router-dom": "^6.
|
|
157
|
+
"react-router-dom": "^6.8.1",
|
|
157
158
|
"react-side-effect": "^2.1.1",
|
|
158
159
|
"redux-logger": "^3.0.6",
|
|
159
|
-
"serialize-javascript": "^6.0.0",
|
|
160
160
|
"styled-components": "^5.3.1",
|
|
161
|
-
"
|
|
162
|
-
"@modern-js/
|
|
163
|
-
"@modern-js/
|
|
164
|
-
"@modern-js/utils": "2.5.0"
|
|
161
|
+
"@modern-js/plugin": "2.7.0",
|
|
162
|
+
"@modern-js/types": "2.7.0",
|
|
163
|
+
"@modern-js/utils": "2.7.0"
|
|
165
164
|
},
|
|
166
165
|
"peerDependencies": {
|
|
167
166
|
"react": ">=17",
|
|
168
167
|
"react-dom": ">=17"
|
|
169
168
|
},
|
|
170
169
|
"devDependencies": {
|
|
170
|
+
"@types/cookie": "0.5.1",
|
|
171
171
|
"@remix-run/web-fetch": "^4.1.3",
|
|
172
172
|
"@testing-library/react": "^13.4.0",
|
|
173
173
|
"@testing-library/react-hooks": "^8.0.1",
|
|
@@ -176,17 +176,16 @@
|
|
|
176
176
|
"@types/loadable__webpack-plugin": "^5.7.3",
|
|
177
177
|
"@types/node": "^14",
|
|
178
178
|
"@types/react-side-effect": "^1.1.1",
|
|
179
|
-
"@types/serialize-javascript": "^5.0.1",
|
|
180
179
|
"jest": "^27",
|
|
181
180
|
"react": "^18",
|
|
182
181
|
"react-dom": "^18",
|
|
183
182
|
"ts-jest": "^27.0.4",
|
|
184
183
|
"typescript": "^4",
|
|
185
|
-
"@modern-js/
|
|
186
|
-
"@modern-js/core": "2.
|
|
187
|
-
"@modern-js/
|
|
188
|
-
"@scripts/
|
|
189
|
-
"@scripts/
|
|
184
|
+
"@modern-js/core": "2.7.0",
|
|
185
|
+
"@modern-js/server-core": "2.7.0",
|
|
186
|
+
"@modern-js/app-tools": "2.7.0",
|
|
187
|
+
"@scripts/build": "2.7.0",
|
|
188
|
+
"@scripts/jest-config": "2.7.0"
|
|
190
189
|
},
|
|
191
190
|
"sideEffects": false,
|
|
192
191
|
"modernConfig": {},
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var prefetch_worker_exports = {};
|
|
19
|
-
__export(prefetch_worker_exports, {
|
|
20
|
-
default: () => prefetch_worker_default
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(prefetch_worker_exports);
|
|
23
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
-
var import_server = require("react-dom/server");
|
|
25
|
-
var import_server2 = require("@loadable/server");
|
|
26
|
-
const prefetch = async (App, context) => {
|
|
27
|
-
var _a;
|
|
28
|
-
const { ssrContext } = context;
|
|
29
|
-
const { loadableStats } = ssrContext;
|
|
30
|
-
if (loadableStats) {
|
|
31
|
-
const extractor = new import_server2.ChunkExtractor({
|
|
32
|
-
stats: loadableStats,
|
|
33
|
-
entrypoints: [ssrContext.entryName].filter(Boolean)
|
|
34
|
-
});
|
|
35
|
-
(0, import_server.renderToStaticMarkup)(extractor.collectChunks(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
36
|
-
context
|
|
37
|
-
})));
|
|
38
|
-
} else {
|
|
39
|
-
(0, import_server.renderToStaticMarkup)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
40
|
-
context
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
if (!context.loaderManager.hasPendingLoaders()) {
|
|
44
|
-
return {
|
|
45
|
-
initialData: context.initialData,
|
|
46
|
-
i18nData: context.__i18nData__
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const loadersData = await context.loaderManager.awaitPendingLoaders();
|
|
50
|
-
Object.keys(loadersData).forEach((id) => {
|
|
51
|
-
const data = loadersData[id];
|
|
52
|
-
if (data._error) {
|
|
53
|
-
ssrContext.logger.error("App Prefetch Loader", data._error);
|
|
54
|
-
ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
|
|
55
|
-
delete data._error;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
loadersData,
|
|
60
|
-
initialData: context.initialData,
|
|
61
|
-
i18nData: context.__i18nData__,
|
|
62
|
-
storeState: (_a = context == null ? void 0 : context.store) == null ? void 0 : _a.getState()
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
var prefetch_worker_default = prefetch;
|
|
66
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
-
0 && (module.exports = {});
|