@bleedingdev/modern-js-runtime 3.5.0-ultramodern.10 → 3.5.0-ultramodern.100

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 (151) hide show
  1. package/dist/cjs/boundary-debugger/index.js +13 -3
  2. package/dist/cjs/cli/index.js +1 -11
  3. package/dist/cjs/cli/registry.js +18 -0
  4. package/dist/cjs/cli/ssr/index.js +3 -2
  5. package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +8 -4
  6. package/dist/cjs/core/browser/hydrate.js +16 -2
  7. package/dist/cjs/core/browser/index.js +19 -18
  8. package/dist/cjs/core/context/index.js +3 -0
  9. package/dist/cjs/core/context/public.js +49 -0
  10. package/dist/cjs/core/context/runtime.js +6 -8
  11. package/dist/cjs/core/react/wrapper.js +57 -0
  12. package/dist/cjs/core/server/federatedCss.js +7 -3
  13. package/dist/cjs/core/server/requestHandler.js +15 -45
  14. package/dist/cjs/core/server/requestResponse.js +83 -0
  15. package/dist/cjs/core/server/routerCleanup.js +16 -6
  16. package/dist/cjs/core/server/scriptOrder.js +13 -10
  17. package/dist/cjs/core/server/stream/afterTemplate.js +9 -5
  18. package/dist/cjs/core/server/stream/template.js +3 -3
  19. package/dist/cjs/core/server/string/index.js +3 -3
  20. package/dist/cjs/core/server/string/loadable.js +3 -11
  21. package/dist/cjs/index.js +7 -6
  22. package/dist/cjs/module-federation/consume-surface.js +199 -0
  23. package/dist/cjs/module-federation/distributed-ssr.js +134 -0
  24. package/dist/cjs/module-federation/index.js +258 -120
  25. package/dist/cjs/module-federation/last-known-good.js +124 -0
  26. package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +140 -0
  27. package/dist/cjs/module-federation/surface-resolution-types.js +61 -0
  28. package/dist/cjs/router/cli/code/nestedRoutes.js +3 -0
  29. package/dist/cjs/router/cli/code/templates.js +3 -2
  30. package/dist/cjs/router/cli/constants.js +1 -0
  31. package/dist/cjs/router/cli/nestedRoutesSpec.js +3 -1
  32. package/dist/cjs/router/runtime/hooks.js +7 -6
  33. package/dist/cjs/router/runtime/internal.js +30 -16
  34. package/dist/cjs/router/runtime/plugin.js +6 -7
  35. package/dist/cjs/router/runtime/provider.js +58 -12
  36. package/dist/esm/boundary-debugger/index.mjs +13 -3
  37. package/dist/esm/cli/code.mjs +12 -12
  38. package/dist/esm/cli/index.mjs +2 -12
  39. package/dist/esm/cli/registry.mjs +0 -0
  40. package/dist/esm/cli/ssr/index.mjs +3 -2
  41. package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +8 -4
  42. package/dist/esm/core/browser/hydrate.mjs +15 -4
  43. package/dist/esm/core/browser/index.mjs +15 -17
  44. package/dist/esm/core/context/index.mjs +1 -1
  45. package/dist/esm/core/context/public.mjs +5 -0
  46. package/dist/esm/core/context/runtime.mjs +4 -6
  47. package/dist/esm/core/react/wrapper.mjs +58 -1
  48. package/dist/esm/core/server/federatedCss.mjs +7 -3
  49. package/dist/esm/core/server/requestHandler.mjs +15 -45
  50. package/dist/esm/core/server/requestResponse.mjs +39 -0
  51. package/dist/esm/core/server/routerCleanup.mjs +11 -4
  52. package/dist/esm/core/server/scriptOrder.mjs +11 -8
  53. package/dist/esm/core/server/stream/afterTemplate.mjs +10 -6
  54. package/dist/esm/core/server/stream/template.mjs +3 -3
  55. package/dist/esm/core/server/string/index.mjs +3 -3
  56. package/dist/esm/core/server/string/loadable.mjs +3 -8
  57. package/dist/esm/exports/loadable.mjs +3 -3
  58. package/dist/esm/index.mjs +2 -1
  59. package/dist/esm/module-federation/consume-surface.mjs +158 -0
  60. package/dist/esm/module-federation/distributed-ssr.mjs +81 -0
  61. package/dist/esm/module-federation/index.mjs +6 -0
  62. package/dist/esm/module-federation/last-known-good.mjs +80 -0
  63. package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +100 -0
  64. package/dist/esm/module-federation/surface-resolution-types.mjs +8 -0
  65. package/dist/esm/router/cli/code/index.mjs +5 -5
  66. package/dist/esm/router/cli/code/nestedRoutes.mjs +3 -0
  67. package/dist/esm/router/cli/code/templates.mjs +3 -2
  68. package/dist/esm/router/cli/constants.mjs +1 -0
  69. package/dist/esm/router/cli/handler.mjs +3 -3
  70. package/dist/esm/router/cli/nestedRoutesSpec.mjs +3 -1
  71. package/dist/esm/router/runtime/hooks.mjs +7 -6
  72. package/dist/esm/router/runtime/internal.mjs +26 -18
  73. package/dist/esm/router/runtime/plugin.mjs +6 -7
  74. package/dist/esm/router/runtime/provider.mjs +56 -13
  75. package/dist/esm-node/boundary-debugger/index.mjs +13 -3
  76. package/dist/esm-node/cli/code.mjs +12 -12
  77. package/dist/esm-node/cli/index.mjs +2 -12
  78. package/dist/esm-node/cli/registry.mjs +1 -0
  79. package/dist/esm-node/cli/ssr/index.mjs +3 -2
  80. package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +8 -4
  81. package/dist/esm-node/core/browser/hydrate.mjs +15 -4
  82. package/dist/esm-node/core/browser/index.mjs +15 -17
  83. package/dist/esm-node/core/context/index.mjs +1 -1
  84. package/dist/esm-node/core/context/public.mjs +6 -0
  85. package/dist/esm-node/core/context/runtime.mjs +4 -6
  86. package/dist/esm-node/core/react/wrapper.mjs +58 -1
  87. package/dist/esm-node/core/server/federatedCss.mjs +7 -3
  88. package/dist/esm-node/core/server/requestHandler.mjs +15 -45
  89. package/dist/esm-node/core/server/requestResponse.mjs +40 -0
  90. package/dist/esm-node/core/server/routerCleanup.mjs +11 -4
  91. package/dist/esm-node/core/server/scriptOrder.mjs +11 -8
  92. package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -6
  93. package/dist/esm-node/core/server/stream/template.mjs +3 -3
  94. package/dist/esm-node/core/server/string/index.mjs +3 -3
  95. package/dist/esm-node/core/server/string/loadable.mjs +3 -8
  96. package/dist/esm-node/exports/loadable.mjs +3 -3
  97. package/dist/esm-node/index.mjs +2 -1
  98. package/dist/esm-node/module-federation/consume-surface.mjs +159 -0
  99. package/dist/esm-node/module-federation/distributed-ssr.mjs +82 -0
  100. package/dist/esm-node/module-federation/index.mjs +6 -0
  101. package/dist/esm-node/module-federation/last-known-good.mjs +81 -0
  102. package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +101 -0
  103. package/dist/esm-node/module-federation/surface-resolution-types.mjs +9 -0
  104. package/dist/esm-node/router/cli/code/index.mjs +5 -5
  105. package/dist/esm-node/router/cli/code/nestedRoutes.mjs +3 -0
  106. package/dist/esm-node/router/cli/code/templates.mjs +3 -2
  107. package/dist/esm-node/router/cli/constants.mjs +1 -0
  108. package/dist/esm-node/router/cli/handler.mjs +3 -3
  109. package/dist/esm-node/router/cli/nestedRoutesSpec.mjs +3 -1
  110. package/dist/esm-node/router/runtime/hooks.mjs +7 -6
  111. package/dist/esm-node/router/runtime/internal.mjs +26 -18
  112. package/dist/esm-node/router/runtime/plugin.mjs +6 -7
  113. package/dist/esm-node/router/runtime/provider.mjs +56 -13
  114. package/dist/types/boundary-debugger/index.d.ts +1 -1
  115. package/dist/types/cli/registry.d.ts +2 -0
  116. package/dist/types/common.d.ts +8 -1
  117. package/dist/types/core/browser/hydrate.d.ts +2 -1
  118. package/dist/types/core/browser/index.d.ts +4 -1
  119. package/dist/types/core/context/index.d.ts +26 -10
  120. package/dist/types/core/context/monitors/default.d.ts +10 -2
  121. package/dist/types/core/context/monitors/index.d.ts +1 -1
  122. package/dist/types/core/context/monitors/index.server.d.ts +2 -2
  123. package/dist/types/core/context/public.d.ts +27 -0
  124. package/dist/types/core/context/runtime.d.ts +12 -22
  125. package/dist/types/core/react/index.d.ts +1 -1
  126. package/dist/types/core/server/requestResponse.d.ts +15 -0
  127. package/dist/types/core/server/routerCleanup.d.ts +2 -1
  128. package/dist/types/core/server/scriptOrder.d.ts +1 -1
  129. package/dist/types/core/server/stream/shared.d.ts +2 -2
  130. package/dist/types/core/server/string/loadable.d.ts +0 -2
  131. package/dist/types/exports/head.d.ts +1 -1
  132. package/dist/types/index.d.ts +5 -5
  133. package/dist/types/internal.d.ts +0 -1
  134. package/dist/types/module-federation/consume-surface.d.ts +104 -0
  135. package/dist/types/module-federation/distributed-ssr.d.ts +61 -0
  136. package/dist/types/module-federation/index.d.ts +6 -0
  137. package/dist/types/module-federation/last-known-good.d.ts +72 -0
  138. package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +25 -0
  139. package/dist/types/module-federation/surface-resolution-types.d.ts +23 -0
  140. package/dist/types/router/cli/constants.d.ts +1 -0
  141. package/dist/types/router/runtime/hooks.d.ts +10 -6
  142. package/dist/types/router/runtime/internal.d.ts +13 -3
  143. package/dist/types/router/runtime/plugin.d.ts +1 -1
  144. package/dist/types/router/runtime/plugin.node.d.ts +1 -1
  145. package/dist/types/router/runtime/provider.d.ts +28 -11
  146. package/dist/types/router/runtime/types.d.ts +27 -5
  147. package/package.json +47 -27
  148. package/dist/cjs/exports/tanstack-router.js +0 -83
  149. package/dist/esm/exports/tanstack-router.mjs +0 -30
  150. package/dist/esm-node/exports/tanstack-router.mjs +0 -31
  151. package/dist/types/exports/tanstack-router.d.ts +0 -88
