@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.
Files changed (69) hide show
  1. package/dist/cjs/core/browser/index.js +16 -6
  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/cjs/state/cli/index.js +2 -2
  17. package/dist/esm/core/browser/index.js +14 -8
  18. package/dist/esm/core/compat/hooks.js +88 -0
  19. package/dist/esm/core/compat/index.js +20 -0
  20. package/dist/esm/core/compatible.js +17 -13
  21. package/dist/esm/core/context/index.js +9 -1
  22. package/dist/esm/core/context/runtime.js +2 -3
  23. package/dist/esm/core/index.js +1 -3
  24. package/dist/esm/core/plugin/base.js +0 -28
  25. package/dist/esm/core/plugin/index.js +14 -17
  26. package/dist/esm/core/plugin/types.js +0 -0
  27. package/dist/esm/core/react/index.js +4 -4
  28. package/dist/esm/core/server/requestHandler.js +6 -6
  29. package/dist/esm/router/runtime/hooks.js +5 -5
  30. package/dist/esm/router/runtime/plugin.js +114 -115
  31. package/dist/esm/router/runtime/plugin.node.js +112 -111
  32. package/dist/esm/state/cli/index.js +2 -2
  33. package/dist/esm-node/core/browser/index.js +12 -6
  34. package/dist/esm-node/core/compat/hooks.js +54 -0
  35. package/dist/esm-node/core/compat/index.js +18 -0
  36. package/dist/esm-node/core/compatible.js +16 -12
  37. package/dist/esm-node/core/context/index.js +9 -1
  38. package/dist/esm-node/core/context/runtime.js +1 -2
  39. package/dist/esm-node/core/index.js +1 -3
  40. package/dist/esm-node/core/plugin/base.js +0 -24
  41. package/dist/esm-node/core/plugin/index.js +16 -14
  42. package/dist/esm-node/core/plugin/types.js +0 -0
  43. package/dist/esm-node/core/react/index.js +4 -4
  44. package/dist/esm-node/core/server/requestHandler.js +5 -5
  45. package/dist/esm-node/router/runtime/hooks.js +5 -5
  46. package/dist/esm-node/router/runtime/plugin.js +108 -109
  47. package/dist/esm-node/router/runtime/plugin.node.js +90 -92
  48. package/dist/esm-node/state/cli/index.js +2 -2
  49. package/dist/types/cli/template.d.ts +2 -2
  50. package/dist/types/core/browser/hydrate.d.ts +1 -1
  51. package/dist/types/core/browser/index.d.ts +4 -0
  52. package/dist/types/core/compat/hooks.d.ts +4 -0
  53. package/dist/types/core/compat/index.d.ts +2 -0
  54. package/dist/types/core/compatible.d.ts +7 -6
  55. package/dist/types/core/context/index.d.ts +7 -2
  56. package/dist/types/core/context/runtime.d.ts +1 -3
  57. package/dist/types/core/index.d.ts +1 -2
  58. package/dist/types/core/plugin/base.d.ts +9 -33
  59. package/dist/types/core/plugin/index.d.ts +19 -12
  60. package/dist/types/core/plugin/types.d.ts +10 -0
  61. package/dist/types/index.d.ts +1 -1
  62. package/dist/types/router/runtime/hooks.d.ts +7 -3
  63. package/dist/types/router/runtime/index.d.ts +1 -0
  64. package/dist/types/router/runtime/plugin.d.ts +5 -2
  65. package/dist/types/router/runtime/plugin.node.d.ts +5 -2
  66. package/package.json +10 -10
  67. package/dist/esm/core/plugin/runner.js +0 -17
  68. package/dist/esm-node/core/plugin/runner.js +0 -17
  69. package/dist/types/core/plugin/runner.d.ts +0 -9
@@ -15,7 +15,7 @@ import { JSX_SHELL_STREAM_END_MARK } from "../../common";
15
15
  import { RuntimeReactContext } from "../../core";
