@modern-js/runtime 2.63.7 → 2.64.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/browser/index.js +16 -6
- 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/cjs/state/cli/index.js +2 -2
- package/dist/esm/core/browser/index.js +14 -8
- 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/state/cli/index.js +2 -2
- package/dist/esm-node/core/browser/index.js +12 -6
- 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/esm-node/state/cli/index.js +2 -2
- package/dist/types/cli/template.d.ts +2 -2
- package/dist/types/core/browser/hydrate.d.ts +1 -1
- package/dist/types/core/browser/index.d.ts +4 -0
- 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
|
@@ -49,121 +49,120 @@ function modifyRoutes(modifyFunction) {
|
|
|
49
49
|
const routerPlugin = (userConfig = {}) => {
|
|
50
50
|
return {
|
|
51
51
|
name: "@modern-js/plugin-router",
|
|
52
|
-
|
|
53
|
-
modifyRoutes: import_hooks.modifyRoutes
|
|
52
|
+
registryHooks: {
|
|
53
|
+
modifyRoutes: import_hooks.modifyRoutes,
|
|
54
|
+
onBeforeCreateRoutes: import_hooks.onBeforeCreateRoutes
|
|
54
55
|
},
|
|
55
56
|
setup: (api) => {
|
|
56
57
|
let routes = [];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
window.location.reload();
|
|
68
|
-
}
|
|
58
|
+
api.onBeforeRender((context) => {
|
|
59
|
+
if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
|
|
60
|
+
var _ssrContext_request;
|
|
61
|
+
const { ssrContext } = context;
|
|
62
|
+
const currentPathname = (0, import_url.normalizePathname)(window.location.pathname);
|
|
63
|
+
const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && (0, import_url.normalizePathname)(ssrContext.request.pathname);
|
|
64
|
+
if (initialPathname && initialPathname !== currentPathname) {
|
|
65
|
+
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
66
|
+
console.error(errorMsg);
|
|
67
|
+
window.location.reload();
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
wrapRoot: (App) => {
|
|
82
|
-
const pluginConfig = api.useRuntimeConfigContext();
|
|
83
|
-
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes, future } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
|
|
84
|
-
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
85
|
-
finalRouteConfig = {
|
|
86
|
-
routes: (0, import_context.getGlobalRoutes)(),
|
|
87
|
-
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
88
|
-
...routesConfig
|
|
89
|
-
};
|
|
90
|
-
if (!finalRouteConfig.routes && !createRoutes) {
|
|
91
|
-
return App;
|
|
69
|
+
}
|
|
70
|
+
context.router = {
|
|
71
|
+
useMatches: import_router.useMatches,
|
|
72
|
+
useLocation: import_router.useLocation,
|
|
73
|
+
useHref: import_router.useHref
|
|
74
|
+
};
|
|
75
|
+
Object.defineProperty(context, "routes", {
|
|
76
|
+
get() {
|
|
77
|
+
return routes;
|
|
92
78
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
hydrationData
|
|
119
|
-
});
|
|
120
|
-
const originSubscribe = router.subscribe;
|
|
121
|
-
router.subscribe = (listener) => {
|
|
122
|
-
const wrapedListener = (...args) => {
|
|
123
|
-
const blockRoute = getBlockNavState ? getBlockNavState() : false;
|
|
124
|
-
if (blockRoute) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
return listener(...args);
|
|
128
|
-
};
|
|
129
|
-
return originSubscribe(wrapedListener);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
api.wrapRoot((App) => {
|
|
82
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
83
|
+
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes, future } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
|
|
84
|
+
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
85
|
+
finalRouteConfig = {
|
|
86
|
+
routes: (0, import_context.getGlobalRoutes)(),
|
|
87
|
+
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
88
|
+
...routesConfig
|
|
89
|
+
};
|
|
90
|
+
if (!finalRouteConfig.routes && !createRoutes) {
|
|
91
|
+
return App;
|
|
92
|
+
}
|
|
93
|
+
const getRouteApp = () => {
|
|
94
|
+
const useCreateRouter = (props) => {
|
|
95
|
+
const runtimeContext = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
96
|
+
const baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
|
97
|
+
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
|
|
98
|
+
let hydrationData = window._ROUTER_DATA;
|
|
99
|
+
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
100
|
+
return (0, import_react.useMemo)(() => {
|
|
101
|
+
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
102
|
+
hydrationData = {
|
|
103
|
+
...hydrationData,
|
|
104
|
+
errors: (0, import_utils.deserializeErrors)(hydrationData.errors)
|
|
130
105
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
finalRouteConfig,
|
|
134
|
-
props
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
106
|
+
}
|
|
107
|
+
routes = createRoutes ? createRoutes() : (0, import_router.createRoutesFromElements)((0, import_utils.renderRoutes)({
|
|
108
|
+
routesConfig: finalRouteConfig,
|
|
109
|
+
props
|
|
110
|
+
}));
|
|
111
|
+
const hooks = api.getHooks();
|
|
112
|
+
routes = hooks.modifyRoutes.call(routes);
|
|
113
|
+
const router = supportHtml5History ? (0, import_router.createBrowserRouter)(routes, {
|
|
114
|
+
basename: _basename,
|
|
115
|
+
hydrationData
|
|
116
|
+
}) : (0, import_router.createHashRouter)(routes, {
|
|
117
|
+
basename: _basename,
|
|
118
|
+
hydrationData
|
|
119
|
+
});
|
|
120
|
+
const originSubscribe = router.subscribe;
|
|
121
|
+
router.subscribe = (listener) => {
|
|
122
|
+
const wrapedListener = (...args) => {
|
|
123
|
+
const blockRoute = getBlockNavState ? getBlockNavState() : false;
|
|
124
|
+
if (blockRoute) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
return listener(...args);
|
|
128
|
+
};
|
|
129
|
+
return originSubscribe(wrapedListener);
|
|
130
|
+
};
|
|
131
|
+
return router;
|
|
132
|
+
}, [
|
|
133
|
+
finalRouteConfig,
|
|
134
|
+
props,
|
|
135
|
+
_basename,
|
|
136
|
+
hydrationData,
|
|
137
|
+
getBlockNavState
|
|
138
|
+
]);
|
|
163
139
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
140
|
+
const Null = () => null;
|
|
141
|
+
return (props) => {
|
|
142
|
+
beforeCreateRouter = false;
|
|
143
|
+
const router = useCreateRouter(props);
|
|
144
|
+
const routerWrapper = (
|
|
145
|
+
// 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
|
|
146
|
+
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
147
|
+
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_router.RouterProvider, {
|
|
151
|
+
router,
|
|
152
|
+
future
|
|
153
|
+
}),
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Null, {}),
|
|
155
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Null, {})
|
|
156
|
+
]
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
return App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
160
|
+
children: routerWrapper
|
|
161
|
+
}) : routerWrapper;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
return getRouteApp();
|
|
165
|
+
});
|
|
167
166
|
}
|
|
168
167
|
};
|
|
169
168
|
};
|
|
@@ -60,102 +60,100 @@ function createRemixReuqest(request) {
|
|
|
60
60
|
const routerPlugin = (userConfig = {}) => {
|
|
61
61
|
return {
|
|
62
62
|
name: "@modern-js/plugin-router",
|
|
63
|
-
|
|
63
|
+
registryHooks: {
|
|
64
64
|
modifyRoutes: import_hooks.modifyRoutes,
|
|
65
|
-
|
|
65
|
+
onBeforeCreateRoutes: import_hooks.onBeforeCreateRoutes
|
|
66
66
|
},
|
|
67
67
|
setup: (api) => {
|
|
68
68
|
let finalRouteConfig = {};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return interrupt(routerContext);
|
|
111
|
-
}
|
|
112
|
-
const errors = Object.values(routerContext.errors || {});
|
|
113
|
-
if (
|
|
114
|
-
// TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
|
|
115
|
-
errors.length > 0 && loaderFailureMode === "clientRender"
|
|
116
|
-
) {
|
|
117
|
-
routerContext.statusCode = 200;
|
|
118
|
-
throw errors[0];
|
|
119
|
-
}
|
|
120
|
-
const router = (0, import_router.createStaticRouter)(routes, routerContext);
|
|
121
|
-
context.routerContext = routerContext;
|
|
122
|
-
context.remixRouter = router;
|
|
123
|
-
context.routes = routes;
|
|
124
|
-
},
|
|
125
|
-
wrapRoot: (App) => {
|
|
126
|
-
if (!finalRouteConfig) {
|
|
127
|
-
return App;
|
|
128
|
-
}
|
|
129
|
-
const getRouteApp = () => {
|
|
130
|
-
return () => {
|
|
131
|
-
const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
132
|
-
const { remixRouter, routerContext, ssrContext } = context;
|
|
133
|
-
const { nonce, mode, useJsonScript } = ssrContext;
|
|
134
|
-
const routerWrapper = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
135
|
-
children: [
|
|
136
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_router.StaticRouterProvider, {
|
|
137
|
-
router: remixRouter,
|
|
138
|
-
context: routerContext,
|
|
139
|
-
hydrate: false
|
|
140
|
-
}),
|
|
141
|
-
mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
|
|
142
|
-
// So we can inject it only when streaming ssr
|
|
143
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DeferredDataScripts.default, {
|
|
144
|
-
nonce,
|
|
145
|
-
context: routerContext,
|
|
146
|
-
useJsonScript
|
|
147
|
-
}),
|
|
148
|
-
mode === "stream" && import_common.JSX_SHELL_STREAM_END_MARK
|
|
149
|
-
]
|
|
150
|
-
});
|
|
151
|
-
return App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
152
|
-
children: routerWrapper
|
|
153
|
-
}) : routerWrapper;
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
return getRouteApp();
|
|
69
|
+
api.onBeforeRender(async (context, interrupt) => {
|
|
70
|
+
var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1;
|
|
71
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
72
|
+
const { basename = "", routesConfig, createRoutes } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
|
|
73
|
+
finalRouteConfig = {
|
|
74
|
+
routes: (0, import_context.getGlobalRoutes)(),
|
|
75
|
+
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
76
|
+
...routesConfig
|
|
77
|
+
};
|
|
78
|
+
if (!finalRouteConfig.routes && !createRoutes) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const { request, mode: ssrMode, nonce, loaderFailureMode = "errorBoundary" } = context.ssrContext;
|
|
82
|
+
const { baseUrl } = request;
|
|
83
|
+
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
|
|
84
|
+
const { reporter } = context.ssrContext;
|
|
85
|
+
const requestContext = (0, import_node.createRequestContext)((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
|
|
86
|
+
requestContext.set(import_node.reporterCtx, reporter);
|
|
87
|
+
const hooks = api.getHooks();
|
|
88
|
+
await hooks.onBeforeCreateRoutes.call(context);
|
|
89
|
+
let routes = createRoutes ? createRoutes() : (0, import_router2.createRoutesFromElements)((0, import_utils.renderRoutes)({
|
|
90
|
+
routesConfig: finalRouteConfig,
|
|
91
|
+
ssrMode,
|
|
92
|
+
props: {
|
|
93
|
+
nonce
|
|
94
|
+
},
|
|
95
|
+
reporter
|
|
96
|
+
}));
|
|
97
|
+
routes = hooks.modifyRoutes.call(routes);
|
|
98
|
+
const { query } = (0, import_remix_router.createStaticHandler)(routes, {
|
|
99
|
+
basename: _basename
|
|
100
|
+
});
|
|
101
|
+
const remixRequest = createRemixReuqest(context.ssrContext.request.raw);
|
|
102
|
+
const end = (0, import_time.time)();
|
|
103
|
+
const routerContext = await query(remixRequest, {
|
|
104
|
+
requestContext
|
|
105
|
+
});
|
|
106
|
+
const cost = end();
|
|
107
|
+
(_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, import_constants.LOADER_REPORTER_NAME, cost);
|
|
108
|
+
if (routerContext instanceof Response) {
|
|
109
|
+
return interrupt(routerContext);
|
|
157
110
|
}
|
|
158
|
-
|
|
111
|
+
const errors = Object.values(routerContext.errors || {});
|
|
112
|
+
if (
|
|
113
|
+
// TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
|
|
114
|
+
errors.length > 0 && loaderFailureMode === "clientRender"
|
|
115
|
+
) {
|
|
116
|
+
routerContext.statusCode = 200;
|
|
117
|
+
throw errors[0];
|
|
118
|
+
}
|
|
119
|
+
const router = (0, import_router.createStaticRouter)(routes, routerContext);
|
|
120
|
+
context.routerContext = routerContext;
|
|
121
|
+
context.remixRouter = router;
|
|
122
|
+
context.routes = routes;
|
|
123
|
+
});
|
|
124
|
+
api.wrapRoot((App) => {
|
|
125
|
+
if (!finalRouteConfig) {
|
|
126
|
+
return App;
|
|
127
|
+
}
|
|
128
|
+
const getRouteApp = () => {
|
|
129
|
+
return () => {
|
|
130
|
+
const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
131
|
+
const { remixRouter, routerContext, ssrContext } = context;
|
|
132
|
+
const { nonce, mode, useJsonScript } = ssrContext;
|
|
133
|
+
const routerWrapper = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_router.StaticRouterProvider, {
|
|
136
|
+
router: remixRouter,
|
|
137
|
+
context: routerContext,
|
|
138
|
+
hydrate: false
|
|
139
|
+
}),
|
|
140
|
+
mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
|
|
141
|
+
// So we can inject it only when streaming ssr
|
|
142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DeferredDataScripts.default, {
|
|
143
|
+
nonce,
|
|
144
|
+
context: routerContext,
|
|
145
|
+
useJsonScript
|
|
146
|
+
}),
|
|
147
|
+
mode === "stream" && import_common.JSX_SHELL_STREAM_END_MARK
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
return App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
151
|
+
children: routerWrapper
|
|
152
|
+
}) : routerWrapper;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
return getRouteApp();
|
|
156
|
+
});
|
|
159
157
|
}
|
|
160
158
|
};
|
|
161
159
|
};
|
|
@@ -33,8 +33,8 @@ const statePlugin = () => ({
|
|
|
33
33
|
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
34
34
|
var _getEntryOptions;
|
|
35
35
|
const { entryName, isMainEntry } = entrypoint;
|
|
36
|
-
const userConfig = api.
|
|
37
|
-
const { packageName, metaName } = api.
|
|
36
|
+
const userConfig = api.getNormalizedConfig();
|
|
37
|
+
const { packageName, metaName } = api.getAppContext();
|
|
38
38
|
const stateConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
39
39
|
if (stateConfig) {
|
|
40
40
|
plugins.push({
|
|
@@ -5,10 +5,9 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
5
5
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
7
|
import cookieTool from "cookie";
|
|
8
|
-
import { getGlobalAppInit } from "../context";
|
|
8
|
+
import { getGlobalAppInit, getGlobalInternalRuntimeContext } from "../context";
|
|
9
9
|
import { getInitialContext } from "../context/runtime";
|
|
10
10
|
import { createLoaderManager } from "../loader/loaderManager";
|
|
11
|
-
import { getGlobalRunner } from "../plugin/runner";
|
|
12
11
|
import { wrapRuntimeContextProvider } from "../react/wrapper";
|
|
13
12
|
import { hydrateRoot } from "./hydrate";
|
|
14
13
|
var IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
@@ -54,7 +53,7 @@ function render(App, id) {
|
|
|
54
53
|
}
|
|
55
54
|
function _render() {
|
|
56
55
|
_render = _async_to_generator(function(App, id) {
|
|
57
|
-
var
|
|
56
|
+
var context, runBeforeRender, ModernRender, ModernHydrate, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement;
|
|
58
57
|
function _ModernRender() {
|
|
59
58
|
_ModernRender = _async_to_generator(function(App2) {
|
|
60
59
|
var renderFunc;
|
|
@@ -84,17 +83,20 @@ function _render() {
|
|
|
84
83
|
return _ts_generator(this, function(_state) {
|
|
85
84
|
switch (_state.label) {
|
|
86
85
|
case 0:
|
|
87
|
-
|
|
88
|
-
context = getInitialContext(runner);
|
|
86
|
+
context = getInitialContext();
|
|
89
87
|
runBeforeRender = function() {
|
|
90
88
|
var _ref = _async_to_generator(function(context2) {
|
|
91
|
-
var init;
|
|
89
|
+
var internalRuntimeContext, api, hooks, init;
|
|
92
90
|
return _ts_generator(this, function(_state2) {
|
|
93
91
|
switch (_state2.label) {
|
|
94
92
|
case 0:
|
|
93
|
+
internalRuntimeContext = getGlobalInternalRuntimeContext();
|
|
94
|
+
api = internalRuntimeContext.pluginAPI;
|
|
95
|
+
api.updateRuntimeContext(context2);
|
|
96
|
+
hooks = internalRuntimeContext.hooks;
|
|
95
97
|
return [
|
|
96
98
|
4,
|
|
97
|
-
|
|
99
|
+
hooks.onBeforeRender.call(context2)
|
|
98
100
|
];
|
|
99
101
|
case 1:
|
|
100
102
|
_state2.sent();
|
|
@@ -270,5 +272,9 @@ function _hydrateWithReact17() {
|
|
|
270
272
|
return _hydrateWithReact17.apply(this, arguments);
|
|
271
273
|
}
|
|
272
274
|
export {
|
|
273
|
-
|
|
275
|
+
hydrateWithReact17,
|
|
276
|
+
hydrateWithReact18,
|
|
277
|
+
render,
|
|
278
|
+
renderWithReact17,
|
|
279
|
+
renderWithReact18
|
|
274
280
|
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
function transformHookRunner(hookRunnerName) {
|
|
5
|
+
switch (hookRunnerName) {
|
|
6
|
+
case "beforeRender":
|
|
7
|
+
return "onBeforeRender";
|
|
8
|
+
default:
|
|
9
|
+
return hookRunnerName;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function handleSetupResult(setupResult, api) {
|
|
13
|
+
if (!setupResult) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
Object.keys(setupResult).forEach(function(key) {
|
|
17
|
+
var fn = setupResult[key];
|
|
18
|
+
if (typeof fn === "function") {
|
|
19
|
+
var newAPI = transformHookRunner(key);
|
|
20
|
+
if (api[newAPI]) {
|
|
21
|
+
if (key === "beforeRender") {
|
|
22
|
+
api[newAPI](/* @__PURE__ */ _async_to_generator(function() {
|
|
23
|
+
var _len, params, _key;
|
|
24
|
+
var _arguments = arguments;
|
|
25
|
+
return _ts_generator(this, function(_state) {
|
|
26
|
+
switch (_state.label) {
|
|
27
|
+
case 0:
|
|
28
|
+
for (_len = _arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
29
|
+
params[_key] = _arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
4,
|
|
33
|
+
fn.apply(void 0, _to_consumable_array(params))
|
|
34
|
+
];
|
|
35
|
+
case 1:
|
|
36
|
+
_state.sent();
|
|
37
|
+
return [
|
|
38
|
+
2
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
} else {
|
|
44
|
+
api[newAPI](function() {
|
|
45
|
+
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
46
|
+
params[_key] = arguments[_key];
|
|
47
|
+
}
|
|
48
|
+
var res = fn.apply(void 0, _to_consumable_array(params));
|
|
49
|
+
return res;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function getHookRunners(runtimeContext) {
|
|
57
|
+
var _internalContext = runtimeContext._internalContext;
|
|
58
|
+
var hooks = _internalContext.hooks;
|
|
59
|
+
return {
|
|
60
|
+
beforeRender: function() {
|
|
61
|
+
var _ref = _async_to_generator(function(context) {
|
|
62
|
+
return _ts_generator(this, function(_state) {
|
|
63
|
+
return [
|
|
64
|
+
2,
|
|
65
|
+
hooks.onBeforeRender.call(context)
|
|
66
|
+
];
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
return function(context) {
|
|
70
|
+
return _ref.apply(this, arguments);
|
|
71
|
+
};
|
|
72
|
+
}(),
|
|
73
|
+
wrapRoot: function(App) {
|
|
74
|
+
return hooks.wrapRoot.call(App);
|
|
75
|
+
},
|
|
76
|
+
pickContext: function(context) {
|
|
77
|
+
return hooks.pickContext.call(context);
|
|
78
|
+
},
|
|
79
|
+
modifyRuntimeConfig: function(config) {
|
|
80
|
+
return hooks.modifyRuntimeConfig.call(config);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
getHookRunners,
|
|
86
|
+
handleSetupResult,
|
|
87
|
+
transformHookRunner
|
|
88
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getHookRunners } from "./hooks";
|
|
2
|
+
var compatPlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: "@modern-js/runtime-plugin-compat",
|
|
5
|
+
_registryApi: function(getRuntimeContext) {
|
|
6
|
+
return {
|
|
7
|
+
useRuntimeConfigContext: function() {
|
|
8
|
+
var _internalContext = getRuntimeContext()._internalContext;
|
|
9
|
+
return _internalContext.config;
|
|
10
|
+
},
|
|
11
|
+
useHookRunners: function() {
|
|
12
|
+
return getHookRunners(getRuntimeContext());
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
compatPlugin
|
|
20
|
+
};
|