@@ -13,46 +13,89 @@ function reportUnsupportedProviderRegistryHooks(providerPlugin) {
13
13
  if (unsupportedHookNames.length > 0) console.warn(`[@modern-js/runtime] The router provider "${providerPlugin.name}" declares registry hooks outside the router hook contract: ${unsupportedHookNames.join(', ')}. These hooks are not registered when the provider is resolved through \`runtime.router.framework\` — declare them on a separate runtime plugin instead.`);
14
14
  return unsupportedHookNames;
15
15
  }
16
- const REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v2');
16
+ function createRouterProviderRealm(registrations) {
17
+ const providers = new Map();
18
+ let defaultProvider;
19
+ for (const registration of registrations){
20
+ if (!registration.name) throw new Error('[@modern-js/runtime] A router provider realm cannot contain an unnamed provider.');
21
+ if (providers.has(registration.name)) throw new Error(`[@modern-js/runtime] Router provider "${registration.name}" is declared more than once in the same runtime realm.`);
22
+ if (true === registration.isDefault && void 0 !== defaultProvider && defaultProvider !== registration.name) throw new Error(`[@modern-js/runtime] Router provider realm declares both "${defaultProvider}" and "${registration.name}" as defaults.`);
23
+ providers.set(registration.name, registration.factory);
24
+ if (true === registration.isDefault) defaultProvider = registration.name;
25
+ }
26
+ const providerNames = Object.freeze([
27
+ ...providers.keys()
28
+ ]);
29
+ return Object.freeze({
30
+ ...defaultProvider ? {
31
+ defaultProvider
32
+ } : {},
33
+ get: (name)=>providers.get(name),
34
+ names: ()=>providerNames
35
+ });
36
+ }
37
+ const REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v3');
38
+ const LEGACY_V2_REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v2');
17
39
  function getRegistry() {
18
40
  const host = globalThis;
19
41
  host[REGISTRY_SLOT] ??= {
20
42
  providers: new Map(),
43
+ duplicateProviders: new Set(),
21
44
  warnedDuplicates: new Set()
22
45
  };
46
+ host[REGISTRY_SLOT].duplicateProviders ??= new Set();
23
47
  host[REGISTRY_SLOT].warnedDuplicates ??= new Set();
24
48
  return host[REGISTRY_SLOT];
25
49
  }