16
16
  import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
17
17
  import DeferredDataScripts from "./DeferredDataScripts.node";
18
- import { beforeCreateRoutes as beforeCreateRoutesHook, modifyRoutes as modifyRoutesHook } from "./hooks";
18
+ import { modifyRoutes as modifyRoutesHook, onBeforeCreateRoutes as onBeforeCreateRoutesHook } from "./hooks";
19
19
  import { renderRoutes, urlJoin } from "./utils";
20
20
  function createRemixReuqest(request) {
21
21
  var method = "GET";
@@ -31,126 +31,127 @@ var routerPlugin = function() {
31
31
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
32
32
  return {
33
33
  name: "@modern-js/plugin-router",
34
- registerHook: {
34
+ registryHooks: {
35
35
  modifyRoutes: modifyRoutesHook,
36
- beforeCreateRoutes: beforeCreateRoutesHook
36
+ onBeforeCreateRoutes: onBeforeCreateRoutesHook
37
37
  },
38
38
  setup: function(api) {
39
39
  var finalRouteConfig = {};
40
- return {
41
- beforeRender: function beforeRender(context, interrupt) {
42
- return _async_to_generator(function() {
43
- var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1, pluginConfig, _merge, _merge_basename, basename, routesConfig, createRoutes, _context_ssrContext2, request, ssrMode, nonce, _context_ssrContext_loaderFailureMode, loaderFailureMode, baseUrl, _basename, reporter, requestContext, runner, routes, query, remixRequest, end, routerContext, cost, errors, router;
44
- return _ts_generator(this, function(_state) {
45
- switch (_state.label) {
46
- case 0:
47
- pluginConfig = api.useRuntimeConfigContext();
48
- _merge = merge(pluginConfig.router || {}, userConfig), _merge_basename = _merge.basename, basename = _merge_basename === void 0 ? "" : _merge_basename, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes;
49
- finalRouteConfig = _object_spread({
50
- routes: getGlobalRoutes(),
51
- globalApp: getGlobalLayoutApp()
52
- }, routesConfig);
53
- if (!finalRouteConfig.routes && !createRoutes) {
54
- return [
55
- 2
56
- ];
57
- }
58
- _context_ssrContext2 = context.ssrContext, request = _context_ssrContext2.request, ssrMode = _context_ssrContext2.mode, nonce = _context_ssrContext2.nonce, _context_ssrContext_loaderFailureMode = _context_ssrContext2.loaderFailureMode, loaderFailureMode = _context_ssrContext_loaderFailureMode === void 0 ? "errorBoundary" : _context_ssrContext_loaderFailureMode;
59
- baseUrl = request.baseUrl;
60
- _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
61
- reporter = context.ssrContext.reporter;
62
- requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
63
- requestContext.set(reporterCtx, reporter);
64
- runner = api.useHookRunners();
40
+ api.onBeforeRender(function() {
41
+ var _ref = _async_to_generator(function(context, interrupt) {
42
+ var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1, pluginConfig, _merge, _merge_basename, basename, routesConfig, createRoutes, _context_ssrContext2, request, ssrMode, nonce, _context_ssrContext_loaderFailureMode, loaderFailureMode, baseUrl, _basename, reporter, requestContext, hooks, routes, query, remixRequest, end, routerContext, cost, errors, router;
43
+ return _ts_generator(this, function(_state) {
44
+ switch (_state.label) {
45
+ case 0:
46
+ pluginConfig = api.getRuntimeConfig();
47
+ _merge = merge(pluginConfig.router || {}, userConfig), _merge_basename = _merge.basename, basename = _merge_basename === void 0 ? "" : _merge_basename, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes;
48
+ finalRouteConfig = _object_spread({
49
+ routes: getGlobalRoutes(),
50
+ globalApp: getGlobalLayoutApp()
51
+ }, routesConfig);
52
+ if (!finalRouteConfig.routes && !createRoutes) {
65
53
  return [
66
- 4,
67
- runner.beforeCreateRoutes(context)
68
- ];
69
- case 1:
70
- _state.sent();
71
- routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
72
- routesConfig: finalRouteConfig,
73
- ssrMode,
74
- props: {
75
- nonce
76
- },
77
- reporter
78
- }));
79
- routes = runner.modifyRoutes(routes);
80
- query = createStaticHandler(routes, {
81
- basename: _basename
82
- }).query;
83
- remixRequest = createRemixReuqest(context.ssrContext.request.raw);
84
- end = time();
85
- return [
86
- 4,
87
- query(remixRequest, {
88
- requestContext
89
- })
54
+ 2
90
55
  ];
91
- case 2:
92
- routerContext = _state.sent();
93
- cost = end();
94
- (_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);
95
- if (_instanceof(routerContext, Response)) {
96
- return [
97
- 2,
98
- interrupt(routerContext)
99
- ];
100
- }
101
- errors = Object.values(routerContext.errors || {});
102
- if (
103
- // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
104
- errors.length > 0 && loaderFailureMode === "clientRender"
105
- ) {
106
- routerContext.statusCode = 200;
107
- throw errors[0];
108
- }
109
- router = createStaticRouter(routes, routerContext);
110
- context.routerContext = routerContext;
111
- context.remixRouter = router;
112
- context.routes = routes;
56
+ }
57
+ _context_ssrContext2 = context.ssrContext, request = _context_ssrContext2.request, ssrMode = _context_ssrContext2.mode, nonce = _context_ssrContext2.nonce, _context_ssrContext_loaderFailureMode = _context_ssrContext2.loaderFailureMode, loaderFailureMode = _context_ssrContext_loaderFailureMode === void 0 ? "errorBoundary" : _context_ssrContext_loaderFailureMode;
58
+ baseUrl = request.baseUrl;
59
+ _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
60
+ reporter = context.ssrContext.reporter;
61
+ requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
62
+ requestContext.set(reporterCtx, reporter);
63
+ hooks = api.getHooks();
64
+ return [
65
+ 4,
66
+ hooks.onBeforeCreateRoutes.call(context)
67
+ ];
68
+ case 1:
69
+ _state.sent();
70
+ routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
71
+ routesConfig: finalRouteConfig,
72
+ ssrMode,
73
+ props: {
74
+ nonce
75
+ },
76
+ reporter
77
+ }));
78
+ routes = hooks.modifyRoutes.call(routes);
79
+ query = createStaticHandler(routes, {
80
+ basename: _basename
81
+ }).query;
82
+ remixRequest = createRemixReuqest(context.ssrContext.request.raw);
83
+ end = time();
84
+ return [
85
+ 4,
86
+ query(remixRequest, {
87
+ requestContext
88
+ })
89
+ ];
90
+ case 2:
91
+ routerContext = _state.sent();
92
+ cost = end();
93
+ (_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);
94
+ if (_instanceof(routerContext, Response)) {
113
95
  return [
114
- 2
96
+ 2,
97
+ interrupt(routerContext)
115
98
  ];
116
- }
99
+ }
100
+ errors = Object.values(routerContext.errors || {});
101
+ if (
102
+ // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
103
+ errors.length > 0 && loaderFailureMode === "clientRender"
104
+ ) {
105
+ routerContext.statusCode = 200;
106
+ throw errors[0];
107
+ }
108
+ router = createStaticRouter(routes, routerContext);
109
+ context.routerContext = routerContext;
110
+ context.remixRouter = router;
111
+ context.routes = routes;
112
+ return [
113
+ 2
114
+ ];
115
+ }
116
+ });
117
+ });
118
+ return function(context, interrupt) {
119
+ return _ref.apply(this, arguments);
120
+ };
121
+ }());
122
+ api.wrapRoot(function(App) {
123
+ if (!finalRouteConfig) {
124
+ return App;
125
+ }
126
+ var getRouteApp = function() {
127
+ return function() {
128
+ var context = useContext(RuntimeReactContext);
129
+ var remixRouter = context.remixRouter, routerContext = context.routerContext, ssrContext = context.ssrContext;
130
+ var nonce = ssrContext.nonce, mode = ssrContext.mode, useJsonScript = ssrContext.useJsonScript;
131
+ var routerWrapper = /* @__PURE__ */ _jsxs(_Fragment, {
132
+ children: [
133
+ /* @__PURE__ */ _jsx(StaticRouterProvider, {
134
+ router: remixRouter,
135
+ context: routerContext,
136
+ hydrate: false
137
+ }),
138
+ mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
139
+ // So we can inject it only when streaming ssr
140
+ /* @__PURE__ */ _jsx(DeferredDataScripts, {
141
+ nonce,
142
+ context: routerContext,
143
+ useJsonScript
144
+ }),
145
+ mode === "stream" && JSX_SHELL_STREAM_END_MARK
146
+ ]
117
147
  });
118
- })();
119
- },
120
- wrapRoot: function(App) {
121
- if (!finalRouteConfig) {
122
- return App;
123
- }
124
- var getRouteApp = function() {
125
- return function() {
126
- var context = useContext(RuntimeReactContext);
127
- var remixRouter = context.remixRouter, routerContext = context.routerContext, ssrContext = context.ssrContext;
128
- var nonce = ssrContext.nonce, mode = ssrContext.mode, useJsonScript = ssrContext.useJsonScript;
129
- var routerWrapper = /* @__PURE__ */ _jsxs(_Fragment, {
130
- children: [
131
- /* @__PURE__ */ _jsx(StaticRouterProvider, {
132
- router: remixRouter,
133
- context: routerContext,
134
- hydrate: false
135
- }),
136
- mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
137
- // So we can inject it only when streaming ssr
138
- /* @__PURE__ */ _jsx(DeferredDataScripts, {
139
- nonce,
140
- context: routerContext,
141
- useJsonScript
142
- }),
143
- mode === "stream" && JSX_SHELL_STREAM_END_MARK
144
- ]
145
- });
146
- return App ? /* @__PURE__ */ _jsx(App, {
147
- children: routerWrapper
148
- }) : routerWrapper;
149
- };
148
+ return App ? /* @__PURE__ */ _jsx(App, {
149
+ children: routerWrapper
150
+ }) : routerWrapper;
150
151
  };
151
- return getRouteApp();
152
- }
153
- };
152
+ };
153
+ return getRouteApp();
154
+ });
154
155
  }
155
156
  };
