@bleedingdev/modern-js-runtime 3.5.0-ultramodern.1 → 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.
- package/dist/cjs/boundary-debugger/index.js +13 -3
- package/dist/cjs/cli/index.js +1 -11
- package/dist/cjs/cli/registry.js +18 -0
- package/dist/cjs/cli/ssr/index.js +3 -2
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +8 -4
- package/dist/cjs/core/browser/hydrate.js +16 -2
- package/dist/cjs/core/browser/index.js +19 -18
- package/dist/cjs/core/context/index.js +3 -0
- package/dist/cjs/core/context/public.js +49 -0
- package/dist/cjs/core/context/runtime.js +6 -8
- package/dist/cjs/core/react/wrapper.js +57 -0
- package/dist/cjs/core/server/federatedCss.js +7 -3
- package/dist/cjs/core/server/requestHandler.js +15 -45
- package/dist/cjs/core/server/requestResponse.js +83 -0
- package/dist/cjs/core/server/routerCleanup.js +16 -6
- package/dist/cjs/core/server/scriptOrder.js +13 -10
- package/dist/cjs/core/server/stream/afterTemplate.js +9 -5
- package/dist/cjs/core/server/stream/template.js +3 -3
- package/dist/cjs/core/server/string/index.js +3 -3
- package/dist/cjs/core/server/string/loadable.js +3 -11
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/module-federation/consume-surface.js +199 -0
- package/dist/cjs/module-federation/distributed-ssr.js +134 -0
- package/dist/cjs/module-federation/index.js +258 -120
- package/dist/cjs/module-federation/last-known-good.js +124 -0
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +140 -0
- package/dist/cjs/module-federation/surface-resolution-types.js +61 -0
- package/dist/cjs/router/cli/code/nestedRoutes.js +3 -0
- package/dist/cjs/router/cli/code/templates.js +3 -2
- package/dist/cjs/router/cli/constants.js +1 -0
- package/dist/cjs/router/cli/nestedRoutesSpec.js +3 -1
- package/dist/cjs/router/runtime/hooks.js +7 -6
- package/dist/cjs/router/runtime/internal.js +30 -16
- package/dist/cjs/router/runtime/plugin.js +6 -7
- package/dist/cjs/router/runtime/provider.js +58 -12
- package/dist/esm/boundary-debugger/index.mjs +13 -3
- package/dist/esm/cli/code.mjs +12 -12
- package/dist/esm/cli/index.mjs +2 -12
- package/dist/esm/cli/registry.mjs +0 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +8 -4
- package/dist/esm/core/browser/hydrate.mjs +15 -4
- package/dist/esm/core/browser/index.mjs +15 -17
- package/dist/esm/core/context/index.mjs +1 -1
- package/dist/esm/core/context/public.mjs +5 -0
- package/dist/esm/core/context/runtime.mjs +4 -6
- package/dist/esm/core/react/wrapper.mjs +58 -1
- package/dist/esm/core/server/federatedCss.mjs +7 -3
- package/dist/esm/core/server/requestHandler.mjs +15 -45
- package/dist/esm/core/server/requestResponse.mjs +39 -0
- package/dist/esm/core/server/routerCleanup.mjs +11 -4
- package/dist/esm/core/server/scriptOrder.mjs +11 -8
- package/dist/esm/core/server/stream/afterTemplate.mjs +10 -6
- package/dist/esm/core/server/stream/template.mjs +3 -3
- package/dist/esm/core/server/string/index.mjs +3 -3
- package/dist/esm/core/server/string/loadable.mjs +3 -8
- package/dist/esm/exports/loadable.mjs +3 -3
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/module-federation/consume-surface.mjs +158 -0
- package/dist/esm/module-federation/distributed-ssr.mjs +81 -0
- package/dist/esm/module-federation/index.mjs +6 -0
- package/dist/esm/module-federation/last-known-good.mjs +80 -0
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +100 -0
- package/dist/esm/module-federation/surface-resolution-types.mjs +8 -0
- package/dist/esm/router/cli/code/index.mjs +5 -5
- package/dist/esm/router/cli/code/nestedRoutes.mjs +3 -0
- package/dist/esm/router/cli/code/templates.mjs +3 -2
- package/dist/esm/router/cli/constants.mjs +1 -0
- package/dist/esm/router/cli/handler.mjs +3 -3
- package/dist/esm/router/cli/nestedRoutesSpec.mjs +3 -1
- package/dist/esm/router/runtime/hooks.mjs +7 -6
- package/dist/esm/router/runtime/internal.mjs +26 -18
- package/dist/esm/router/runtime/plugin.mjs +6 -7
- package/dist/esm/router/runtime/provider.mjs +56 -13
- package/dist/esm-node/boundary-debugger/index.mjs +13 -3
- package/dist/esm-node/cli/code.mjs +12 -12
- package/dist/esm-node/cli/index.mjs +2 -12
- package/dist/esm-node/cli/registry.mjs +1 -0
- package/dist/esm-node/cli/ssr/index.mjs +3 -2
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +8 -4
- package/dist/esm-node/core/browser/hydrate.mjs +15 -4
- package/dist/esm-node/core/browser/index.mjs +15 -17
- package/dist/esm-node/core/context/index.mjs +1 -1
- package/dist/esm-node/core/context/public.mjs +6 -0
- package/dist/esm-node/core/context/runtime.mjs +4 -6
- package/dist/esm-node/core/react/wrapper.mjs +58 -1
- package/dist/esm-node/core/server/federatedCss.mjs +7 -3
- package/dist/esm-node/core/server/requestHandler.mjs +15 -45
- package/dist/esm-node/core/server/requestResponse.mjs +40 -0
- package/dist/esm-node/core/server/routerCleanup.mjs +11 -4
- package/dist/esm-node/core/server/scriptOrder.mjs +11 -8
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -6
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +2 -2
- package/dist/esm-node/core/server/stream/template.mjs +3 -3
- package/dist/esm-node/core/server/string/index.mjs +3 -3
- package/dist/esm-node/core/server/string/loadable.mjs +5 -10
- package/dist/esm-node/exports/loadable.mjs +3 -3
- package/dist/esm-node/index.mjs +2 -1
- package/dist/esm-node/module-federation/consume-surface.mjs +159 -0
- package/dist/esm-node/module-federation/distributed-ssr.mjs +82 -0
- package/dist/esm-node/module-federation/index.mjs +6 -0
- package/dist/esm-node/module-federation/last-known-good.mjs +81 -0
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +101 -0
- package/dist/esm-node/module-federation/surface-resolution-types.mjs +9 -0
- package/dist/esm-node/router/cli/code/index.mjs +5 -5
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +3 -0
- package/dist/esm-node/router/cli/code/templates.mjs +3 -2
- package/dist/esm-node/router/cli/constants.mjs +1 -0
- package/dist/esm-node/router/cli/handler.mjs +3 -3
- package/dist/esm-node/router/cli/index.mjs +2 -2
- package/dist/esm-node/router/cli/nestedRoutesSpec.mjs +3 -1
- package/dist/esm-node/router/runtime/hooks.mjs +7 -6
- package/dist/esm-node/router/runtime/internal.mjs +26 -18
- package/dist/esm-node/router/runtime/plugin.mjs +6 -7
- package/dist/esm-node/router/runtime/provider.mjs +56 -13
- package/dist/types/boundary-debugger/index.d.ts +1 -1
- package/dist/types/cli/registry.d.ts +2 -0
- package/dist/types/common.d.ts +8 -1
- package/dist/types/core/browser/hydrate.d.ts +2 -1
- package/dist/types/core/browser/index.d.ts +4 -1
- package/dist/types/core/context/index.d.ts +26 -10
- package/dist/types/core/context/monitors/default.d.ts +10 -2
- package/dist/types/core/context/monitors/index.d.ts +1 -1
- package/dist/types/core/context/monitors/index.server.d.ts +2 -2
- package/dist/types/core/context/public.d.ts +27 -0
- package/dist/types/core/context/runtime.d.ts +12 -22
- package/dist/types/core/react/index.d.ts +1 -1
- package/dist/types/core/server/requestResponse.d.ts +15 -0
- package/dist/types/core/server/routerCleanup.d.ts +2 -1
- package/dist/types/core/server/scriptOrder.d.ts +1 -1
- package/dist/types/core/server/stream/shared.d.ts +2 -2
- package/dist/types/core/server/string/loadable.d.ts +0 -2
- package/dist/types/exports/head.d.ts +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/internal.d.ts +0 -1
- package/dist/types/module-federation/consume-surface.d.ts +104 -0
- package/dist/types/module-federation/distributed-ssr.d.ts +61 -0
- package/dist/types/module-federation/index.d.ts +6 -0
- package/dist/types/module-federation/last-known-good.d.ts +72 -0
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +25 -0
- package/dist/types/module-federation/surface-resolution-types.d.ts +23 -0
- package/dist/types/router/cli/constants.d.ts +1 -0
- package/dist/types/router/runtime/hooks.d.ts +10 -6
- package/dist/types/router/runtime/internal.d.ts +13 -3
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/router/runtime/plugin.node.d.ts +1 -1
- package/dist/types/router/runtime/provider.d.ts +28 -11
- package/dist/types/router/runtime/types.d.ts +27 -5
- package/package.json +47 -27
- package/dist/cjs/exports/tanstack-router.js +0 -83
- package/dist/esm/exports/tanstack-router.mjs +0 -30
- package/dist/esm-node/exports/tanstack-router.mjs +0 -31
- package/dist/types/exports/tanstack-router.d.ts +0 -88
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
3
|
import { modifyRoutes, routerPlugin } from "./plugin.mjs";
|
|
4
|
-
import { registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks } from "./provider.mjs";
|
|
4
|
+
import { createRouterProviderRealm, registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks } from "./provider.mjs";
|
|
5
5
|
registerRouterProvider('react-router', routerPlugin, {
|
|
6
6
|
isDefault: true
|
|
7
7
|
});
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
const createRouterPlugin = (localProviders = [])=>{
|
|
9
|
+
const providerRealm = createRouterProviderRealm([
|
|
10
|
+
{
|
|
11
|
+
name: 'react-router',
|
|
12
|
+
factory: routerPlugin,
|
|
13
|
+
isDefault: true
|
|
14
|
+
},
|
|
15
|
+
...localProviders
|
|
16
|
+
]);
|
|
17
|
+
return (userConfig = {})=>({
|
|
18
|
+
name: '@modern-js/plugin-router',
|
|
19
|
+
registryHooks: routerProviderRegistryHooks,
|
|
20
|
+
setup: (api)=>{
|
|
21
|
+
const mergedConfig = merge(api.getRuntimeConfig().router || {}, userConfig);
|
|
22
|
+
const pluginFactory = resolveRouterProvider(mergedConfig.framework, {
|
|
23
|
+
realm: providerRealm
|
|
24
|
+
});
|
|
25
|
+
const providerPlugin = pluginFactory(userConfig);
|
|
26
|
+
reportUnsupportedProviderRegistryHooks(providerPlugin);
|
|
27
|
+
providerPlugin.setup?.(api);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const internal_routerPlugin = createRouterPlugin();
|
|
24
32
|
const internal = internal_routerPlugin;
|
|
25
33
|
export { renderRoutes } from "./utils.mjs";
|
|
26
34
|
export default internal;
|
|
27
|
-
export { internal_routerPlugin as routerPlugin, modifyRoutes, registerRouterProvider, resolveRouterProvider };
|
|
35
|
+
export { createRouterPlugin, createRouterProviderRealm, internal_routerPlugin as routerPlugin, modifyRoutes, registerRouterProvider, resolveRouterProvider };
|
|
@@ -65,10 +65,10 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
65
65
|
};
|
|
66
66
|
let cachedRouter = null;
|
|
67
67
|
const RouterWrapper = (props)=>{
|
|
68
|
-
const routerResult = useRouterCreation({
|
|
68
|
+
const routerResult = useRouterCreation(process.env.MODERN_ENABLE_RSC ? {
|
|
69
69
|
...props,
|
|
70
70
|
rscPayload: props?.rscPayload
|
|
71
|
-
}, {
|
|
71
|
+
} : props, {
|
|
72
72
|
api: api,
|
|
73
73
|
createRoutes,
|
|
74
74
|
supportHtml5History,
|
|
@@ -122,16 +122,15 @@ function useRouterCreation(props, options) {
|
|
|
122
122
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
123
123
|
const _basename = '/' === baseUrl ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
124
124
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
125
|
-
const rscPayload = props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
126
|
-
let hydrationData = window._ROUTER_DATA || rscPayload;
|
|
125
|
+
const rscPayload = process.env.MODERN_ENABLE_RSC && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
126
|
+
let hydrationData = process.env.MODERN_ENABLE_RSC ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
127
127
|
return (0, __rspack_external_react.useMemo)(()=>{
|
|
128
128
|
if (hydrationData?.errors) hydrationData = {
|
|
129
129
|
...hydrationData,
|
|
130
130
|
errors: deserializeErrors(hydrationData.errors)
|
|
131
131
|
};
|
|
132
|
-
const isRscClient = getGlobalIsRscClient();
|
|
133
132
|
let routes = null;
|
|
134
|
-
routes =
|
|
133
|
+
routes = process.env.MODERN_ENABLE_RSC && getGlobalIsRscClient() ? createRoutes ? createRoutes() : createRouteObjectsFromConfig({
|
|
135
134
|
routesConfig: finalRouteConfig
|
|
136
135
|
}) : createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
137
136
|
routesConfig: finalRouteConfig,
|
|
@@ -139,7 +138,7 @@ function useRouterCreation(props, options) {
|
|
|
139
138
|
}));
|
|
140
139
|
if (!routes) routes = [];
|
|
141
140
|
const hooks = api.getHooks();
|
|
142
|
-
if (rscPayload) try {
|
|
141
|
+
if (process.env.MODERN_ENABLE_RSC && rscPayload) try {
|
|
143
142
|
const router = createClientRouterFromPayload(rscPayload, routes, _basename);
|
|
144
143
|
return {
|
|
145
144
|
router,
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
|
|
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)
|
|
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
|
-
...
|
|
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 };
|
package/dist/types/common.d.ts
CHANGED
|
@@ -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
|
|
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?:
|
|
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?:
|
|
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:
|
|
52
|
-
export declare function getGlobalInternalRuntimeContext():
|
|
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 |
|
|
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
|
-
|
|
2
|
-
|
|
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: () =>
|
|
1
|
+
export declare const getMonitors: () => import("./default").RuntimeMonitors;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const getMonitors: () =>
|
|
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
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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?:
|
|
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):
|
|
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
|
|
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
|
|
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 {
|
|
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:
|
|
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:
|
|
5
|
+
Helmet: typeof Helmet;
|
|
6
6
|
HelmetData: typeof AsyncHelmetData;
|
|
7
7
|
HelmetProvider: typeof HelmetProvider;
|
|
8
8
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { RouterConfig } from './router/
|
|
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
|
|
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 };
|
package/dist/types/internal.d.ts
CHANGED
|
@@ -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>;
|