@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.
Files changed (64) hide show
  1. package/dist/cjs/core/browser/index.js +6 -4
  2. package/dist/cjs/core/compat/hooks.js +80 -0
  3. package/dist/cjs/core/{plugin/runner.js → compat/index.js} +19 -19
  4. package/dist/cjs/core/compatible.js +15 -11
  5. package/dist/cjs/core/context/index.js +12 -2
  6. package/dist/cjs/core/context/runtime.js +1 -2
  7. package/dist/cjs/core/index.js +1 -4
  8. package/dist/cjs/core/plugin/base.js +0 -35
  9. package/dist/cjs/core/plugin/index.js +17 -17
  10. package/dist/cjs/core/plugin/types.js +16 -0
  11. package/dist/cjs/core/react/index.js +3 -3
  12. package/dist/cjs/core/server/requestHandler.js +4 -4
  13. package/dist/cjs/router/runtime/hooks.js +7 -7
  14. package/dist/cjs/router/runtime/plugin.js +107 -108
  15. package/dist/cjs/router/runtime/plugin.node.js +89 -91
  16. package/dist/esm/core/browser/index.js +9 -7
  17. package/dist/esm/core/compat/hooks.js +88 -0
  18. package/dist/esm/core/compat/index.js +20 -0
  19. package/dist/esm/core/compatible.js +17 -13
  20. package/dist/esm/core/context/index.js +9 -1
  21. package/dist/esm/core/context/runtime.js +2 -3
  22. package/dist/esm/core/index.js +1 -3
  23. package/dist/esm/core/plugin/base.js +0 -28
  24. package/dist/esm/core/plugin/index.js +14 -17
  25. package/dist/esm/core/plugin/types.js +0 -0
  26. package/dist/esm/core/react/index.js +4 -4
  27. package/dist/esm/core/server/requestHandler.js +6 -6
  28. package/dist/esm/router/runtime/hooks.js +5 -5
  29. package/dist/esm/router/runtime/plugin.js +114 -115
  30. package/dist/esm/router/runtime/plugin.node.js +112 -111
  31. package/dist/esm-node/core/browser/index.js +7 -5
  32. package/dist/esm-node/core/compat/hooks.js +54 -0
  33. package/dist/esm-node/core/compat/index.js +18 -0
  34. package/dist/esm-node/core/compatible.js +16 -12
  35. package/dist/esm-node/core/context/index.js +9 -1
  36. package/dist/esm-node/core/context/runtime.js +1 -2
  37. package/dist/esm-node/core/index.js +1 -3
  38. package/dist/esm-node/core/plugin/base.js +0 -24
  39. package/dist/esm-node/core/plugin/index.js +16 -14
  40. package/dist/esm-node/core/plugin/types.js +0 -0
  41. package/dist/esm-node/core/react/index.js +4 -4
  42. package/dist/esm-node/core/server/requestHandler.js +5 -5
  43. package/dist/esm-node/router/runtime/hooks.js +5 -5
  44. package/dist/esm-node/router/runtime/plugin.js +108 -109
  45. package/dist/esm-node/router/runtime/plugin.node.js +90 -92
  46. package/dist/types/core/browser/hydrate.d.ts +1 -1
  47. package/dist/types/core/compat/hooks.d.ts +4 -0
  48. package/dist/types/core/compat/index.d.ts +2 -0
  49. package/dist/types/core/compatible.d.ts +7 -6
  50. package/dist/types/core/context/index.d.ts +7 -2
  51. package/dist/types/core/context/runtime.d.ts +1 -3
  52. package/dist/types/core/index.d.ts +1 -2
  53. package/dist/types/core/plugin/base.d.ts +9 -33
  54. package/dist/types/core/plugin/index.d.ts +19 -12
  55. package/dist/types/core/plugin/types.d.ts +10 -0
  56. package/dist/types/index.d.ts +1 -1
  57. package/dist/types/router/runtime/hooks.d.ts +7 -3
  58. package/dist/types/router/runtime/index.d.ts +1 -0
  59. package/dist/types/router/runtime/plugin.d.ts +5 -2
  60. package/dist/types/router/runtime/plugin.node.d.ts +5 -2
  61. package/package.json +10 -10
  62. package/dist/esm/core/plugin/runner.js +0 -17
  63. package/dist/esm-node/core/plugin/runner.js +0 -17
  64. 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