156
157
  };
@@ -11,8 +11,8 @@ var statePlugin = function() {
11
11
  var entrypoint = param.entrypoint, plugins = param.plugins;
12
12
  var _getEntryOptions;
13
13
  var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
14
- var userConfig = api.useResolvedConfigContext();
15
- var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, metaName = _api_useAppContext.metaName;
14
+ var userConfig = api.getNormalizedConfig();
15
+ var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, metaName = _api_getAppContext.metaName;
16
16
  var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
17
17
  if (stateConfig) {
18
18
  plugins.push({
@@ -1,8 +1,7 @@
1
1
  import cookieTool from "cookie";
2
- import { getGlobalAppInit } from "../context";
2
+ import { getGlobalAppInit, getGlobalInternalRuntimeContext } from "../context";
3
3
  import { getInitialContext } from "../context/runtime";
4
4
  import { createLoaderManager } from "../loader/loaderManager";
5
- import { getGlobalRunner } from "../plugin/runner";
6
5
  import { wrapRuntimeContextProvider } from "../react/wrapper";
7
6
  import { hydrateRoot } from "./hydrate";
8
7
  const IS_REACT18 = process.env.IS_REACT18 === "true";
@@ -48,10 +47,13 @@ function isClientArgs(id) {
48
47
  return typeof id === "undefined" || typeof id === "string" || typeof HTMLElement !== "undefined" && id instanceof HTMLElement;
49
48
  }
50
49
  async function render(App, id) {
51
- const runner = getGlobalRunner();
52
- const context = getInitialContext(runner);
50
+ const context = getInitialContext();
53
51
  const runBeforeRender = async (context2) => {
54
- await runner.beforeRender(context2);
52
+ const internalRuntimeContext = getGlobalInternalRuntimeContext();
53
+ const api = internalRuntimeContext.pluginAPI;
54
+ api.updateRuntimeContext(context2);
55
+ const hooks = internalRuntimeContext.hooks;
56
+ await hooks.onBeforeRender.call(context2);
55
57
  const init = getGlobalAppInit();
56
58
  return init === null || init === void 0 ? void 0 : init(context2);
57
59
  };
@@ -120,5 +122,9 @@ async function hydrateWithReact17(App, rootElement, callback) {
120
122
  return root;
121
123
  }
122
124
  export {
123
- render
125
+ hydrateWithReact17,
126
+ hydrateWithReact18,
127
+ render,
128
+ renderWithReact17,
129
+ renderWithReact18
124
130
  };
@@ -0,0 +1,54 @@
1
+ function transformHookRunner(hookRunnerName) {
2
+ switch (hookRunnerName) {
3
+ case "beforeRender":
4
+ return "onBeforeRender";
5
+ default:
6
+ return hookRunnerName;
7
+ }
8
+ }
9
+ function handleSetupResult(setupResult, api) {
10
+ if (!setupResult) {
11
+ return;
12
+ }
13
+ Object.keys(setupResult).forEach((key) => {
14
+ const fn = setupResult[key];
15
+ if (typeof fn === "function") {
16
+ const newAPI = transformHookRunner(key);
17
+ if (api[newAPI]) {
18
+ if (key === "beforeRender") {
19
+ api[newAPI](async (...params) => {
20
+ await fn(...params);
21
+ });
22
+ } else {
23
+ api[newAPI]((...params) => {
24
+ const res = fn(...params);
25
+ return res;
26
+ });
27
+ }
28
+ }
29
+ }
30
+ });
31
+ }
32
+ function getHookRunners(runtimeContext) {
33
+ const { _internalContext } = runtimeContext;
34
+ const { hooks } = _internalContext;
35
+ return {
36
+ beforeRender: async (context) => {
37
+ return hooks.onBeforeRender.call(context);
38
+ },
39
+ wrapRoot: (App) => {
40
+ return hooks.wrapRoot.call(App);
41
+ },
42
+ pickContext: (context) => {
43
+ return hooks.pickContext.call(context);
44
+ },
45
+ modifyRuntimeConfig: (config) => {
46
+ return hooks.modifyRuntimeConfig.call(config);
47
+ }
48
+ };
49
+ }
50
+ export {
51
+ getHookRunners,
52
+ handleSetupResult,
53
+ transformHookRunner
54
+ };
@@ -0,0 +1,18 @@
1
+ import { getHookRunners } from "./hooks";
2
+ const compatPlugin = () => ({
3
+ name: "@modern-js/runtime-plugin-compat",
4
+ _registryApi: (getRuntimeContext) => {
5
+ return {
6
+ useRuntimeConfigContext: () => {
7
+ const { _internalContext } = getRuntimeContext();
8
+ return _internalContext.config;
9
+ },
10
+ useHookRunners: () => {
11
+ return getHookRunners(getRuntimeContext());
12
+ }
13
+ };
14
+ }
15
+ });
16
+ export {
17
+ compatPlugin
18
+ };
@@ -2,26 +2,25 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
3
3
  import React, { useContext, useMemo } from "react";
4
4
  import { hydrateRoot as ModernHydrateRoot } from "./browser/hydrate";
5
- import { getGlobalAppInit } from "./context";
5
+ import { getGlobalAppInit, getGlobalInternalRuntimeContext } from "./context";
6
6
  import { RuntimeReactContext } from "./context/runtime";
7
7
  import { createLoaderManager } from "./loader/loaderManager";
8
8
  import { registerPlugin } from "./plugin";
9
- import { getGlobalRunner } from "./plugin/runner";
10
9
  import { wrapRuntimeContextProvider } from "./react/wrapper";
11
10
  const IS_REACT18 = process.env.IS_REACT18 === "true";
12
11
  function isClientArgs(id) {
13
12
  return typeof id === "string" || typeof HTMLElement !== "undefined" && id instanceof HTMLElement;
14
13
  }
15
- const getInitialContext = (runner) => ({
14
+ const getInitialContext = () => ({
16
15
  loaderManager: createLoaderManager({}),
17
- runner,
18
16
  isBrowser: true,
19
17
  routeManifest: typeof window !== "undefined" && window[ROUTE_MANIFEST]
20
18
  });
21
- const createApp = ({ plugins, runtime, props: globalProps }) => {
22
- const runner = registerPlugin(plugins, {
19
+ const createApp = ({ plugins, props: globalProps }) => {
20
+ const context = registerPlugin(plugins, {
23
21
  plugins: []
24
- }, runtime);
22
+ });
23
+ const hooks = context.hooks;
25
24
  return (App) => {
26
25
  const WrapperComponent = (props) => {
27
26
  return /* @__PURE__ */ React.createElement(App || React.Fragment, App ? {
@@ -31,7 +30,7 @@ const createApp = ({ plugins, runtime, props: globalProps }) => {
31
30
  ...props
32
31
  }) : child));
33
32
  };
34
- const WrapperApp = runner.wrapRoot(WrapperComponent);
33
+ const WrapperApp = hooks.wrapRoot.call(WrapperComponent);
35
34
  const WrapComponent = (props) => {
36
35
  const mergedProps = {
37
36
  ...props,
@@ -46,10 +45,13 @@ const createApp = ({ plugins, runtime, props: globalProps }) => {
46
45
  };
47
46
  const bootstrap = async (BootApp, id, root, ReactDOM) => {
48
47
  const App = BootApp;
49
- const runner = getGlobalRunner();
50
- const context = getInitialContext(runner);
48
+ const internalRuntimeContext = getGlobalInternalRuntimeContext();
49
+ const api = internalRuntimeContext.pluginAPI;
50
+ const hooks = internalRuntimeContext.hooks;
51
+ const context = getInitialContext();
52
+ api.updateRuntimeContext(context);
51
53
  const runBeforeRender = async (context2) => {
52
- await runner.beforeRender(context2);
54
+ await hooks.onBeforeRender.call(context2);
53
55
  const init = getGlobalAppInit();
54
56
  return init === null || init === void 0 ? void 0 : init(context2);
55
57
  };
@@ -152,7 +154,9 @@ const useRuntimeContext = () => {
152
154
  request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
153
155
  response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
154
156
  };
155
- const memoizedContext = useMemo(() => context.runner.pickContext(pickedContext), [
157
+ const internalRuntimeContext = getGlobalInternalRuntimeContext();
158
+ const hooks = internalRuntimeContext.hooks;
159
+ const memoizedContext = useMemo(() => hooks.pickContext.call(pickedContext), [
156
160
  context
157
161
  ]);
158
162
  return memoizedContext;
@@ -7,6 +7,12 @@ function setGlobalContext(context) {
7
7
  globalContext.appConfig = typeof context.appConfig === "function" ? context.appConfig() : context.appConfig;
8
8
  globalContext.layoutApp = context.layoutApp;
9
9
  }
10
+ function setGlobalInternalRuntimeContext(context) {
11
+ globalContext.internalRuntimeContext = context;
12
+ }
13
+ function getGlobalInternalRuntimeContext() {
14
+ return globalContext.internalRuntimeContext;
15
+ }
10
16
  function getGlobalApp() {
11
17
  return globalContext.App;
12
18
  }
@@ -29,8 +35,10 @@ export {
29
35
  getGlobalApp,
30
36
  getGlobalAppConfig,
31
37
  getGlobalAppInit,
38
+ getGlobalInternalRuntimeContext,
32
39
  getGlobalLayoutApp,
33
40
  getGlobalRoutes,
34
41
  getInitialContext,
35
- setGlobalContext
42
+ setGlobalContext,
43
+ setGlobalInternalRuntimeContext
36
44
  };
@@ -3,9 +3,8 @@ import { createContext } from "react";
3
3
  import { createLoaderManager } from "../loader/loaderManager";
4
4
  const RuntimeReactContext = createContext({});
5
5
  const ServerRouterContext = createContext({});
6
- const getInitialContext = (runner, isBrowser = true, routeManifest) => ({
6
+ const getInitialContext = (isBrowser = true, routeManifest) => ({
7
7
  loaderManager: createLoaderManager({}),
8
- runner,
9
8
  isBrowser,
10
9
  routeManifest: routeManifest || typeof window !== "undefined" && window[ROUTE_MANIFEST]
11
10
  });
@@ -1,4 +1,3 @@
1
- import { runtime } from "./plugin";
2
1
  import { defineConfig, getConfig, defineRuntimeConfig } from "./config";
3
2
  export * from "./compatible";
4
3
  import { RuntimeReactContext, ServerRouterContext } from "./context/runtime";
@@ -9,6 +8,5 @@ export {
9
8
  ServerRouterContext,
10
9
  defineConfig,
11
10
  defineRuntimeConfig,
12
- getConfig,
13
- runtime
11
+ getConfig
14
12
  };
@@ -1,24 +0,0 @@
1
- import { createAsyncInterruptWorkflow, createContext, createManager, createSyncParallelWorkflow, createWaterfall } from "@modern-js/plugin";
2
- const RuntimeConfigContext = createContext({});
3
- const useRuntimeConfigContext = () => RuntimeConfigContext.use().value;
4
- const wrapRoot = createWaterfall();
5
- const beforeRender = createAsyncInterruptWorkflow();
6
- const pickContext = createWaterfall();
7
- const modifyRuntimeConfig = createSyncParallelWorkflow();
8
- const runtimeHooks = {
9
- beforeRender,
10
- wrapRoot,
11
- pickContext,
12
- modifyRuntimeConfig
13
- };
14
- const runtimePluginAPI = {
15
- useRuntimeConfigContext
16
- };
17
- const createRuntime = () => createManager(runtimeHooks, runtimePluginAPI);
18
- const runtime = createRuntime();
19
- export {
20
- RuntimeConfigContext,
21
- createRuntime,
22
- runtime,
23
- useRuntimeConfigContext
24
- };
@@ -1,19 +1,21 @@
1
+ import { runtime } from "@modern-js/plugin-v2/runtime";
1
2
  import { merge } from "@modern-js/runtime-utils/merge";
2
- import { RuntimeConfigContext, runtime } from "./base";
3
- import { getGlobalRunner, setGlobalRunner } from "./runner";
4
- export * from "./base";
5
- function setupConfigContext() {
6
- const runner = getGlobalRunner();
7
- const configs = runner.modifyRuntimeConfig();
8
- RuntimeConfigContext.set(merge({}, ...configs));
9
- }
10
- function registerPlugin(internalPlugins, runtimeConfig, customRuntime) {
3
+ import { compatPlugin } from "../compat";
4
+ import { handleSetupResult } from "../compat/hooks";
5
+ import { setGlobalInternalRuntimeContext } from "../context";
6
+ function registerPlugin(internalPlugins, runtimeConfig) {
11
7
  const { plugins = [] } = runtimeConfig || {};
12
- (customRuntime || runtime).usePlugin(...internalPlugins, ...plugins);
13
- const runner = (customRuntime || runtime).init();
14
- setGlobalRunner(runner);
15
- setupConfigContext();
16
- return runner;
8
+ const { runtimeContext } = runtime.run({
9
+ plugins: [
10
+ compatPlugin(),
11
+ ...internalPlugins,
12
+ ...plugins
13
+ ],
14
+ config: runtimeConfig || {},
15
+ handleSetupResult
16
+ });
17
+ setGlobalInternalRuntimeContext(runtimeContext);
18
+ return runtimeContext;
17
19
  }
18
20
  function mergeConfig(config, ...otherConfig) {
19
21
  return merge({}, config, ...otherConfig);
File without changes
@@ -1,16 +1,16 @@
1
1
  import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
2
2
  import { isBrowser } from "../../common";
3
3
  import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
4
- import { getGlobalApp } from "../context";
5
- import { getGlobalRunner } from "../plugin/runner";
4
+ import { getGlobalApp, getGlobalInternalRuntimeContext } from "../context";
6
5
  function createRoot(UserApp) {
7
6
  const App = UserApp || getGlobalApp();
8
7
  if (isBrowser()) {
9
8
  window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
10
9
  window._ROUTER_DATA = window._ROUTER_DATA || parsedJSONFromElement(ROUTER_DATA_JSON_ID);
11
10
  }
12
- const runner = getGlobalRunner();
13
- const WrapperApp = runner.wrapRoot(App);
11
+ const internalRuntimeContext = getGlobalInternalRuntimeContext();
12
+ const hooks = internalRuntimeContext.hooks;
13
+ const WrapperApp = hooks.wrapRoot.call(App);
14
14
  return WrapperApp;
15
15
  }
16
16
  export {
@@ -1,8 +1,7 @@
1
1
  import { getPathname, parseCookie, parseHeaders, parseQuery } from "@modern-js/runtime-utils/universal/request";
2
- import { getGlobalAppInit } from "../context";
2
+ import { getGlobalAppInit, getGlobalInternalRuntimeContext } from "../context";
3
3
  import { getInitialContext } from "../context/runtime";
4
4
  import { createLoaderManager } from "../loader/loaderManager";
5
- import { getGlobalRunner } from "../plugin/runner";
6
5
  import { createRoot } from "../react";
7
6
  import { CHUNK_CSS_PLACEHOLDER } from "./constants";
8
7
  import { getSSRConfigByEntry, getSSRMode } from "./utils";
@@ -66,11 +65,12 @@ const createRequestHandler = async (handleRequest) => {
66
65
  const requestHandler = async (request, options) => {
67
66
  var _context_routerContext, _context_routerContext1;
68
67
  const Root = createRoot();
69
- const runner = getGlobalRunner();
68
+ const internalRuntimeContext = getGlobalInternalRuntimeContext();
69
+ const hooks = internalRuntimeContext.hooks;
70
70
  const { routeManifest } = options.resource;
71
- const context = getInitialContext(runner, false, routeManifest);
71
+ const context = getInitialContext(false, routeManifest);
72
72
  const runBeforeRender = async (context2) => {
73
- const result = await runner.beforeRender(context2);
73
+ const result = await hooks.onBeforeRender.call(context2);
74
74
  if (typeof Response !== "undefined" && result instanceof Response) {
75
75
  return result;
76
76
  }
@@ -1,7 +1,7 @@
1
- import { createAsyncInterruptWorkflow, createWaterfall } from "@modern-js/plugin";
2
- const modifyRoutes = createWaterfall();
3
- const beforeCreateRoutes = createAsyncInterruptWorkflow();
1
+ import { createSyncHook } from "@modern-js/plugin-v2";
2
+ const modifyRoutes = createSyncHook();
3
+ const onBeforeCreateRoutes = createSyncHook();
4
4
  export {
5
- beforeCreateRoutes,
6
- modifyRoutes
5
+ modifyRoutes,
6
+ onBeforeCreateRoutes
7
7
  };