@modern-js/runtime 2.63.7 → 2.64.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/dist/cjs/core/browser/index.js +6 -4
- package/dist/cjs/core/compat/hooks.js +80 -0
- package/dist/cjs/core/{plugin/runner.js → compat/index.js} +19 -19
- package/dist/cjs/core/compatible.js +15 -11
- package/dist/cjs/core/context/index.js +12 -2
- package/dist/cjs/core/context/runtime.js +1 -2
- package/dist/cjs/core/index.js +1 -4
- package/dist/cjs/core/plugin/base.js +0 -35
- package/dist/cjs/core/plugin/index.js +17 -17
- package/dist/cjs/core/plugin/types.js +16 -0
- package/dist/cjs/core/react/index.js +3 -3
- package/dist/cjs/core/server/requestHandler.js +4 -4
- package/dist/cjs/router/runtime/hooks.js +7 -7
- package/dist/cjs/router/runtime/plugin.js +107 -108
- package/dist/cjs/router/runtime/plugin.node.js +89 -91
- package/dist/esm/core/browser/index.js +9 -7
- package/dist/esm/core/compat/hooks.js +88 -0
- package/dist/esm/core/compat/index.js +20 -0
- package/dist/esm/core/compatible.js +17 -13
- package/dist/esm/core/context/index.js +9 -1
- package/dist/esm/core/context/runtime.js +2 -3
- package/dist/esm/core/index.js +1 -3
- package/dist/esm/core/plugin/base.js +0 -28
- package/dist/esm/core/plugin/index.js +14 -17
- package/dist/esm/core/plugin/types.js +0 -0
- package/dist/esm/core/react/index.js +4 -4
- package/dist/esm/core/server/requestHandler.js +6 -6
- package/dist/esm/router/runtime/hooks.js +5 -5
- package/dist/esm/router/runtime/plugin.js +114 -115
- package/dist/esm/router/runtime/plugin.node.js +112 -111
- package/dist/esm-node/core/browser/index.js +7 -5
- package/dist/esm-node/core/compat/hooks.js +54 -0
- package/dist/esm-node/core/compat/index.js +18 -0
- package/dist/esm-node/core/compatible.js +16 -12
- package/dist/esm-node/core/context/index.js +9 -1
- package/dist/esm-node/core/context/runtime.js +1 -2
- package/dist/esm-node/core/index.js +1 -3
- package/dist/esm-node/core/plugin/base.js +0 -24
- package/dist/esm-node/core/plugin/index.js +16 -14
- package/dist/esm-node/core/plugin/types.js +0 -0
- package/dist/esm-node/core/react/index.js +4 -4
- package/dist/esm-node/core/server/requestHandler.js +5 -5
- package/dist/esm-node/router/runtime/hooks.js +5 -5
- package/dist/esm-node/router/runtime/plugin.js +108 -109
- package/dist/esm-node/router/runtime/plugin.node.js +90 -92
- package/dist/types/core/browser/hydrate.d.ts +1 -1
- package/dist/types/core/compat/hooks.d.ts +4 -0
- package/dist/types/core/compat/index.d.ts +2 -0
- package/dist/types/core/compatible.d.ts +7 -6
- package/dist/types/core/context/index.d.ts +7 -2
- package/dist/types/core/context/runtime.d.ts +1 -3
- package/dist/types/core/index.d.ts +1 -2
- package/dist/types/core/plugin/base.d.ts +9 -33
- package/dist/types/core/plugin/index.d.ts +19 -12
- package/dist/types/core/plugin/types.d.ts +10 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/runtime/hooks.d.ts +7 -3
- package/dist/types/router/runtime/index.d.ts +1 -0
- package/dist/types/router/runtime/plugin.d.ts +5 -2
- package/dist/types/router/runtime/plugin.node.d.ts +5 -2
- package/package.json +10 -10
- package/dist/esm/core/plugin/runner.js +0 -17
- package/dist/esm-node/core/plugin/runner.js +0 -17
- package/dist/types/core/plugin/runner.d.ts +0 -9
|
@@ -5,7 +5,7 @@ import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
|
5
5
|
import { useContext, useMemo } from "react";
|
|
6
6
|
import { RuntimeReactContext } from "../../core";
|
|
7
7
|
import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
|
|
8
|
-
import { modifyRoutes as modifyRoutesHook } from "./hooks";
|
|
8
|
+
import { modifyRoutes as modifyRoutesHook, onBeforeCreateRoutes as onBeforeCreateRoutesHook } from "./hooks";
|
|
9
9
|
import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
|
|
10
10
|
let finalRouteConfig = {
|
|
11
11
|
routes: []
|
|
@@ -23,121 +23,120 @@ function modifyRoutes(modifyFunction) {
|
|
|
23
23
|
const routerPlugin = (userConfig = {}) => {
|
|
24
24
|
return {
|
|
25
25
|
name: "@modern-js/plugin-router",
|
|
26
|
-
|
|
27
|
-
modifyRoutes: modifyRoutesHook
|
|
26
|
+
registryHooks: {
|
|
27
|
+
modifyRoutes: modifyRoutesHook,
|
|
28
|
+
onBeforeCreateRoutes: onBeforeCreateRoutesHook
|
|
28
29
|
},
|
|
29
30
|
setup: (api) => {
|
|
30
31
|
let routes = [];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
window.location.reload();
|
|
42
|
-
}
|
|
32
|
+
api.onBeforeRender((context) => {
|
|
33
|
+
if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
|
|
34
|
+
var _ssrContext_request;
|
|
35
|
+
const { ssrContext } = context;
|
|
36
|
+
const currentPathname = normalizePathname(window.location.pathname);
|
|
37
|
+
const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
|
|
38
|
+
if (initialPathname && initialPathname !== currentPathname) {
|
|
39
|
+
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
40
|
+
console.error(errorMsg);
|
|
41
|
+
window.location.reload();
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
wrapRoot: (App) => {
|
|
56
|
-
const pluginConfig = api.useRuntimeConfigContext();
|
|
57
|
-
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes, future } = merge(pluginConfig.router || {}, userConfig);
|
|
58
|
-
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
59
|
-
finalRouteConfig = {
|
|
60
|
-
routes: getGlobalRoutes(),
|
|
61
|
-
globalApp: getGlobalLayoutApp(),
|
|
62
|
-
...routesConfig
|
|
63
|
-
};
|
|
64
|
-
if (!finalRouteConfig.routes && !createRoutes) {
|
|
65
|
-
return App;
|
|
43
|
+
}
|
|
44
|
+
context.router = {
|
|
45
|
+
useMatches,
|
|
46
|
+
useLocation,
|
|
47
|
+
useHref
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(context, "routes", {
|
|
50
|
+
get() {
|
|
51
|
+
return routes;
|
|
66
52
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
hydrationData
|
|
93
|
-
});
|
|
94
|
-
const originSubscribe = router.subscribe;
|
|
95
|
-
router.subscribe = (listener) => {
|
|
96
|
-
const wrapedListener = (...args) => {
|
|
97
|
-
const blockRoute = getBlockNavState ? getBlockNavState() : false;
|
|
98
|
-
if (blockRoute) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
return listener(...args);
|
|
102
|
-
};
|
|
103
|
-
return originSubscribe(wrapedListener);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
api.wrapRoot((App) => {
|
|
56
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
57
|
+
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes, future } = merge(pluginConfig.router || {}, userConfig);
|
|
58
|
+
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
59
|
+
finalRouteConfig = {
|
|
60
|
+
routes: getGlobalRoutes(),
|
|
61
|
+
globalApp: getGlobalLayoutApp(),
|
|
62
|
+
...routesConfig
|
|
63
|
+
};
|
|
64
|
+
if (!finalRouteConfig.routes && !createRoutes) {
|
|
65
|
+
return App;
|
|
66
|
+
}
|
|
67
|
+
const getRouteApp = () => {
|
|
68
|
+
const useCreateRouter = (props) => {
|
|
69
|
+
const runtimeContext = useContext(RuntimeReactContext);
|
|
70
|
+
const baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
|
71
|
+
const _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
|
|
72
|
+
let hydrationData = window._ROUTER_DATA;
|
|
73
|
+
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
74
|
+
return useMemo(() => {
|
|
75
|
+
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
76
|
+
hydrationData = {
|
|
77
|
+
...hydrationData,
|
|
78
|
+
errors: deserializeErrors(hydrationData.errors)
|
|
104
79
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
finalRouteConfig,
|
|
108
|
-
props
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
80
|
+
}
|
|
81
|
+
routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
82
|
+
routesConfig: finalRouteConfig,
|
|
83
|
+
props
|
|
84
|
+
}));
|
|
85
|
+
const hooks = api.getHooks();
|
|
86
|
+
routes = hooks.modifyRoutes.call(routes);
|
|
87
|
+
const router = supportHtml5History ? createBrowserRouter(routes, {
|
|
88
|
+
basename: _basename,
|
|
89
|
+
hydrationData
|
|
90
|
+
}) : createHashRouter(routes, {
|
|
91
|
+
basename: _basename,
|
|
92
|
+
hydrationData
|
|
93
|
+
});
|
|
94
|
+
const originSubscribe = router.subscribe;
|
|
95
|
+
router.subscribe = (listener) => {
|
|
96
|
+
const wrapedListener = (...args) => {
|
|
97
|
+
const blockRoute = getBlockNavState ? getBlockNavState() : false;
|
|
98
|
+
if (blockRoute) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
return listener(...args);
|
|
102
|
+
};
|
|
103
|
+
return originSubscribe(wrapedListener);
|
|
104
|
+
};
|
|
105
|
+
return router;
|
|
106
|
+
}, [
|
|
107
|
+
finalRouteConfig,
|
|
108
|
+
props,
|
|
109
|
+
_basename,
|
|
110
|
+
hydrationData,
|
|
111
|
+
getBlockNavState
|
|
112
|
+
]);
|
|
137
113
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
114
|
+
const Null = () => null;
|
|
115
|
+
return (props) => {
|
|
116
|
+
beforeCreateRouter = false;
|
|
117
|
+
const router = useCreateRouter(props);
|
|
118
|
+
const routerWrapper = (
|
|
119
|
+
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
120
|
+
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
121
|
+
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
122
|
+
/* @__PURE__ */ _jsxs(_Fragment, {
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ _jsx(RouterProvider, {
|
|
125
|
+
router,
|
|
126
|
+
future
|
|
127
|
+
}),
|
|
128
|
+
/* @__PURE__ */ _jsx(Null, {}),
|
|
129
|
+
/* @__PURE__ */ _jsx(Null, {})
|
|
130
|
+
]
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
return App ? /* @__PURE__ */ _jsx(App, {
|
|
134
|
+
children: routerWrapper
|
|
135
|
+
}) : routerWrapper;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
return getRouteApp();
|
|
139
|
+
});
|
|
141
140
|
}
|
|
142
141
|
};
|
|
143
142
|
};
|
|
@@ -11,7 +11,7 @@ import { JSX_SHELL_STREAM_END_MARK } from "../../common";
|
|
|
11
11
|
import { RuntimeReactContext } from "../../core";
|
|
12
12
|
import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
|
|
13
13
|
import DeferredDataScripts from "./DeferredDataScripts.node";
|
|
14
|
-
import {
|
|
14
|
+
import { modifyRoutes as modifyRoutesHook, onBeforeCreateRoutes as onBeforeCreateRoutesHook } from "./hooks";
|
|
15
15
|
import { renderRoutes, urlJoin } from "./utils";
|
|
16
16
|
function createRemixReuqest(request) {
|
|
17
17
|
const method = "GET";
|
|
@@ -26,102 +26,100 @@ function createRemixReuqest(request) {
|
|
|
26
26
|
const routerPlugin = (userConfig = {}) => {
|
|
27
27
|
return {
|
|
28
28
|
name: "@modern-js/plugin-router",
|
|
29
|
-
|
|
29
|
+
registryHooks: {
|
|
30
30
|
modifyRoutes: modifyRoutesHook,
|
|
31
|
-
|
|
31
|
+
onBeforeCreateRoutes: onBeforeCreateRoutesHook
|
|
32
32
|
},
|
|
33
33
|
setup: (api) => {
|
|
34
34
|
let finalRouteConfig = {};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return interrupt(routerContext);
|
|
77
|
-
}
|
|
78
|
-
const errors = Object.values(routerContext.errors || {});
|
|
79
|
-
if (
|
|
80
|
-
// TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
|
|
81
|
-
errors.length > 0 && loaderFailureMode === "clientRender"
|
|
82
|
-
) {
|
|
83
|
-
routerContext.statusCode = 200;
|
|
84
|
-
throw errors[0];
|
|
85
|
-
}
|
|
86
|
-
const router = createStaticRouter(routes, routerContext);
|
|
87
|
-
context.routerContext = routerContext;
|
|
88
|
-
context.remixRouter = router;
|
|
89
|
-
context.routes = routes;
|
|
90
|
-
},
|
|
91
|
-
wrapRoot: (App) => {
|
|
92
|
-
if (!finalRouteConfig) {
|
|
93
|
-
return App;
|
|
94
|
-
}
|
|
95
|
-
const getRouteApp = () => {
|
|
96
|
-
return () => {
|
|
97
|
-
const context = useContext(RuntimeReactContext);
|
|
98
|
-
const { remixRouter, routerContext, ssrContext } = context;
|
|
99
|
-
const { nonce, mode, useJsonScript } = ssrContext;
|
|
100
|
-
const routerWrapper = /* @__PURE__ */ _jsxs(_Fragment, {
|
|
101
|
-
children: [
|
|
102
|
-
/* @__PURE__ */ _jsx(StaticRouterProvider, {
|
|
103
|
-
router: remixRouter,
|
|
104
|
-
context: routerContext,
|
|
105
|
-
hydrate: false
|
|
106
|
-
}),
|
|
107
|
-
mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
|
|
108
|
-
// So we can inject it only when streaming ssr
|
|
109
|
-
/* @__PURE__ */ _jsx(DeferredDataScripts, {
|
|
110
|
-
nonce,
|
|
111
|
-
context: routerContext,
|
|
112
|
-
useJsonScript
|
|
113
|
-
}),
|
|
114
|
-
mode === "stream" && JSX_SHELL_STREAM_END_MARK
|
|
115
|
-
]
|
|
116
|
-
});
|
|
117
|
-
return App ? /* @__PURE__ */ _jsx(App, {
|
|
118
|
-
children: routerWrapper
|
|
119
|
-
}) : routerWrapper;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
return getRouteApp();
|
|
35
|
+
api.onBeforeRender(async (context, interrupt) => {
|
|
36
|
+
var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1;
|
|
37
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
38
|
+
const { basename = "", routesConfig, createRoutes } = merge(pluginConfig.router || {}, userConfig);
|
|
39
|
+
finalRouteConfig = {
|
|
40
|
+
routes: getGlobalRoutes(),
|
|
41
|
+
globalApp: getGlobalLayoutApp(),
|
|
42
|
+
...routesConfig
|
|
43
|
+
};
|
|
44
|
+
if (!finalRouteConfig.routes && !createRoutes) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { request, mode: ssrMode, nonce, loaderFailureMode = "errorBoundary" } = context.ssrContext;
|
|
48
|
+
const { baseUrl } = request;
|
|
49
|
+
const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
50
|
+
const { reporter } = context.ssrContext;
|
|
51
|
+
const requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
|
|
52
|
+
requestContext.set(reporterCtx, reporter);
|
|
53
|
+
const hooks = api.getHooks();
|
|
54
|
+
await hooks.onBeforeCreateRoutes.call(context);
|
|
55
|
+
let routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
56
|
+
routesConfig: finalRouteConfig,
|
|
57
|
+
ssrMode,
|
|
58
|
+
props: {
|
|
59
|
+
nonce
|
|
60
|
+
},
|
|
61
|
+
reporter
|
|
62
|
+
}));
|
|
63
|
+
routes = hooks.modifyRoutes.call(routes);
|
|
64
|
+
const { query } = createStaticHandler(routes, {
|
|
65
|
+
basename: _basename
|
|
66
|
+
});
|
|
67
|
+
const remixRequest = createRemixReuqest(context.ssrContext.request.raw);
|
|
68
|
+
const end = time();
|
|
69
|
+
const routerContext = await query(remixRequest, {
|
|
70
|
+
requestContext
|
|
71
|
+
});
|
|
72
|
+
const cost = end();
|
|
73
|
+
(_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : (_context_ssrContext_onTiming = _context_ssrContext1.onTiming) === null || _context_ssrContext_onTiming === void 0 ? void 0 : _context_ssrContext_onTiming.call(_context_ssrContext1, LOADER_REPORTER_NAME, cost);
|
|
74
|
+
if (routerContext instanceof Response) {
|
|
75
|
+
return interrupt(routerContext);
|
|
123
76
|
}
|
|
124
|
-
|
|
77
|
+
const errors = Object.values(routerContext.errors || {});
|
|
78
|
+
if (
|
|
79
|
+
// TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
|
|
80
|
+
errors.length > 0 && loaderFailureMode === "clientRender"
|
|
81
|
+
) {
|
|
82
|
+
routerContext.statusCode = 200;
|
|
83
|
+
throw errors[0];
|
|
84
|
+
}
|
|
85
|
+
const router = createStaticRouter(routes, routerContext);
|
|
86
|
+
context.routerContext = routerContext;
|
|
87
|
+
context.remixRouter = router;
|
|
88
|
+
context.routes = routes;
|
|
89
|
+
});
|
|
90
|
+
api.wrapRoot((App) => {
|
|
91
|
+
if (!finalRouteConfig) {
|
|
92
|
+
return App;
|
|
93
|
+
}
|
|
94
|
+
const getRouteApp = () => {
|
|
95
|
+
return () => {
|
|
96
|
+
const context = useContext(RuntimeReactContext);
|
|
97
|
+
const { remixRouter, routerContext, ssrContext } = context;
|
|
98
|
+
const { nonce, mode, useJsonScript } = ssrContext;
|
|
99
|
+
const routerWrapper = /* @__PURE__ */ _jsxs(_Fragment, {
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ _jsx(StaticRouterProvider, {
|
|
102
|
+
router: remixRouter,
|
|
103
|
+
context: routerContext,
|
|
104
|
+
hydrate: false
|
|
105
|
+
}),
|
|
106
|
+
mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
|
|
107
|
+
// So we can inject it only when streaming ssr
|
|
108
|
+
/* @__PURE__ */ _jsx(DeferredDataScripts, {
|
|
109
|
+
nonce,
|
|
110
|
+
context: routerContext,
|
|
111
|
+
useJsonScript
|
|
112
|
+
}),
|
|
113
|
+
mode === "stream" && JSX_SHELL_STREAM_END_MARK
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
return App ? /* @__PURE__ */ _jsx(App, {
|
|
117
|
+
children: routerWrapper
|
|
118
|
+
}) : routerWrapper;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
return getRouteApp();
|
|
122
|
+
});
|
|
125
123
|
}
|
|
126
124
|
};
|
|
127
125
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { Root } from 'react-dom/client';
|
|
3
|
-
import type { RuntimeContext } from '../context';
|
|
3
|
+
import type { RuntimeContext } from '../context/runtime';
|
|
4
4
|
export declare const isReact18: () => boolean;
|
|
5
5
|
export declare function hydrateRoot(App: React.ReactElement, context: RuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement, callback?: () => void) => Promise<HTMLElement | Root>): Promise<HTMLElement | Root>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RuntimeContext } from '../context';
|
|
2
|
+
export declare function transformHookRunner(hookRunnerName: string): string;
|
|
3
|
+
export declare function handleSetupResult(setupResult: Record<string, (...args: any) => any>, api: Record<string, any>): void;
|
|
4
|
+
export declare function getHookRunners(runtimeContext: RuntimeContext): Record<string, any>;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { RuntimePlugin } from '@modern-js/plugin-v2';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { Renderer } from 'react-dom';
|
|
3
4
|
import type { createRoot, hydrateRoot } from 'react-dom/client';
|
|
4
|
-
import { type RuntimeContext
|
|
5
|
-
import { type Plugin
|
|
5
|
+
import { type RuntimeContext } from './context/runtime';
|
|
6
|
+
import { type Plugin } from './plugin';
|
|
7
|
+
import type { RuntimeExtends } from './plugin/types';
|
|
6
8
|
export type CreateAppOptions = {
|
|
7
|
-
plugins: Plugin[];
|
|
9
|
+
plugins: (Plugin | RuntimePlugin<RuntimeExtends>)[];
|
|
8
10
|
/**
|
|
9
11
|
* In the test cases, we need to execute multiple createApp instances simultaneously, and they must not share the runtime.
|
|
10
12
|
*/
|
|
11
|
-
runtime?: typeof runtime;
|
|
12
13
|
props?: any;
|
|
13
14
|
};
|
|
14
|
-
export declare const createApp: ({ plugins,
|
|
15
|
+
export declare const createApp: ({ plugins, props: globalProps, }: CreateAppOptions) => (App?: React.ComponentType<any>) => (props: any) => React.JSX.Element;
|
|
15
16
|
type BootStrap<T = unknown> = (App: React.ComponentType, id: string | HTMLElement | RuntimeContext, root?: any, ReactDOM?: {
|
|
16
17
|
render?: Renderer;
|
|
17
18
|
hydrate?: Renderer;
|
|
@@ -19,5 +20,5 @@ type BootStrap<T = unknown> = (App: React.ComponentType, id: string | HTMLElemen
|
|
|
19
20
|
hydrateRoot?: typeof hydrateRoot;
|
|
20
21
|
}) => Promise<T>;
|
|
21
22
|
export declare const bootstrap: BootStrap;
|
|
22
|
-
export declare const useRuntimeContext: () =>
|
|
23
|
+
export declare const useRuntimeContext: () => RuntimeContext;
|
|
23
24
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { InternalRuntimeContext } from '@modern-js/plugin-v2';
|
|
2
3
|
import type { NestedRoute, PageRoute } from '@modern-js/types';
|
|
3
4
|
import type { AppConfig } from '../../common';
|
|
4
|
-
|
|
5
|
+
import type { RuntimeExtends } from '../plugin/types';
|
|
6
|
+
export { type RuntimeContext, RuntimeReactContext, getInitialContext, } from './runtime';
|
|
5
7
|
interface GlobalContext {
|
|
6
8
|
/**
|
|
7
9
|
* App.tsx export default component
|
|
@@ -23,10 +25,13 @@ interface GlobalContext {
|
|
|
23
25
|
* page router _app.tsx export layout app
|
|
24
26
|
*/
|
|
25
27
|
layoutApp?: React.ComponentType;
|
|
28
|
+
internalRuntimeContext?: InternalRuntimeContext<RuntimeExtends>;
|
|
26
29
|
}
|
|
27
|
-
export declare function setGlobalContext(context: Omit<GlobalContext, 'appConfig'> & {
|
|
30
|
+
export declare function setGlobalContext(context: Omit<GlobalContext, 'appConfig' | 'internalRuntimeContext'> & {
|
|
28
31
|
appConfig?: () => AppConfig;
|
|
29
32
|
}): void;
|
|
33
|
+
export declare function setGlobalInternalRuntimeContext(context: InternalRuntimeContext<RuntimeExtends>): void;
|
|
34
|
+
export declare function getGlobalInternalRuntimeContext(): InternalRuntimeContext<Required<import("@modern-js/plugin-v2").RuntimePluginExtends<import("../plugin/types").RuntimeConfig, import("./runtime").RuntimeContext, {}, {}>>>;
|
|
30
35
|
export declare function getGlobalApp(): import("react").ComponentType<{}> | undefined;
|
|
31
36
|
export declare function getGlobalRoutes(): undefined | (NestedRoute | PageRoute)[];
|
|
32
37
|
export declare function getGlobalAppInit(): any;
|
|
@@ -3,13 +3,11 @@ import type { Store } from '@modern-js-reduck/store';
|
|
|
3
3
|
import type { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
4
4
|
import type { RouteManifest } from '../../router/runtime/types';
|
|
5
5
|
import { createLoaderManager } from '../loader/loaderManager';
|
|
6
|
-
import type { PluginRunner, runtime } from '../plugin';
|
|
7
6
|
import type { SSRServerContext, TSSRContext } from '../types';
|
|
8
7
|
interface BaseRuntimeContext {
|
|
9
8
|
initialData?: Record<string, unknown>;
|
|
10
9
|
loaderManager: ReturnType<typeof createLoaderManager>;
|
|
11
10
|
isBrowser: boolean;
|
|
12
|
-
runner: ReturnType<typeof runtime.init>;
|
|
13
11
|
ssrContext?: SSRServerContext;
|
|
14
12
|
store?: Store;
|
|
15
13
|
routeManifest: RouteManifest;
|
|
@@ -35,5 +33,5 @@ export interface TRuntimeContext extends Partial<BaseRuntimeContext> {
|
|
|
35
33
|
store?: Store;
|
|
36
34
|
[key: string]: any;
|
|
37
35
|
}
|
|
38
|
-
export declare const getInitialContext: (
|
|
36
|
+
export declare const getInitialContext: (isBrowser?: boolean, routeManifest?: RouteManifest) => RuntimeContext;
|
|
39
37
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { Plugin } from './plugin';
|
|
1
|
+
export type { Plugin, RuntimePluginFuture } from './plugin';
|
|
3
2
|
export { defineConfig, getConfig, defineRuntimeConfig } from './config';
|
|
4
3
|
export * from './compatible';
|
|
5
4
|
export type { RuntimeContext } from './context/runtime';
|
|
@@ -1,40 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import type { AsyncInterruptWorkflow, PluginOptions, Setup, SyncParallelWorkflow, Waterfall } from '@modern-js/plugin';
|
|
3
3
|
import type { RuntimeContext, TRuntimeContext } from '../context/runtime';
|
|
4
|
-
import type { RuntimeConfig } from './
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
wrapRoot: import("@modern-js/plugin").Waterfall<import("react").ComponentType<any>>;
|
|
12
|
-
pickContext: import("@modern-js/plugin").Waterfall<TRuntimeContext>;
|
|
13
|
-
modifyRuntimeConfig: import("@modern-js/plugin").SyncParallelWorkflow<void, Record<string, any>>;
|
|
4
|
+
import type { RuntimeConfig } from './types';
|
|
5
|
+
/** All hooks of runtime plugin. */
|
|
6
|
+
export type RuntimeHooks = {
|
|
7
|
+
beforeRender: AsyncInterruptWorkflow<RuntimeContext, void>;
|
|
8
|
+
wrapRoot: Waterfall<React.ComponentType<any>>;
|
|
9
|
+
pickContext: Waterfall<TRuntimeContext>;
|
|
10
|
+
modifyRuntimeConfig: SyncParallelWorkflow<void, Record<string, any>>;
|
|
14
11
|
};
|
|
15
|
-
|
|
12
|
+
export type RuntimePluginAPI = {
|
|
16
13
|
useRuntimeConfigContext: () => RuntimeConfig;
|
|
17
14
|
};
|
|
18
|
-
/** All hooks of runtime plugin. */
|
|
19
|
-
export type RuntimeHooks = typeof runtimeHooks;
|
|
20
|
-
export type RuntimePluginAPI = typeof runtimePluginAPI;
|
|
21
15
|
/** Plugin options of a runtime plugin. */
|
|
22
16
|
export type Plugin = PluginOptions<RuntimeHooks, Setup<RuntimeHooks, RuntimePluginAPI>>;
|
|
23
|
-
export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
|
|
24
|
-
beforeRender: import("@modern-js/plugin").AsyncInterruptWorkflow<RuntimeContext, void>;
|
|
25
|
-
wrapRoot: import("@modern-js/plugin").Waterfall<import("react").ComponentType<any>>;
|
|
26
|
-
pickContext: import("@modern-js/plugin").Waterfall<TRuntimeContext>;
|
|
27
|
-
modifyRuntimeConfig: import("@modern-js/plugin").SyncParallelWorkflow<void, Record<string, any>>;
|
|
28
|
-
}, {
|
|
29
|
-
useRuntimeConfigContext: () => RuntimeConfig;
|
|
30
|
-
}>;
|
|
31
|
-
export declare const runtime: import("@modern-js/plugin").Manager<{
|
|
32
|
-
beforeRender: import("@modern-js/plugin").AsyncInterruptWorkflow<RuntimeContext, void>;
|
|
33
|
-
wrapRoot: import("@modern-js/plugin").Waterfall<import("react").ComponentType<any>>;
|
|
34
|
-
pickContext: import("@modern-js/plugin").Waterfall<TRuntimeContext>;
|
|
35
|
-
modifyRuntimeConfig: import("@modern-js/plugin").SyncParallelWorkflow<void, Record<string, any>>;
|
|
36
|
-
}, {
|
|
37
|
-
useRuntimeConfigContext: () => RuntimeConfig;
|
|
38
|
-
}>;
|
|
39
|
-
export type PluginRunner = ReturnType<typeof runtime.init>;
|
|
40
|
-
export {};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}>;
|
|
1
|
+
import type { Plugin as RuntimePlugin } from './base';
|
|
2
|
+
import type { RuntimeConfig, RuntimePluginFuture } from './types';
|
|
3
|
+
export type { Plugin } from './base';
|
|
4
|
+
export type { RuntimePluginFuture };
|
|
5
|
+
export declare function registerPlugin(internalPlugins: (RuntimePlugin | RuntimePluginFuture)[], runtimeConfig?: RuntimeConfig): {
|
|
6
|
+
hooks: import("@modern-js/plugin-v2/runtime").Hooks<{} | undefined, import("@modern-js/plugin-v2/runtime").RuntimeContext>;
|
|
7
|
+
extendsHooks: {} | undefined;
|
|
8
|
+
config: {} | undefined;
|
|
9
|
+
pluginAPI?: Readonly<{
|
|
10
|
+
updateRuntimeContext: (updateContext: import("@modern-js/plugin-v2/dist/types/types/utils").DeepPartial<import("@modern-js/plugin-v2/runtime").RuntimeContext>) => void;
|
|
11
|
+
getHooks: () => Readonly<import("@modern-js/plugin-v2/runtime").Hooks<{} | undefined, import("@modern-js/plugin-v2/runtime").RuntimeContext>>;
|
|
12
|
+
getRuntimeConfig: () => Readonly<{} | undefined>;
|
|
13
|
+
onBeforeRender: import("@modern-js/plugin-v2/dist/types").PluginHookTap<import("@modern-js/plugin-v2/dist/types/types/runtime/hooks").OnBeforeRenderFn<{} | undefined>>;
|
|
14
|
+
wrapRoot: import("@modern-js/plugin-v2/dist/types").PluginHookTap<import("@modern-js/plugin-v2/dist/types/types/runtime/hooks").WrapRootFn>;
|
|
15
|
+
pickContext: import("@modern-js/plugin-v2/dist/types").PluginHookTap<import("@modern-js/plugin-v2/dist/types/types/runtime/hooks").PickContextFn<import("@modern-js/plugin-v2/runtime").RuntimeContext>>;
|
|
16
|
+
modifyRuntimeConfig: import("@modern-js/plugin-v2/dist/types").PluginHookTap<import("@modern-js/plugin-v2/dist/types/types/runtime/hooks").ModifyRuntimeConfigFn<{} | undefined>>;
|
|
17
|
+
} & {}> | undefined;
|
|
18
|
+
_internalContext?: any | undefined;
|
|
19
|
+
};
|
|
13
20
|
export declare function mergeConfig(config: Record<string, any>, ...otherConfig: Record<string, any>[]): Record<string, any>;
|