50
+ function getLegacyV2Registry() {
51
+ const host = globalThis;
52
+ return host[LEGACY_V2_REGISTRY_SLOT];
53
+ }
26
54
  function registerRouterProvider(name, factory, options = {}) {
27
55
  const registry = getRegistry();
28
56
  const existing = registry.providers.get(name);
29
57
  if (void 0 !== existing) {
30
- if (existing !== factory && !registry.warnedDuplicates.has(name)) {
31
- registry.warnedDuplicates.add(name);
32
- console.warn(`[@modern-js/runtime] The router provider "${name}" was registered more than once with different module instances; keeping the first registration. This usually means two copies of the providing plugin were bundled — for Module Federation, add the provider runtime (e.g. '@modern-js/plugin-tanstack/runtime') to the shared modules of both the host and the remote to deduplicate it.`);
33
- }
58
+ if (existing !== factory) registry.duplicateProviders.add(name);
34
59
  return;
35
60
  }
36
- if (true !== options.isDefault) {
37
- if (void 0 !== registry.nonDefaultProvider && registry.nonDefaultProvider !== name) throw new Error(`[@modern-js/runtime] Cannot register router provider "${name}": the competing router provider "${registry.nonDefaultProvider}" is already registered. Only one non-default router provider may be installed at a time — remove one of the router plugins.`);
38
- registry.nonDefaultProvider = name;
39
- } else registry.defaultProvider = name;
61
+ if (true === options.isDefault) registry.defaultProvider = name;
40
62
  registry.providers.set(name, factory);
41
63
  }
42
64
  function resolveRouterProvider(framework, options = {}) {
65
+ if (void 0 !== options.realm) {
66
+ const name = framework || options.realm.defaultProvider;
67
+ const realmProviderNames = options.realm.names();
68
+ if (void 0 === name) throw new Error(`[@modern-js/runtime] The app-owned router provider realm does not declare a default provider. Available realm providers: ${realmProviderNames.join(', ') || '(none)'}.`);
69
+ const factory = options.realm.get(name);
70
+ if (void 0 === factory) throw new Error(`[@modern-js/runtime] Router provider "${name}" is not registered in the app-owned router provider realm. Available realm providers: ${realmProviderNames.join(', ') || '(none)'}. Compatibility registry fallback is disabled for app-owned realms.`);
71
+ return factory;
72
+ }
43
73
  const registry = getRegistry();
44
- const name = framework || registry.defaultProvider || options.localDefault?.name;
74
+ const legacyV2Registry = getLegacyV2Registry();
75
+ const name = framework || options.localDefault?.name || registry.defaultProvider || legacyV2Registry?.defaultProvider;
45
76
  if (void 0 === name) throw new Error('[@modern-js/runtime] No default router provider is registered. This is a bug in the runtime setup.');
46
77
  if (void 0 !== options.localDefault && name === options.localDefault.name) return options.localDefault.factory;
47
78
  const factory = registry.providers.get(name);
48
- if (void 0 !== factory) return factory;
79
+ if (void 0 !== factory) {
80
+ if (registry.duplicateProviders.has(name) && !registry.warnedDuplicates.has(name)) {
81
+ registry.warnedDuplicates.add(name);
82
+ console.warn(`[@modern-js/runtime] The router provider "${name}" was registered more than once with different module instances, and a router wrapper without an app-owned provider realm is resolving the mixed-version compatibility fallback. The fallback is keeping the first registration. Modern router wrappers isolate app-owned realms automatically. For an older wrapper, share the provider runtime between Module Federation host and remotes or upgrade every app to a realm-aware runtime.`);
83
+ }
84
+ return factory;
85
+ }
86
+ const legacyV2Factory = legacyV2Registry?.providers.get(name);
87
+ if (void 0 !== legacyV2Factory) return legacyV2Factory;
49
88
  if ('tanstack' === name) throw new Error("[@modern-js/runtime] `runtime.router.framework` is set to \"tanstack\", but no TanStack router provider is registered. Install @modern-js/plugin-tanstack, add `tanstackRouterPlugin()` to the `plugins` array in modern.config.ts, and make sure '@modern-js/plugin-tanstack/runtime' is imported (e.g. in modern.runtime.ts).");
50
89
  throw new Error(`[@modern-js/runtime] Unknown router framework "${name}". Registered providers: ${[
51
- ...registry.providers.keys()
90
+ ...new Set([
91
+ ...registry.providers.keys(),
92
+ ...legacyV2Registry?.providers.keys() ?? []
93
+ ])
52
94
  ].join(', ') || '(none)'}. Install and register the plugin that provides this router framework.`);
53
95
  }