- registerHook: {
27
- modifyRoutes: modifyRoutesHook
26
+ registryHooks: {
27
+ modifyRoutes: modifyRoutesHook,
28
+ onBeforeCreateRoutes: onBeforeCreateRoutesHook
28
29
  },
29
30
  setup: (api) => {
30
31
  let routes = [];
31
- return {
32
- beforeRender(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();
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
- context.router = {
45
- useMatches,
46
- useLocation,
47
- useHref
48
- };
49
- Object.defineProperty(context, "routes", {
50
- get() {
51
- return routes;
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
- 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)
79
- };
80
- }
81
- routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
82
- routesConfig: finalRouteConfig,
83
- props
84
- }));
85
- const runner = api.useHookRunners();
86
- routes = runner.modifyRoutes(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);
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
- return router;
106
- }, [
107
- finalRouteConfig,
108
- props,
109
- _basename,
110
- hydrationData,
111
- getBlockNavState
112
- ]);
113
- };
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
- };
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
- return getRouteApp();
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 { beforeCreateRoutes as beforeCreateRoutesHook, modifyRoutes as modifyRoutesHook } from "./hooks";
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
- registerHook: {
29
+ registryHooks: {
30
30
  modifyRoutes: modifyRoutesHook,
31
- beforeCreateRoutes: beforeCreateRoutesHook
31
+ onBeforeCreateRoutes: onBeforeCreateRoutesHook
32
32
  },
33
33
  setup: (api) => {
34
34
  let finalRouteConfig = {};
35
- return {
36
- async beforeRender(context, interrupt) {
37
- var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1;
38
- const pluginConfig = api.useRuntimeConfigContext();
39
- const { basename = "", routesConfig, createRoutes } = merge(pluginConfig.router || {}, userConfig);
40
- finalRouteConfig = {
41
- routes: getGlobalRoutes(),
42
- globalApp: getGlobalLayoutApp(),
43
- ...routesConfig
44
- };
45
- if (!finalRouteConfig.routes && !createRoutes) {
46
- return;
47
- }
48
- const { request, mode: ssrMode, nonce, loaderFailureMode = "errorBoundary" } = context.ssrContext;
49
- const { baseUrl } = request;
50
- const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
51
- const { reporter } = context.ssrContext;
52
- const requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
53
- requestContext.set(reporterCtx, reporter);
54
- const runner = api.useHookRunners();
55
- await runner.beforeCreateRoutes(context);
56
- let routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
57
- routesConfig: finalRouteConfig,
58
- ssrMode,
59
- props: {
60
- nonce
61
- },
62
- reporter
63
- }));
64
- routes = runner.modifyRoutes(routes);
65
- const { query } = createStaticHandler(routes, {
66
- basename: _basename
67
- });
68
- const remixRequest = createRemixReuqest(context.ssrContext.request.raw);
69
- const end = time();
70
- const routerContext = await query(remixRequest, {
71
- requestContext
72
- });
73
- const cost = end();
74
- (_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);
75
- if (routerContext instanceof Response) {
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>;
@@ -0,0 +1,2 @@
1
+ import type { RuntimePluginFuture } from '../plugin/types';
2
+ export declare const compatPlugin: () => RuntimePluginFuture;
@@ -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, type TRuntimeContext } from './context/runtime';
5
- import { type Plugin, type runtime } from './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, runtime, props: globalProps, }: CreateAppOptions) => (App?: React.ComponentType<any>) => (props: any) => React.JSX.Element;
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: () => TRuntimeContext;
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
- export { RuntimeReactContext, type RuntimeContext, getInitialContext, } from './runtime';
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: (runner: PluginRunner, isBrowser?: boolean, routeManifest?: RouteManifest) => RuntimeContext;
36
+ export declare const getInitialContext: (isBrowser?: boolean, routeManifest?: RouteManifest) => RuntimeContext;
39
37
  export {};
@@ -1,5 +1,4 @@
1
- export { runtime } from './plugin';
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 { type PluginOptions, type Setup } from '@modern-js/plugin';
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 './index';
5
- export declare const RuntimeConfigContext: import("@modern-js/plugin").Context<RuntimeConfig>;
6
- export declare const useRuntimeConfigContext: () => RuntimeConfig;
7
- export interface AppProps {
8
- }
9
- declare const runtimeHooks: {
10
- beforeRender: import("@modern-js/plugin").AsyncInterruptWorkflow<RuntimeContext, void>;
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
- declare const runtimePluginAPI: {
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
- /// <reference types="react" />
2
- import { type Plugin, runtime } from './base';
3
- export * from './base';
4
- export interface RuntimeConfig {
5
- plugins?: Plugin[];
6
- }
7
- export declare function registerPlugin(internalPlugins: Plugin[], runtimeConfig?: RuntimeConfig, customRuntime?: typeof runtime): import("@modern-js/plugin").ToRunners<{
8
- beforeRender: import("@modern-js/plugin").AsyncInterruptWorkflow<import("..").RuntimeContext, void>;
9
- wrapRoot: import("@modern-js/plugin").Waterfall<import("react").ComponentType<any>>;
10
- pickContext: import("@modern-js/plugin").Waterfall<import("../context/runtime").TRuntimeContext>;
11
- modifyRuntimeConfig: import("@modern-js/plugin").SyncParallelWorkflow<void, Record<string, any>>;
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>;