54
96
  function unsafe_resetRouterProvidersForTesting() {
55
97
  const host = globalThis;
56
98
  delete host[REGISTRY_SLOT];
99
+ delete host[LEGACY_V2_REGISTRY_SLOT];
57
100
  }
58
- export { registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks, unsafe_resetRouterProvidersForTesting };
101
+ export { createRouterProviderRealm, registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks, unsafe_resetRouterProvidersForTesting };
@@ -1,4 +1,4 @@
1
- import type { RuntimePlugin } from '../core';
1
+ import type { RuntimePlugin } from '../common';
2
2
  export type BoundaryDebugEntry = {
3
3
  appId: string;
4
4
  color?: string;
@@ -0,0 +1,2 @@
1
+ /** Type-only contract for generated runtime registry aliases. */
2
+ export {};
@@ -1,5 +1,12 @@
1
- import type { RuntimePlugin } from './core/plugin';
2
1
  export declare const isBrowser: () => boolean;
2
+ export type RuntimePlugin<Extends = unknown> = {
3
+ name?: string;
4
+ registryHooks?: Extends extends {
5
+ extendHooks: infer Hooks;
6
+ } ? Hooks : Record<string, unknown>;
7
+ setup?: (...args: any[]) => unknown;
8
+ [key: string]: unknown;
9
+ };
3
10
  export interface RuntimeConfig {
4
11
  plugins?: RuntimePlugin[];
5
12
  [key: string]: any;
@@ -1,5 +1,6 @@
1
1
  import type React from 'react';
2
- import type { Root } from 'react-dom/client';
2
+ import { type Root } from 'react-dom/client';
3
3
  import type { TRuntimeContext } from '../context/runtime';
4
4
  export declare const isReact18: () => boolean;
5
+ export declare function hydrateWithReact(App: React.ReactElement, rootElement: HTMLElement): Promise<Root>;
5
6
  export declare function hydrateRoot(App: React.ReactElement, context: TRuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement, callback?: () => void) => Promise<HTMLElement | Root>): Promise<HTMLElement | Root>;
@@ -1,9 +1,12 @@
1
1
  import type React from 'react';
2
+ import { hydrateWithReact } from './hydrate';
3
+ export { hydrateWithReact };
2
4
  export type RenderFunc = typeof render;
3
5
  export declare function render(App: React.ReactElement<{
4
6
  basename: string;
5
7
  }>, id?: HTMLElement | string): Promise<HTMLElement | import("react-dom/client").Root>;
8
+ /** Bind a client renderer to the runtime context that owns a nested app root. */
9
+ export declare function createNestedAppRenderer(): RenderFunc;
6
10
  export declare function renderWithReact18(App: React.ReactElement, rootElement: HTMLElement): Promise<import("react-dom/client").Root>;
7
11
  export declare function renderWithReact17(App: React.ReactElement, rootElement: HTMLElement): Promise<HTMLElement>;
8
- export declare function hydrateWithReact18(App: React.ReactElement, rootElement: HTMLElement): Promise<import("react-dom/client").Root>;
9
12
  export declare function hydrateWithReact17(App: React.ReactElement, rootElement: HTMLElement, callback?: () => void): Promise<any>;
@@ -1,13 +1,29 @@
1
- import type { InternalRuntimeContext } from '@modern-js/plugin';
2
- import type { NestedRoute, PageRoute } from '@modern-js/types';
3
1
  import type React from 'react';
4
- import type { RuntimeExtends } from '../plugin/types';
5
2
  import type { ServerPayload } from './serverPayload/index';
3
+ export type RuntimeRoute = {
4
+ children?: RuntimeRoute[];
5
+ routes?: RuntimeRoute[];
6
+ [key: string]: any;
7
+ };
8
+ type RuntimeHookCaller = {
9
+ call: (...args: any[]) => any;
10
+ [key: string]: unknown;
11
+ };
12
+ type RuntimeHooks = Record<string, RuntimeHookCaller>;
13
+ type RuntimePluginAPI = {
14
+ updateRuntimeContext?: (context: unknown) => unknown;
15
+ [key: string]: any;
16
+ };
17
+ type InternalRuntimeContextLike = {
18
+ hooks: RuntimeHooks;
19
+ pluginAPI?: RuntimePluginAPI;
20
+ [key: string]: any;
21
+ };
6
22
  export { DefaultNotFound } from '../../router/runtime/DefaultNotFound';
7
23
  export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, type RouterExtendsHooks, } from '../../router/runtime/hooks';
8
24
  export { applyRouterRuntimeState, applyRouterServerPrepareResult, cleanupRouterRuntimeState, createRouterRuntimeState, createRouterServerSnapshot, getRouterHydrationScripts, getRouterMatchedRouteIds, getRouterRuntimeState, getRouterServerSnapshot, type RouterLifecycleContext, type RouterLifecyclePhase, } from '../../router/runtime/lifecycle';
9
- export { type RouterProviderFactory, type RouterProviderPlugin, registerRouterProvider, resolveRouterProvider, routerProviderRegistryHooks, } from '../../router/runtime/provider';
10
- export type { BuiltInRouterFramework, InternalRouterRuntimeState, InternalRouterServerSnapshot, RouterFramework, RouterRouteMatchSnapshot, RouterServerPrepareResult, } from '../../router/runtime/types';
25
+ export { createRouterProviderRealm, type RouterProviderFactory, type RouterProviderPlugin, type RouterProviderRealm, type RouterProviderRegistration, registerRouterProvider, resolveRouterProvider, routerProviderRegistryHooks, } from '../../router/runtime/provider';
26
+ export type { BuiltInRouterFramework, InternalRouterRuntimeState, InternalRouterServerSnapshot, LoaderFunction, LoaderFunctionArgs, ModernRoute, RouterFramework, RouterRouteMatchSnapshot, RouterServerPrepareResult, } from '../../router/runtime/types';
11
27
  export { createRuntimeContextExtension, type RuntimeContextExtension, } from './extensions';
12
28
  export { getInitialContext, InternalRuntimeContext, RuntimeContext, type TInternalRuntimeContext, type TRuntimeContext, } from './runtime';
13
29
  export type { PayloadRoute, ServerPayload } from './serverPayload/index';
@@ -20,7 +36,7 @@ interface GlobalContext {
20
36
  /**
21
37
  * nest router and page router config
22
38
  */
23
- routes?: (NestedRoute | PageRoute)[];
39
+ routes?: RuntimeRoute[];
24
40
  /**
25
41
  * nest router init function
26
42
  */
@@ -33,7 +49,7 @@ interface GlobalContext {
33
49
  * Entry basename for routing
34
50
  */
35
51
  basename?: string;
36
- internalRuntimeContext?: InternalRuntimeContext<RuntimeExtends>;
52
+ internalRuntimeContext?: InternalRuntimeContextLike;
37
53
  /**
38
54
  * RSCRoot
39
55
  */
@@ -48,9 +64,9 @@ export declare function getGlobalEnableRsc(): boolean | undefined;
48
64
  export declare function setGlobalContext(context: Omit<GlobalContext, 'internalRuntimeContext'>): void;
49
65
  export declare function getCurrentEntryName(): string | undefined;
50
66
  export declare function getGlobalRSCRoot(): React.ComponentType<{}> | undefined;
51
- export declare function setGlobalInternalRuntimeContext(context: InternalRuntimeContext<RuntimeExtends>): void;
52
- export declare function getGlobalInternalRuntimeContext(): InternalRuntimeContext<Required<import("@modern-js/plugin").RuntimePluginExtends<import("../plugin/types").RuntimeConfig, import("./runtime").TInternalRuntimeContext, {}, {}>>>;
67
+ export declare function setGlobalInternalRuntimeContext(context: InternalRuntimeContextLike): void;
68
+ export declare function getGlobalInternalRuntimeContext(): InternalRuntimeContextLike;
53
69
  export declare function getGlobalApp(): React.ComponentType<{}> | undefined;
54
- export declare function getGlobalRoutes(): undefined | (NestedRoute | PageRoute)[];
70
+ export declare function getGlobalRoutes(): undefined | RuntimeRoute[];
55
71
  export declare function getGlobalLayoutApp(): React.ComponentType<{}> | undefined;
56
72
  export declare function getGlobalBasename(): string | undefined;
@@ -1,2 +1,10 @@
1
- import type { Monitors } from '@modern-js/types';
2
- export declare const defaultMonitors: Omit<Monitors, 'push'>;
1
+ export type RuntimeMonitors = {
2
+ counter: (name: string, ...args: any[]) => void;
3
+ info: (...args: any[]) => void;
4
+ debug: (...args: any[]) => void;
5
+ trace: (...args: any[]) => void;
6
+ warn: (...args: any[]) => void;
7
+ error: (...args: any[]) => void;
8
+ timing: (name: string, dur: number, ...args: any[]) => void;
9
+ };
10
+ export declare const defaultMonitors: RuntimeMonitors;
@@ -1 +1 @@
1
- export declare const getMonitors: () => Omit<import("@modern-js/types").Monitors, "push">;
1
+ export declare const getMonitors: () => import("./default").RuntimeMonitors;
@@ -1,2 +1,2 @@
1
- import type { Monitors } from '@modern-js/types';
2
- export declare const getMonitors: () => Omit<Monitors, 'push'>;
1
+ import { type RuntimeMonitors } from './default';
2
+ export declare const getMonitors: () => RuntimeMonitors;
@@ -0,0 +1,27 @@
1
+ type RuntimeRequest = Record<string, unknown>;
2
+ type RuntimeResponse = Record<string, unknown>;
3
+ export type RequestContext = {
4
+ request: RuntimeRequest;
5
+ response: RuntimeResponse;
6
+ };
7
+ export interface TRuntimeContext {
8
+ initialData?: Record<string, unknown>;
9
+ isBrowser: boolean;
10
+ routes?: unknown[];
11
+ requestContext: RequestContext;
12
+ /**
13
+ * @deprecated Use `requestContext` instead
14
+ */
15
+ context: RequestContext;
16
+ [key: string]: unknown;
17
+ }
18
+ export declare const RuntimeContext: import("react").Context<TRuntimeContext>;
19
+ /**
20
+ * deprecated, use RuntimeContext instead
21
+ */
22
+ export declare const ReactRuntimeContext: import("react").Context<TRuntimeContext>;
23
+ /**
24
+ * @deprecated use use(RuntimeContext) instead
25
+ */
26
+ export declare const useRuntimeContext: () => TRuntimeContext;
27
+ export {};
@@ -1,36 +1,26 @@
1
1
  import type { RouteObject, StaticHandlerContext } from '@modern-js/runtime-utils/router';
2
+ import type { BaseSSRServerContext } from '@modern-js/types';
2
3
  import type { RouteManifest } from '../../router/runtime/types';
3
- import type { RequestContext, SSRServerContext } from '../types';
4
- export interface TRuntimeContext {
5
- initialData?: Record<string, unknown>;
6
- isBrowser: boolean;
7
- routes?: RouteObject[];
8
- requestContext: RequestContext;
9
- /**
10
- * @deprecated Use `requestContext` instead
11
- */
12
- context: RequestContext;
13
- [key: string]: unknown;
14
- }
4
+ import { type TRuntimeContext } from './public';
5
+ export type InternalSSRContext = {
6
+ request: BaseSSRServerContext['request'] & {
7
+ raw?: Request;
8
+ };
9
+ response: BaseSSRServerContext['response'];
10
+ [key: string]: any;
11
+ };
12
+ export { ReactRuntimeContext, RuntimeContext, type TRuntimeContext, useRuntimeContext, } from './public';
15
13
  /**
16
14
  * InternalRuntimeContext used internally and by plugins
17
15
  */
18
16
  export interface TInternalRuntimeContext extends TRuntimeContext {
19
17
  routeManifest?: RouteManifest;
18
+ routes?: RouteObject[];
20
19
  routerContext?: StaticHandlerContext;
21
20
  unstable_getBlockNavState?: () => boolean;
22
- ssrContext?: SSRServerContext;
21
+ ssrContext?: InternalSSRContext;
23
22
  _internalContext?: any;
24
23
  _internalRouterBaseName?: any;
25
24
  }
26
25
  export declare const InternalRuntimeContext: import("react").Context<TInternalRuntimeContext>;
27
- export declare const RuntimeContext: import("react").Context<TRuntimeContext>;
28
- /**
29
- * deprecated, use RuntimeContext instead
30
- */
31
- export declare const ReactRuntimeContext: import("react").Context<TRuntimeContext>;
32
26
  export declare const getInitialContext: (isBrowser?: boolean, routeManifest?: RouteManifest) => TInternalRuntimeContext;
33
- /**
34
- * @deprecated use use(RuntimeContext) instead
35
- */
36
- export declare const useRuntimeContext: () => TRuntimeContext;
@@ -1,2 +1,2 @@
1
1
  import type React from 'react';
2
- export declare function createRoot(UserApp?: React.ComponentType | null): React.ComponentType<any>;
2
+ export declare function createRoot(UserApp?: React.ComponentType | null): any;
@@ -0,0 +1,15 @@
1
+ import type { OnError } from '@modern-js/app-tools';
2
+ import type { TInternalRuntimeContext } from '../context';
3
+ import type { RouterCleanup } from './routerCleanup';
4
+ export type ResponseProxy = {
5
+ headers: Record<string, string>;
6
+ status: number;
7
+ };
8
+ export type RedirectContext = {
9
+ enableRsc: boolean;
10
+ isRSCNavigation: boolean;
11
+ basename: string;
12
+ };
13
+ export declare const applyRouterSnapshotResult: (context: TInternalRuntimeContext, onError: OnError) => void;
14
+ export declare const createLoaderRedirectResponse: (beforeRenderResult: Response | undefined, redirectCtx: RedirectContext) => Response | undefined;
15
+ export declare const finalizeRenderResponse: (response: Response, responseProxy: ResponseProxy, redirectCtx: RedirectContext, routerCleanup: RouterCleanup) => Response;
@@ -24,5 +24,6 @@ export type RouterCleanup = {
24
24
  */
25
25
  deferUntilBodyDone: (response: Response) => Response;
26
26
  };
27
- export declare function withRouterCleanup<T>(runtimeContext: TInternalRuntimeContext, onError: OnError, callback: (routerCleanup: RouterCleanup) => Promise<T>): Promise<T>;
27
+ export declare function runWithRouterCleanupOnError<T>(routerCleanup: RouterCleanup, callback: () => Promise<T> | T): Promise<T>;
28
+ export declare function finishWithRouterCleanup<T>(routerCleanup: RouterCleanup, callback: () => Promise<T> | T): Promise<T>;
28
29
  export declare function createRouterCleanup(runtimeContext: TInternalRuntimeContext, onError: OnError): RouterCleanup;
@@ -9,7 +9,7 @@ type ScriptChunkLike = {
9
9
  filename?: string;
10
10
  url?: string;
11
11
  };
12
- export declare function getMatchedRouteAssets(runtimeContext: TInternalRuntimeContext, routeManifest?: RouteManifestLike): string[];
12
+ export declare function getMatchedRouteChunks<T>(runtimeContext: TInternalRuntimeContext, routeManifest: RouteManifestLike | undefined, routeAssetToChunk: (asset: string) => T): T[];
13
13
  export declare const orderHydrationScriptChunks: <T extends ScriptChunkLike>({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName, }: {
14
14
  asyncEntryChunks: T[];
15
15
  collectedChunks: T[];
@@ -1,7 +1,7 @@
1
1
  import type { OnError } from '@modern-js/app-tools';
2
2
  import type { ClientManifest as RscClientManifest, ServerManifest as RscServerManifest, SSRManifest as RscSSRManifest } from '@modern-js/types/server';
3
3
  import type React from 'react';
4
- import type { TRuntimeContext } from '../../context';
4
+ import type { TInternalRuntimeContext } from '../../context';
5
5
  import type { HandleRequestConfig } from '../requestHandler';
6
6
  import type { RenderStreaming, SSRConfig } from '../shared';
7
7
  export type RscManifest = {
@@ -11,7 +11,7 @@ export type RscManifest = {
11
11
  entryCssFiles?: Record<string, string[]>;
12
12
  };
13
13
  export type CreateReadableStreamFromElementOptions = {
14
- runtimeContext: TRuntimeContext;
14
+ runtimeContext: TInternalRuntimeContext;
15
15
  config: HandleRequestConfig;
16
16
  ssrConfig: SSRConfig;
17
17
  htmlTemplate: string;
@@ -1,7 +1,6 @@
1
1
  import type { ReactElement } from 'react';
2
2
  import type { TInternalRuntimeContext } from '../../context';
3
3
  import type { ChunkSet, Collector } from './types';
4
- export { orderHydrationScriptChunks } from '../scriptOrder';
5
4
  declare module '@loadable/server' {
6
5
  interface ChunkExtractor {
7
6
  chunks: string[];
@@ -30,7 +29,6 @@ export declare class LoadableCollector implements Collector {
30
29
  private options;
31
30
  private extractor?;
32
31
  constructor(options: LoadableCollectorOptions);
33
- private getMatchedRouteChunks;
34
32
  collect(comopnent: ReactElement): ReactElement;
35
33
  effect(): Promise<void>;
36
34
  private emitLoadableScripts;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { Helmet as AsyncHelmet, HelmetData as AsyncHelmetData, type HelmetDatum, type HelmetHTMLBodyDatum, type HelmetHTMLElementDatum, type HelmetProps, HelmetProvider, type HelmetServerState, type HelmetTags } from 'react-helmet-async';
3
3
  export declare const Helmet: (props: React.PropsWithChildren<HelmetProps>) => React.CElement<React.PropsWithChildren<HelmetProps>, AsyncHelmet> | null;
4
4
  declare const head: {
5
- Helmet: (props: React.PropsWithChildren<HelmetProps>) => React.CElement<React.PropsWithChildren<HelmetProps>, AsyncHelmet> | null;
5
+ Helmet: typeof Helmet;
6
6
  HelmetData: typeof AsyncHelmetData;
7
7
  HelmetProvider: typeof HelmetProvider;
8
8
  };
@@ -1,10 +1,10 @@
1
- import type { RouterConfig } from './router/internal';
2
- export type { RuntimeConfig } from './common';
1
+ import type { RouterConfig } from './router/runtime/types';
2
+ export type { RuntimeConfig, RuntimePlugin } from './common';
3
3
  export { isBrowser } from './common';
4
- export type { RuntimePlugin } from './core';
5
- export { defineRuntimeConfig, RuntimeContext, useRuntimeContext, } from './core';
4
+ export { defineRuntimeConfig } from './core/config';
6
5
  export { getMonitors } from './core/context/monitors';
6
+ export type { TRuntimeContext } from './core/context/public';
7
+ export { RuntimeContext, useRuntimeContext, } from './core/context/public';
7
8
  export { getRequest } from './core/context/request';
8
9
  export { redirect, setHeaders, setStatus } from './core/context/response';
9
- export type { TRuntimeContext } from './core/context/runtime';
10
10
  export type { RouterConfig };
@@ -1,2 +1 @@
1
1
  export { InternalRuntimeContext, type TInternalRuntimeContext, } from './core/context/runtime';
2
- export type { SSRServerContext } from './core/types';
@@ -0,0 +1,104 @@
1
+ /**
2
+ * G22 — mandatory degraded consumption API.
3
+ *
4
+ * CONTEXT.md (Degraded State): "consuming a surface obliges the consumer to
5
+ * define a degraded state". This module turns that obligation into a
6
+ * compile-level one: {@link SurfaceConsumerOptions.degraded} is a REQUIRED
7
+ * field, so a call site that forgets its fallback does not type-check.
8
+ *
9
+ * The consumer wraps the loadRemote-ish flow (resolve a SurfaceRef through a
10
+ * provider, then load the execution artifact from the resolved record) and
11
+ * guarantees isolation: any discovery/load failure is caught, classified,
12
+ * reported through the existing MF fallback telemetry, and handed to the
13
+ * required degraded handler.
14
+ *
15
+ * Criticality (owner-default 5: unclassified consumption is `critical`). For a
16
+ * `noncritical` consumption the degraded handler's result is returned and the
17
+ * failure is swallowed, so one failing consumption can never propagate to a
18
+ * sibling (CONTEXT.md: faults isolate at the vertical boundary). For a
19
+ * `critical` consumption the degraded handler still runs — telemetry and
20
+ * fallback-UI obligations hold — but the returned promise then REJECTS with the
21
+ * typed failure so callers and rollout machinery observe it. Critical
22
+ * consumption during a rollout window should be driven by expand/contract, not
23
+ * by silent degrade.
24
+ */
25
+ import { type ModuleFederationFallbackClassification, type ModuleFederationFallbackTelemetryEmitOptions, type ModuleFederationFallbackTelemetryPayload } from './index';
26
+ import { type DiscoveryError, type EnvironmentId, type ParsedSurfaceRef, type ResolvedDeliveryUnit, type SurfaceResolutionProvider } from './surface-resolution-types';
27
+ /** Where in the consumption lifecycle a failure was raised. */
28
+ export type SurfaceConsumptionPhase = 'discovery' | 'load' | 'mount';
29
+ /**
30
+ * The typed failure surfaced to the degraded handler. Exactly one of
31
+ * `discoveryError` (resolver returned a typed {@link DiscoveryError}) or
32
+ * `error` (something threw) is populated for a given failure.
33
+ */
34
+ export type SurfaceConsumptionFailure = {
35
+ ref: ParsedSurfaceRef;
36
+ env: EnvironmentId;
37
+ phase: SurfaceConsumptionPhase;
38
+ classification: ModuleFederationFallbackClassification;
39
+ /** Present when discovery returned a typed error state. */
40
+ discoveryError?: DiscoveryError;
41
+ /** Present when a thrown error caused the failure. */
42
+ error?: unknown;
43
+ /** The resolved record, when discovery succeeded but load/mount failed. */
44
+ resolved?: ResolvedDeliveryUnit;
45
+ /** The fallback telemetry payload emitted for this failure. */
46
+ telemetry: ModuleFederationFallbackTelemetryPayload;
47
+ };
48
+ export type SurfaceLoadInput = {
49
+ resolved: ResolvedDeliveryUnit;
50
+ ref: ParsedSurfaceRef;
51
+ env: EnvironmentId;
52
+ };
53
+ export type SurfaceConsumerOptions<T> = {
54
+ /** The logical surface to consume (object or canonical string form). */
55
+ ref: ParsedSurfaceRef | string;
56
+ env: EnvironmentId;
57
+ /** The pluggable resolution seam (RESOLUTION-0001 §2.2). */
58
+ provider: SurfaceResolutionProvider;
59
+ /** Consumer app name, used for telemetry attribution. */
60
+ appName: string;
61
+ /**
62
+ * Loads the execution artifact from a resolved record — the loadRemote-ish
63
+ * flow. Receives the whole {@link ResolvedDeliveryUnit} so the adapter reads
64
+ * locations under one buildMarker (RESOLUTION-0001 §2.3).
65
+ */
66
+ load: (input: SurfaceLoadInput) => Promise<T> | T;
67
+ /**
68
+ * REQUIRED degraded handler (G22 compile-level obligation). There is no
69
+ * default and no way to opt out at the type level: omitting this field is a
70
+ * compile error. Return the value to serve while the surface is unavailable
71
+ * or incompatible.
72
+ */
73
+ degraded: (failure: SurfaceConsumptionFailure) => T | Promise<T>;
74
+ /**
75
+ * Consumption criticality (owner-default 5). Defaults to `'critical'` when
76
+ * omitted.
77
+ *
78
+ * - `'noncritical'`: the degraded handler's result is returned and the
79
+ * failure is swallowed — the promise never rejects.
80
+ * - `'critical'`: the degraded handler still runs (telemetry + fallback-UI
81
+ * obligations hold), but the returned promise then REJECTS with the typed
82
+ * failure so callers / rollout machinery observe it. Prefer expand/contract
83
+ * over silent degrade for critical surfaces during rollout windows.
84
+ */
85
+ classification?: 'critical' | 'noncritical';
86
+ /** Optional telemetry emission options (endpoint/auth/fetch overrides). */
87
+ telemetry?: ModuleFederationFallbackTelemetryEmitOptions;
88
+ };
89
+ /**
90
+ * Consume one surface with a mandatory degraded fallback. On any discovery or
91
+ * load failure the required degraded handler runs (telemetry + fallback UI).
92
+ *
93
+ * For a `noncritical` consumption (see {@link SurfaceConsumerOptions.classification})
94
+ * this resolves to the degraded value and never rejects, so a failing
95
+ * consumption is isolated from any sibling. For a `critical` consumption (the
96
+ * default) it rejects with the typed failure AFTER the degraded handler has
97
+ * run, so callers / rollout machinery observe the failure.
98
+ */
99
+ export declare function consumeSurface<T>(options: SurfaceConsumerOptions<T>): Promise<T>;
100
+ /**
101
+ * Build a reusable consumer bound to a provider/env/app, still requiring a
102
+ * degraded handler per call. Per-call options override the bound base.
103
+ */
104
+ export declare function createSurfaceConsumer(base: Pick<SurfaceConsumerOptions<unknown>, 'provider' | 'env' | 'appName' | 'telemetry'>): <T>(options: Omit<SurfaceConsumerOptions<T>, keyof typeof base> & Partial<Pick<SurfaceConsumerOptions<T>, keyof typeof base>>) => Promise<T>;
@@ -0,0 +1,61 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ export declare const DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY = "__modernDistributedSsrFragments";
3
+ export declare const DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY = "__modernDistributedSsrFragmentRequest";
4
+ export type DistributedSsrFragment = {
5
+ boundaryId: string;
6
+ buildMarker?: string;
7
+ digest?: string;
8
+ expose: string;
9
+ html: string;
10
+ remote: string;
11
+ status: 'ready';
12
+ };
13
+ export type DistributedSsrFragmentFailure = {
14
+ boundaryId: string;
15
+ expose: string;
16
+ reason: string;
17
+ remote: string;
18
+ status: 'degraded';
19
+ };
20
+ type DistributedSsrFragmentResult = DistributedSsrFragment | DistributedSsrFragmentFailure;
21
+ export type DistributedSsrFragmentContext = {
22
+ fragments?: Record<string, DistributedSsrFragment | DistributedSsrFragmentFailure>;
23
+ required: true;
24
+ resolve?: (remote: string, expose: string, props: Record<string, unknown>) => DistributedSsrFragmentResult | PromiseLike<DistributedSsrFragmentResult>;
25
+ };
26
+ export type DistributedSsrBoundaryProps = {
27
+ children: ReactNode;
28
+ expose: string;
29
+ fallback: ReactNode;
30
+ fragmentProps?: Record<string, unknown>;
31
+ remote: string;
32
+ };
33
+ export type CreateDistributedSsrComponentOptions<Props extends object> = {
34
+ createComponent: () => ComponentType<Props>;
35
+ expose: string;
36
+ fallback: ReactNode;
37
+ remote: string;
38
+ };
39
+ export declare function distributedSsrFragmentKey(remote: string, expose: string): string;
40
+ export declare function useDistributedSsrFragmentProps<Props extends object>({ boundaryId, expose, }: {
41
+ boundaryId: string;
42
+ expose: string;
43
+ }): Props;
44
+ /**
45
+ * Keeps the browser on the native Module Federation component while allowing
46
+ * servers that cannot execute remote code (notably workerd) to render a
47
+ * trusted fragment produced by the remote Worker itself.
48
+ *
49
+ * Node SSR has no distributed-fragment context and therefore renders the
50
+ * child normally, preserving Module Federation's in-process SSR path.
51
+ */
52
+ export declare function DistributedSsrBoundary({ children, expose, fallback, fragmentProps, remote, }: DistributedSsrBoundaryProps): import("react").JSX.Element;
53
+ /**
54
+ * Defers creation of the native Module Federation component until React
55
+ * actually renders that child. A workerd request with a verified distributed
56
+ * fragment never constructs the native remote, so its module cannot perform
57
+ * forbidden global-scope network I/O. Browser and Node rendering keep using
58
+ * the native Module Federation component unchanged.
59
+ */
60
+ export declare function createDistributedSsrComponent<Props extends object>({ createComponent, expose, fallback, remote, }: CreateDistributedSsrComponentOptions<Props>): (props: Props) => import("react").JSX.Element;
61
+ export {};
@@ -1,3 +1,9 @@
1
+ export * from './consume-surface';
2
+ export * from './distributed-ssr';
3
+ export { DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY, useDistributedSsrFragmentProps, } from './distributed-ssr';
4
+ export * from './last-known-good';
5
+ export * from './manifest-recovery-runtime-plugin';
6
+ export * from './surface-resolution-types';
1
7
  export declare const MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT = "modernjs:mf-runtime-fallback";
2
8
  export declare const MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT = "modernjs:mf-runtime-recovery";
3
9
  export declare const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = "/_modern/contract-gates/runtime-fallback";