@bleedingdev/modern-js-runtime 3.9.0-ultramodern.1 → 3.9.0-ultramodern.11
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/cli/code.js +3 -1
- package/dist/cjs/cli/ssr/index.js +2 -74
- package/dist/cjs/core/browser/hydrate.js +6 -1
- package/dist/cjs/core/context/index.js +4 -43
- package/dist/cjs/core/context/public.js +4 -7
- package/dist/cjs/core/context/runtime.js +17 -5
- package/dist/cjs/core/react/wrapper.js +22 -65
- package/dist/cjs/core/server/helmet.js +5 -4
- package/dist/cjs/core/server/requestResponse.js +4 -4
- package/dist/cjs/core/server/routerCleanup.js +2 -2
- package/dist/cjs/core/server/shared.js +171 -4
- package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
- package/dist/cjs/core/server/stream/beforeTemplate.js +34 -25
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +28 -21
- package/dist/cjs/core/server/stream/createReadableStream.js +208 -123
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +159 -90
- package/dist/cjs/core/server/stream/deferredScript.js +3 -3
- package/dist/cjs/core/server/stream/shared.js +2 -2
- package/dist/cjs/core/server/string/index.js +100 -64
- package/dist/cjs/core/server/string/loadable.js +34 -19
- package/dist/cjs/core/server/string/ssrData.js +5 -12
- package/dist/cjs/core/server/utils.js +1 -2
- package/dist/cjs/exports/head.js +7 -14
- package/dist/cjs/router/runtime/PrefetchLink.js +67 -123
- package/dist/cjs/router/runtime/hooks.js +13 -2
- package/dist/cjs/router/runtime/internal.js +7 -45
- package/dist/cjs/router/runtime/plugin.js +2 -8
- package/dist/cjs/router/runtime/plugin.node.js +2 -30
- package/dist/cjs/router/runtime/redirect.js +1 -1
- package/dist/esm/cli/code.mjs +3 -1
- package/dist/esm/cli/ssr/index.mjs +3 -72
- package/dist/esm/core/browser/hydrate.mjs +7 -2
- package/dist/esm/core/context/index.mjs +2 -5
- package/dist/esm/core/context/public.mjs +1 -5
- package/dist/esm/core/context/runtime.mjs +13 -4
- package/dist/esm/core/react/wrapper.mjs +21 -67
- package/dist/esm/core/server/helmet.mjs +5 -4
- package/dist/esm/core/server/requestResponse.mjs +3 -3
- package/dist/esm/core/server/routerCleanup.mjs +1 -1
- package/dist/esm/core/server/shared.mjs +153 -1
- package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm/core/server/stream/beforeTemplate.mjs +37 -28
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +31 -24
- package/dist/esm/core/server/stream/createReadableStream.mjs +207 -122
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +149 -90
- package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm/core/server/stream/shared.mjs +2 -2
- package/dist/esm/core/server/string/index.mjs +104 -68
- package/dist/esm/core/server/string/loadable.mjs +34 -19
- package/dist/esm/core/server/string/ssrData.mjs +5 -12
- package/dist/esm/core/server/utils.mjs +1 -2
- package/dist/esm/exports/head.mjs +7 -14
- package/dist/esm/router/runtime/PrefetchLink.mjs +67 -123
- package/dist/esm/router/runtime/hooks.mjs +9 -1
- package/dist/esm/router/runtime/internal.mjs +2 -33
- package/dist/esm/router/runtime/plugin.mjs +1 -7
- package/dist/esm/router/runtime/plugin.node.mjs +1 -29
- package/dist/esm/router/runtime/redirect.mjs +1 -1
- package/dist/esm-node/cli/code.mjs +3 -1
- package/dist/esm-node/cli/ssr/index.mjs +3 -72
- package/dist/esm-node/core/browser/hydrate.mjs +7 -2
- package/dist/esm-node/core/context/index.mjs +2 -5
- package/dist/esm-node/core/context/public.mjs +1 -5
- package/dist/esm-node/core/context/runtime.mjs +13 -4
- package/dist/esm-node/core/react/wrapper.mjs +21 -67
- package/dist/esm-node/core/server/helmet.mjs +5 -4
- package/dist/esm-node/core/server/requestResponse.mjs +3 -3
- package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
- package/dist/esm-node/core/server/shared.mjs +153 -1
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +37 -28
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +31 -24
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +207 -122
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +149 -90
- package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm-node/core/server/stream/shared.mjs +2 -2
- package/dist/esm-node/core/server/string/index.mjs +104 -68
- package/dist/esm-node/core/server/string/loadable.mjs +34 -19
- package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
- package/dist/esm-node/core/server/utils.mjs +1 -2
- package/dist/esm-node/exports/head.mjs +7 -14
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +67 -123
- package/dist/esm-node/router/runtime/hooks.mjs +9 -1
- package/dist/esm-node/router/runtime/internal.mjs +2 -33
- package/dist/esm-node/router/runtime/plugin.mjs +1 -7
- package/dist/esm-node/router/runtime/plugin.node.mjs +1 -29
- package/dist/esm-node/router/runtime/redirect.mjs +1 -1
- package/dist/types/cli/ssr/index.d.ts +0 -3
- package/dist/types/core/context/index.d.ts +4 -6
- package/dist/types/core/context/public.d.ts +1 -23
- package/dist/types/core/context/runtime.d.ts +26 -2
- package/dist/types/core/react/wrapper.d.ts +6 -0
- package/dist/types/core/server/helmet.d.ts +4 -5
- package/dist/types/core/server/requestHandler.d.ts +2 -2
- package/dist/types/core/server/requestResponse.d.ts +1 -1
- package/dist/types/core/server/routerCleanup.d.ts +1 -1
- package/dist/types/core/server/shared.d.ts +24 -1
- package/dist/types/core/server/stream/afterTemplate.d.ts +2 -1
- package/dist/types/core/server/stream/beforeTemplate.d.ts +4 -1
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +4 -1
- package/dist/types/core/server/stream/shared.d.ts +2 -2
- package/dist/types/core/server/string/loadable.d.ts +6 -3
- package/dist/types/core/server/string/ssrData.d.ts +2 -1
- package/dist/types/core/server/string/types.d.ts +1 -5
- package/dist/types/core/server/tracer.d.ts +1 -1
- package/dist/types/core/server/utils.d.ts +1 -1
- package/dist/types/core/types.d.ts +1 -2
- package/dist/types/exports/head.d.ts +2 -2
- package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
- package/dist/types/router/runtime/hooks.d.ts +19 -2
- package/dist/types/router/runtime/internal.d.ts +4 -21
- package/dist/types/router/runtime/types.d.ts +2 -43
- package/package.json +18 -46
- package/rstest.config.mts +32 -2
- package/dist/cjs/boundary-debugger/index.js +0 -317
- package/dist/cjs/core/context/extensions.js +0 -74
- package/dist/cjs/core/context/helmetContext.js +0 -54
- package/dist/cjs/core/server/federatedCss.js +0 -58
- package/dist/cjs/core/server/scriptOrder.js +0 -140
- package/dist/cjs/module-federation/consume-surface.js +0 -199
- package/dist/cjs/module-federation/distributed-ssr.js +0 -135
- package/dist/cjs/module-federation/index.js +0 -316
- package/dist/cjs/module-federation/last-known-good.js +0 -157
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
- package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
- package/dist/cjs/router/runtime/lifecycle.js +0 -167
- package/dist/cjs/router/runtime/provider.js +0 -153
- package/dist/esm/boundary-debugger/index.mjs +0 -277
- package/dist/esm/core/context/extensions.mjs +0 -33
- package/dist/esm/core/context/helmetContext.mjs +0 -13
- package/dist/esm/core/server/federatedCss.mjs +0 -20
- package/dist/esm/core/server/scriptOrder.mjs +0 -90
- package/dist/esm/module-federation/consume-surface.mjs +0 -158
- package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
- package/dist/esm/module-federation/index.mjs +0 -115
- package/dist/esm/module-federation/last-known-good.mjs +0 -113
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
- package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
- package/dist/esm/router/runtime/lifecycle.mjs +0 -105
- package/dist/esm/router/runtime/provider.mjs +0 -100
- package/dist/esm-node/boundary-debugger/index.mjs +0 -278
- package/dist/esm-node/core/context/extensions.mjs +0 -34
- package/dist/esm-node/core/context/helmetContext.mjs +0 -14
- package/dist/esm-node/core/server/federatedCss.mjs +0 -21
- package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
- package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
- package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
- package/dist/esm-node/module-federation/index.mjs +0 -116
- package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
- package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
- package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
- package/dist/esm-node/router/runtime/provider.mjs +0 -101
- package/dist/types/boundary-debugger/index.d.ts +0 -28
- package/dist/types/core/context/extensions.d.ts +0 -35
- package/dist/types/core/context/helmetContext.d.ts +0 -10
- package/dist/types/core/server/federatedCss.d.ts +0 -5
- package/dist/types/core/server/scriptOrder.d.ts +0 -25
- package/dist/types/module-federation/consume-surface.d.ts +0 -104
- package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
- package/dist/types/module-federation/index.d.ts +0 -71
- package/dist/types/module-federation/last-known-good.d.ts +0 -52
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
- package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
- package/dist/types/router/runtime/lifecycle.d.ts +0 -27
- package/dist/types/router/runtime/provider.d.ts +0 -78
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
export * from "./consume-surface.mjs";
|
|
3
|
-
export * from "./distributed-ssr.mjs";
|
|
4
|
-
export * from "./last-known-good.mjs";
|
|
5
|
-
export * from "./manifest-recovery-runtime-plugin.mjs";
|
|
6
|
-
export * from "./surface-resolution-types.mjs";
|
|
7
|
-
const MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT = 'modernjs:mf-runtime-fallback';
|
|
8
|
-
const MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT = 'modernjs:mf-runtime-recovery';
|
|
9
|
-
const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
|
|
10
|
-
const DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER = 'x-modernjs-runtime-signal-token';
|
|
11
|
-
class ModuleFederationRemoteLoadTimeoutError extends Error {
|
|
12
|
-
constructor(remote, timeoutMs){
|
|
13
|
-
super(`Loading remote "${remote}" timed out after ${timeoutMs}ms`);
|
|
14
|
-
this.name = 'ModuleFederationRemoteLoadTimeoutError';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
class ModuleFederationRemoteLoadError extends Error {
|
|
18
|
-
constructor(remote, attempts, causeError){
|
|
19
|
-
super(`Unable to load remote "${remote}" after ${attempts} attempt${attempts > 1 ? 's' : ''}: ${causeError.message}`);
|
|
20
|
-
this.name = 'ModuleFederationRemoteLoadError';
|
|
21
|
-
this.remote = remote;
|
|
22
|
-
this.attempts = attempts;
|
|
23
|
-
this.causeError = causeError;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
class ModuleFederationRemoteComponentContractError extends Error {
|
|
27
|
-
constructor(remote, exportName){
|
|
28
|
-
super(`Remote "${remote}" export "${exportName}" is not a valid React component`);
|
|
29
|
-
this.name = 'ModuleFederationRemoteComponentContractError';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function toError(error) {
|
|
33
|
-
if (error instanceof Error) return error;
|
|
34
|
-
return new Error('string' == typeof error ? error : 'Unknown remote load error');
|
|
35
|
-
}
|
|
36
|
-
function classifyModuleFederationFallback(error) {
|
|
37
|
-
const normalizedError = toError(error);
|
|
38
|
-
if (normalizedError instanceof ModuleFederationRemoteLoadError) return classifyModuleFederationFallback(normalizedError.causeError);
|
|
39
|
-
if (normalizedError instanceof ModuleFederationRemoteLoadTimeoutError) return 'timeout';
|
|
40
|
-
if (normalizedError instanceof ModuleFederationRemoteComponentContractError) return 'contract';
|
|
41
|
-
const message = normalizedError.message;
|
|
42
|
-
if (/version|requiredVersion|singleton|share scope|shared module/i.test(message)) return 'version-skew';
|
|
43
|
-
if (/network|fetch|script|timeout|chunk|loading/i.test(message)) return 'network';
|
|
44
|
-
return 'remote-unavailable';
|
|
45
|
-
}
|
|
46
|
-
function createModuleFederationFallbackTelemetry(input) {
|
|
47
|
-
const error = void 0 !== input.error ? toError(input.error) : void 0;
|
|
48
|
-
const status = input.status ?? 'degraded';
|
|
49
|
-
const eventName = input.eventName ?? ('recovered' === status ? MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT : MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT);
|
|
50
|
-
const metadata = {
|
|
51
|
-
...input.metadata ?? {},
|
|
52
|
-
classification: input.classification,
|
|
53
|
-
remote: input.remote,
|
|
54
|
-
status
|
|
55
|
-
};
|
|
56
|
-
if (void 0 !== input.exportName) metadata.exportName = input.exportName;
|
|
57
|
-
if (void 0 !== input.runtimeDigest) metadata.runtimeDigest = input.runtimeDigest;
|
|
58
|
-
if (void 0 !== error) {
|
|
59
|
-
metadata.errorName = error.name;
|
|
60
|
-
metadata.errorMessage = error.message;
|
|
61
|
-
}
|
|
62
|
-
const payload = {
|
|
63
|
-
appName: input.appName,
|
|
64
|
-
eventName,
|
|
65
|
-
metadata,
|
|
66
|
-
phase: input.phase,
|
|
67
|
-
reason: input.classification,
|
|
68
|
-
schemaVersion: 1
|
|
69
|
-
};
|
|
70
|
-
if (void 0 !== input.entry) payload.entry = input.entry;
|
|
71
|
-
if (void 0 !== input.runtimeDigest) payload.runtimeDigest = input.runtimeDigest;
|
|
72
|
-
return payload;
|
|
73
|
-
}
|
|
74
|
-
function toModuleFederationFallbackAttributes(payload) {
|
|
75
|
-
return {
|
|
76
|
-
'data-mf-fallback-app': payload.appName,
|
|
77
|
-
'data-mf-fallback-classification': payload.reason,
|
|
78
|
-
'data-mf-fallback-phase': payload.phase,
|
|
79
|
-
'data-mf-fallback-remote': String(payload.metadata.remote),
|
|
80
|
-
'data-mf-fallback-status': String(payload.metadata.status),
|
|
81
|
-
'data-mf-telemetry-event': payload.eventName
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
async function emitModuleFederationFallbackTelemetry(input, options = {}) {
|
|
85
|
-
const payload = createModuleFederationFallbackTelemetry(input);
|
|
86
|
-
if ("u" > typeof window && 'function' == typeof window.dispatchEvent && "u" > typeof CustomEvent) window.dispatchEvent(new CustomEvent(payload.eventName, {
|
|
87
|
-
detail: payload
|
|
88
|
-
}));
|
|
89
|
-
const shouldPost = true === options.postSignal || Boolean(options.endpoint);
|
|
90
|
-
if (!shouldPost) return {
|
|
91
|
-
dispatched: true,
|
|
92
|
-
posted: false
|
|
93
|
-
};
|
|
94
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
95
|
-
if ('function' != typeof fetchImpl) return {
|
|
96
|
-
dispatched: true,
|
|
97
|
-
posted: false
|
|
98
|
-
};
|
|
99
|
-
const headers = new Headers({
|
|
100
|
-
'content-type': 'application/json'
|
|
101
|
-
});
|
|
102
|
-
if (void 0 !== options.authToken && options.authToken.length > 0) headers.set(options.authHeaderName ?? DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER, options.authToken);
|
|
103
|
-
const response = await fetchImpl(options.endpoint ?? DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, {
|
|
104
|
-
body: JSON.stringify(payload),
|
|
105
|
-
headers,
|
|
106
|
-
method: 'POST',
|
|
107
|
-
keepalive: true
|
|
108
|
-
});
|
|
109
|
-
return {
|
|
110
|
-
dispatched: true,
|
|
111
|
-
posted: true,
|
|
112
|
-
postStatus: response.status
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
export { DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY, useDistributedSsrFragmentProps } from "./distributed-ssr.mjs";
|
|
116
|
-
export { DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT, MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT, ModuleFederationRemoteComponentContractError, ModuleFederationRemoteLoadError, ModuleFederationRemoteLoadTimeoutError, classifyModuleFederationFallback, createModuleFederationFallbackTelemetry, emitModuleFederationFallbackTelemetry, toModuleFederationFallbackAttributes };
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { selectResolvedSurface } from "@modern-js/utils/universal";
|
|
3
|
-
import { createDiscoveryError, deliveryUnitResolutionKey } from "./surface-resolution-types.mjs";
|
|
4
|
-
const LAST_KNOWN_GOOD_PROVIDER_NAME = 'last-known-good';
|
|
5
|
-
function createInMemoryLkgStorage() {
|
|
6
|
-
const map = new Map();
|
|
7
|
-
return {
|
|
8
|
-
read (key) {
|
|
9
|
-
return map.get(key);
|
|
10
|
-
},
|
|
11
|
-
write (key, record) {
|
|
12
|
-
map.set(key, record);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function markDegraded(resolved, reason) {
|
|
17
|
-
return {
|
|
18
|
-
...resolved,
|
|
19
|
-
compatibility: {
|
|
20
|
-
...resolved.compatibility,
|
|
21
|
-
status: 'degraded',
|
|
22
|
-
reason
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function staleRecordResult(ref, env, ageMs, maxStaleMs) {
|
|
27
|
-
return {
|
|
28
|
-
ok: false,
|
|
29
|
-
error: createDiscoveryError('stale-record', ref, `Last-known-good record for surface is stale: age ${ageMs}ms exceeds maxStaleMs ${maxStaleMs}ms`, {
|
|
30
|
-
env,
|
|
31
|
-
ageMs,
|
|
32
|
-
maxStaleMs
|
|
33
|
-
})
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function resolutionAnswersRef(resolved, ref) {
|
|
37
|
-
const selected = selectResolvedSurface(resolved, ref);
|
|
38
|
-
return selected.ok && selected.surface.servedMajor === ref.major;
|
|
39
|
-
}
|
|
40
|
-
function createLastKnownGoodProvider(options) {
|
|
41
|
-
const storage = options.storage ?? createInMemoryLkgStorage();
|
|
42
|
-
const now = options.now ?? (()=>Math.floor(performance.timeOrigin + performance.now()));
|
|
43
|
-
const maxStaleMs = options.freshness?.maxStaleMs;
|
|
44
|
-
let nextResolutionGeneration = 0;
|
|
45
|
-
const latestCacheableGenerationByKey = new Map();
|
|
46
|
-
const writeTailByKey = new Map();
|
|
47
|
-
async function cacheCompatibleResolution(key, generation, record) {
|
|
48
|
-
latestCacheableGenerationByKey.set(key, Math.max(latestCacheableGenerationByKey.get(key) ?? 0, generation));
|
|
49
|
-
const previous = writeTailByKey.get(key) ?? Promise.resolve();
|
|
50
|
-
const write = previous.catch(()=>void 0).then(async ()=>{
|
|
51
|
-
if (latestCacheableGenerationByKey.get(key) !== generation) return;
|
|
52
|
-
await storage.write(key, record);
|
|
53
|
-
});
|
|
54
|
-
writeTailByKey.set(key, write);
|
|
55
|
-
try {
|
|
56
|
-
await write;
|
|
57
|
-
} finally{
|
|
58
|
-
if (writeTailByKey.get(key) === write) writeTailByKey.delete(key);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function serveFromCache(ref, env, fallback) {
|
|
62
|
-
const key = deliveryUnitResolutionKey(ref.unitId, env);
|
|
63
|
-
const cached = await storage.read(key);
|
|
64
|
-
if (!cached) return fallback();
|
|
65
|
-
if (cached.major !== ref.major) return fallback();
|
|
66
|
-
if (!resolutionAnswersRef(cached.resolved, ref)) return fallback();
|
|
67
|
-
if ('compatible' !== cached.resolved.compatibility.status) return fallback();
|
|
68
|
-
const ageMs = now() - cached.storedAt;
|
|
69
|
-
if (void 0 !== maxStaleMs && ageMs > maxStaleMs) return staleRecordResult(ref, env, ageMs, maxStaleMs);
|
|
70
|
-
return {
|
|
71
|
-
ok: true,
|
|
72
|
-
unit: markDegraded(cached.resolved, `served last-known-good record (age ${ageMs}ms) after provider failure`)
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
name: LAST_KNOWN_GOOD_PROVIDER_NAME,
|
|
77
|
-
async resolve (ref, env) {
|
|
78
|
-
const key = deliveryUnitResolutionKey(ref.unitId, env);
|
|
79
|
-
const generation = ++nextResolutionGeneration;
|
|
80
|
-
let resolution;
|
|
81
|
-
try {
|
|
82
|
-
resolution = await options.provider.resolve(ref, env);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
return serveFromCache(ref, env, ()=>({
|
|
85
|
-
ok: false,
|
|
86
|
-
error: createDiscoveryError('provider-unavailable', ref, error instanceof Error ? error.message : 'provider threw a non-error value', {
|
|
87
|
-
env,
|
|
88
|
-
provider: options.provider.name
|
|
89
|
-
})
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
if (!resolution.ok) {
|
|
93
|
-
const failure = resolution;
|
|
94
|
-
return serveFromCache(ref, env, ()=>failure);
|
|
95
|
-
}
|
|
96
|
-
if (!resolutionAnswersRef(resolution.unit, ref)) return serveFromCache(ref, env, ()=>({
|
|
97
|
-
ok: false,
|
|
98
|
-
error: createDiscoveryError('identity-mismatch', ref, `Provider ${options.provider.name} returned a delivery unit that does not answer the requested surface.`, {
|
|
99
|
-
env,
|
|
100
|
-
provider: options.provider.name,
|
|
101
|
-
recordUnitId: resolution.unit.unitId,
|
|
102
|
-
availableSurfaces: resolution.unit.surfaces.map((surface)=>surface.surfaceId)
|
|
103
|
-
})
|
|
104
|
-
}));
|
|
105
|
-
if ('compatible' === resolution.unit.compatibility.status) await cacheCompatibleResolution(key, generation, {
|
|
106
|
-
resolved: resolution.unit,
|
|
107
|
-
storedAt: now(),
|
|
108
|
-
major: ref.major
|
|
109
|
-
});
|
|
110
|
-
return resolution;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
export { LAST_KNOWN_GOOD_PROVIDER_NAME, createInMemoryLkgStorage, createLastKnownGoodProvider };
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { wait } from "@modern-js/utils/universal";
|
|
3
|
-
const DEFAULT_ATTEMPTS = 3;
|
|
4
|
-
const DEFAULT_RETRY_DELAY_MS = 100;
|
|
5
|
-
const DEFAULT_TIMEOUT_MS = 1000;
|
|
6
|
-
const MAX_ATTEMPTS = 5;
|
|
7
|
-
const MAX_RETRY_DELAY_MS = 1000;
|
|
8
|
-
const MAX_TIMEOUT_MS = 5000;
|
|
9
|
-
const RETRYABLE_HTTP_STATUSES = new Set([
|
|
10
|
-
408,
|
|
11
|
-
425,
|
|
12
|
-
429,
|
|
13
|
-
500,
|
|
14
|
-
502,
|
|
15
|
-
503,
|
|
16
|
-
504
|
|
17
|
-
]);
|
|
18
|
-
const NON_RETRYABLE_ERROR_PATTERNS = [
|
|
19
|
-
/RUNTIME-013/i,
|
|
20
|
-
/invalid manifest/i,
|
|
21
|
-
/manifest (?:schema|contract|version|identity)/i,
|
|
22
|
-
/(?:incompatible|mismatch).*(?:manifest|remote)/i
|
|
23
|
-
];
|
|
24
|
-
const clampInteger = (value, fallback, minimum, maximum)=>{
|
|
25
|
-
if (void 0 === value || !Number.isFinite(value)) return fallback;
|
|
26
|
-
return Math.min(maximum, Math.max(minimum, Math.floor(value)));
|
|
27
|
-
};
|
|
28
|
-
const getErrorMessage = (error)=>{
|
|
29
|
-
if (error instanceof Error) return error.message;
|
|
30
|
-
return 'string' == typeof error ? error : '';
|
|
31
|
-
};
|
|
32
|
-
const getErrorStatus = (error)=>{
|
|
33
|
-
if ('object' == typeof error && null !== error && 'status' in error && 'number' == typeof error.status) return error.status;
|
|
34
|
-
};
|
|
35
|
-
const isRetryableError = (error)=>{
|
|
36
|
-
if (error instanceof SyntaxError) return false;
|
|
37
|
-
const message = getErrorMessage(error);
|
|
38
|
-
if (NON_RETRYABLE_ERROR_PATTERNS.some((pattern)=>pattern.test(message))) return false;
|
|
39
|
-
const status = getErrorStatus(error);
|
|
40
|
-
if (void 0 !== status) return RETRYABLE_HTTP_STATUSES.has(status);
|
|
41
|
-
if (error instanceof Error && [
|
|
42
|
-
'AbortError',
|
|
43
|
-
'TimeoutError'
|
|
44
|
-
].includes(error.name)) return true;
|
|
45
|
-
return error instanceof TypeError || /(?:fetch failed|network|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN)/i.test(message);
|
|
46
|
-
};
|
|
47
|
-
const isHttpManifestUrl = (id)=>{
|
|
48
|
-
if (void 0 === id || 0 === id.length) return false;
|
|
49
|
-
try {
|
|
50
|
-
const url = new URL(id);
|
|
51
|
-
return ('http:' === url.protocol || 'https:' === url.protocol) && url.pathname.endsWith('.json');
|
|
52
|
-
} catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const defaultWait = (milliseconds)=>wait(milliseconds).then(()=>void 0);
|
|
57
|
-
const fetchWithTimeout = (fetchImpl, url, timeoutMs)=>fetchImpl(url, {
|
|
58
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
59
|
-
});
|
|
60
|
-
const createModuleFederationManifestRecoveryPlugin = (options = {})=>{
|
|
61
|
-
const attempts = clampInteger(options.attempts, DEFAULT_ATTEMPTS, 1, MAX_ATTEMPTS);
|
|
62
|
-
const retryDelayMs = clampInteger(options.retryDelayMs, DEFAULT_RETRY_DELAY_MS, 0, MAX_RETRY_DELAY_MS);
|
|
63
|
-
const timeoutMs = clampInteger(options.timeoutMs, DEFAULT_TIMEOUT_MS, 1, MAX_TIMEOUT_MS);
|
|
64
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
65
|
-
const waitImpl = options.waitImpl ?? defaultWait;
|
|
66
|
-
const recoverManifest = (url, attempt)=>{
|
|
67
|
-
const fetchManifest = ()=>Promise.resolve().then(()=>fetchWithTimeout(fetchImpl, url, timeoutMs)).then((response)=>{
|
|
68
|
-
if (!response.ok) {
|
|
69
|
-
if (!RETRYABLE_HTTP_STATUSES.has(response.status) || attempt === attempts - 1) return;
|
|
70
|
-
return recoverManifest(url, attempt + 1);
|
|
71
|
-
}
|
|
72
|
-
return Promise.resolve().then(()=>response.json()).then((manifest)=>manifest, ()=>void 0);
|
|
73
|
-
}, (error)=>{
|
|
74
|
-
if (!isRetryableError(error) || attempt === attempts - 1) return;
|
|
75
|
-
return recoverManifest(url, attempt + 1);
|
|
76
|
-
});
|
|
77
|
-
if (attempt > 0 && retryDelayMs > 0) return waitImpl(retryDelayMs).then(fetchManifest);
|
|
78
|
-
return fetchManifest();
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
name: 'modern-js-manifest-recovery-plugin',
|
|
82
|
-
errorLoadRemote (args) {
|
|
83
|
-
if ('afterResolve' !== args.lifecycle || !isHttpManifestUrl(args.id) || !isRetryableError(args.error) || 'function' != typeof fetchImpl) return Promise.resolve(void 0);
|
|
84
|
-
return recoverManifest(args.id, 0);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
const manifest_recovery_runtime_plugin = createModuleFederationManifestRecoveryPlugin;
|
|
89
|
-
export default manifest_recovery_runtime_plugin;
|
|
90
|
-
export { createModuleFederationManifestRecoveryPlugin };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { createDiscoveryError, formatSurfaceRef, parseSurfaceRef, validateSurfaceRef } from "@modern-js/utils/universal";
|
|
3
|
-
function surfaceResolutionKey(ref, env) {
|
|
4
|
-
return `${env}::${formatSurfaceRef(ref)}`;
|
|
5
|
-
}
|
|
6
|
-
function deliveryUnitResolutionKey(unitId, env) {
|
|
7
|
-
return `${env}::${unitId}`;
|
|
8
|
-
}
|
|
9
|
-
export { createDiscoveryError, deliveryUnitResolutionKey, formatSurfaceRef, parseSurfaceRef, surfaceResolutionKey, validateSurfaceRef };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { createRuntimeContextExtension } from "../../core/context/extensions.mjs";
|
|
3
|
-
const routerRuntimeStateExtension = createRuntimeContextExtension('@modern-js/runtime:router-runtime-state');
|
|
4
|
-
const routerServerSnapshotExtension = createRuntimeContextExtension('@modern-js/runtime:router-server-snapshot');
|
|
5
|
-
function getRouterRuntimeState(runtimeContext) {
|
|
6
|
-
return routerRuntimeStateExtension.get(runtimeContext);
|
|
7
|
-
}
|
|
8
|
-
function getRouterServerSnapshot(runtimeContext) {
|
|
9
|
-
return routerServerSnapshotExtension.get(runtimeContext);
|
|
10
|
-
}
|
|
11
|
-
function toHydrationScripts(state) {
|
|
12
|
-
if (state.hydrationScripts?.length) return state.hydrationScripts;
|
|
13
|
-
return state.hydrationScript ? [
|
|
14
|
-
state.hydrationScript
|
|
15
|
-
] : void 0;
|
|
16
|
-
}
|
|
17
|
-
function getMatchedRouteIdsFromMatches(matches) {
|
|
18
|
-
const routeIds = matches?.map((match)=>match.assetRouteId ?? match.routeId).filter((routeId)=>'string' == typeof routeId);
|
|
19
|
-
return routeIds?.length ? routeIds : void 0;
|
|
20
|
-
}
|
|
21
|
-
function createRouterServerSnapshot(state) {
|
|
22
|
-
const hydrationScripts = toHydrationScripts(state);
|
|
23
|
-
const matchedRouteIds = state.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
24
|
-
return {
|
|
25
|
-
...state,
|
|
26
|
-
...hydrationScripts?.length ? {
|
|
27
|
-
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
28
|
-
hydrationScripts
|
|
29
|
-
} : {},
|
|
30
|
-
...matchedRouteIds ? {
|
|
31
|
-
matchedRouteIds
|
|
32
|
-
} : {}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function createRouterRuntimeState(state) {
|
|
36
|
-
const hasSnapshotState = Boolean(state.serverSnapshot) || Boolean(state.hydrationScript) || Boolean(state.hydrationScripts?.length) || Boolean(state.matchedRouteIds?.length) || Boolean(state.matches?.length);
|
|
37
|
-
const serverSnapshot = state.serverSnapshot ? createRouterServerSnapshot({
|
|
38
|
-
...state.serverSnapshot,
|
|
39
|
-
framework: state.serverSnapshot.framework ?? state.framework,
|
|
40
|
-
basename: state.serverSnapshot.basename ?? state.basename,
|
|
41
|
-
hydrationScript: state.serverSnapshot.hydrationScript ?? state.hydrationScript,
|
|
42
|
-
hydrationScripts: state.serverSnapshot.hydrationScripts ?? state.hydrationScripts,
|
|
43
|
-
matchedRouteIds: state.serverSnapshot.matchedRouteIds ?? state.matchedRouteIds,
|
|
44
|
-
matches: state.serverSnapshot.matches ?? state.matches
|
|
45
|
-
}) : hasSnapshotState ? createRouterServerSnapshot({
|
|
46
|
-
framework: state.framework,
|
|
47
|
-
basename: state.basename,
|
|
48
|
-
hydrationScript: state.hydrationScript,
|
|
49
|
-
hydrationScripts: state.hydrationScripts,
|
|
50
|
-
matchedRouteIds: state.matchedRouteIds,
|
|
51
|
-
matches: state.matches
|
|
52
|
-
}) : void 0;
|
|
53
|
-
const hydrationScripts = toHydrationScripts({
|
|
54
|
-
hydrationScript: state.hydrationScript ?? serverSnapshot?.hydrationScript,
|
|
55
|
-
hydrationScripts: state.hydrationScripts ?? serverSnapshot?.hydrationScripts
|
|
56
|
-
});
|
|
57
|
-
const matchedRouteIds = state.matchedRouteIds ?? serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
58
|
-
return {
|
|
59
|
-
...state,
|
|
60
|
-
...hydrationScripts?.length ? {
|
|
61
|
-
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
62
|
-
hydrationScripts
|
|
63
|
-
} : {},
|
|
64
|
-
...matchedRouteIds ? {
|
|
65
|
-
matchedRouteIds
|
|
66
|
-
} : {},
|
|
67
|
-
...serverSnapshot ? {
|
|
68
|
-
serverSnapshot
|
|
69
|
-
} : {}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function applyRouterRuntimeState(runtimeContext, state) {
|
|
73
|
-
const normalized = createRouterRuntimeState(state);
|
|
74
|
-
routerRuntimeStateExtension.set(runtimeContext, normalized);
|
|
75
|
-
if (normalized.serverSnapshot) routerServerSnapshotExtension.set(runtimeContext, normalized.serverSnapshot);
|
|
76
|
-
return runtimeContext;
|
|
77
|
-
}
|
|
78
|
-
function applyRouterServerPrepareResult(runtimeContext, result) {
|
|
79
|
-
const state = createRouterRuntimeState({
|
|
80
|
-
...result.state,
|
|
81
|
-
cleanup: result.cleanup ?? result.state.cleanup,
|
|
82
|
-
serverSnapshot: result.snapshot ?? result.state.serverSnapshot
|
|
83
|
-
});
|
|
84
|
-
applyRouterRuntimeState(runtimeContext, state);
|
|
85
|
-
return runtimeContext;
|
|
86
|
-
}
|
|
87
|
-
function getRouterHydrationScripts(runtimeContext) {
|
|
88
|
-
const serverSnapshot = getRouterServerSnapshot(runtimeContext);
|
|
89
|
-
const runtimeState = getRouterRuntimeState(runtimeContext);
|
|
90
|
-
return serverSnapshot?.hydrationScripts ?? toHydrationScripts({
|
|
91
|
-
hydrationScript: serverSnapshot?.hydrationScript
|
|
92
|
-
}) ?? runtimeState?.hydrationScripts ?? toHydrationScripts({
|
|
93
|
-
hydrationScript: runtimeState?.hydrationScript
|
|
94
|
-
}) ?? [];
|
|
95
|
-
}
|
|
96
|
-
function getRouterMatchedRouteIds(runtimeContext) {
|
|
97
|
-
const serverSnapshot = getRouterServerSnapshot(runtimeContext);
|
|
98
|
-
const runtimeState = getRouterRuntimeState(runtimeContext);
|
|
99
|
-
return serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(serverSnapshot?.matches) ?? runtimeState?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(runtimeState?.matches);
|
|
100
|
-
}
|
|
101
|
-
async function cleanupRouterRuntimeState(runtimeContext) {
|
|
102
|
-
try {
|
|
103
|
-
await getRouterRuntimeState(runtimeContext)?.cleanup?.();
|
|
104
|
-
} catch {}
|
|
105
|
-
}
|
|
106
|
-
export { applyRouterRuntimeState, applyRouterServerPrepareResult, cleanupRouterRuntimeState, createRouterRuntimeState, createRouterServerSnapshot, getRouterHydrationScripts, getRouterMatchedRouteIds, getRouterRuntimeState, getRouterServerSnapshot };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter } from "./hooks.mjs";
|
|
3
|
-
const routerProviderRegistryHooks = {
|
|
4
|
-
modifyRoutes: modifyRoutes,
|
|
5
|
-
onBeforeCreateRoutes: onBeforeCreateRoutes,
|
|
6
|
-
onBeforeCreateRouter: onBeforeCreateRouter,
|
|
7
|
-
onAfterCreateRouter: onAfterCreateRouter,
|
|
8
|
-
onBeforeHydrateRouter: onBeforeHydrateRouter,
|
|
9
|
-
onAfterHydrateRouter: onAfterHydrateRouter
|
|
10
|
-
};
|
|
11
|
-
function reportUnsupportedProviderRegistryHooks(providerPlugin) {
|
|
12
|
-
const unsupportedHookNames = Object.keys(providerPlugin.registryHooks ?? {}).filter((hookName)=>!(hookName in routerProviderRegistryHooks));
|
|
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
|
-
return unsupportedHookNames;
|
|
15
|
-
}
|
|
16
|
-
function createRouterProviderRealm(registrations) {
|
|
17
|
-
const providers = new Map();
|
|
18
|
-
let defaultProvider;
|
|
19
|
-
for (const registration of registrations){
|
|
20
|
-
if (0 === registration.name.length) 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
|
-
...void 0 !== 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');
|
|
39
|
-
function getRegistry() {
|
|
40
|
-
const host = globalThis;
|
|
41
|
-
host[REGISTRY_SLOT] ??= {
|
|
42
|
-
providers: new Map(),
|
|
43
|
-
duplicateProviders: new Set(),
|
|
44
|
-
warnedDuplicates: new Set()
|
|
45
|
-
};
|
|
46
|
-
host[REGISTRY_SLOT].duplicateProviders ??= new Set();
|
|
47
|
-
host[REGISTRY_SLOT].warnedDuplicates ??= new Set();
|
|
48
|
-
return host[REGISTRY_SLOT];
|
|
49
|
-
}
|
|
50
|
-
function getLegacyV2Registry() {
|
|
51
|
-
const host = globalThis;
|
|
52
|
-
return host[LEGACY_V2_REGISTRY_SLOT];
|
|
53
|
-
}
|
|
54
|
-
function registerRouterProvider(name, factory, options = {}) {
|
|
55
|
-
const registry = getRegistry();
|
|
56
|
-
const existing = registry.providers.get(name);
|
|
57
|
-
if (void 0 !== existing) {
|
|
58
|
-
if (existing !== factory) registry.duplicateProviders.add(name);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (true === options.isDefault) registry.defaultProvider = name;
|
|
62
|
-
registry.providers.set(name, factory);
|
|
63
|
-
}
|
|
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
|
-
}
|
|
73
|
-
const registry = getRegistry();
|
|
74
|
-
const legacyV2Registry = getLegacyV2Registry();
|
|
75
|
-
const name = framework || options.localDefault?.name || registry.defaultProvider || legacyV2Registry?.defaultProvider;
|
|
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.');
|
|
77
|
-
if (void 0 !== options.localDefault && name === options.localDefault.name) return options.localDefault.factory;
|
|
78
|
-
const factory = registry.providers.get(name);
|
|
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;
|
|
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).");
|
|
89
|
-
throw new Error(`[@modern-js/runtime] Unknown router framework "${name}". Registered providers: ${[
|
|
90
|
-
...new Set([
|
|
91
|
-
...registry.providers.keys(),
|
|
92
|
-
...legacyV2Registry?.providers.keys() ?? []
|
|
93
|
-
])
|
|
94
|
-
].join(', ') || '(none)'}. Install and register the plugin that provides this router framework.`);
|
|
95
|
-
}
|
|
96
|
-
function unsafe_resetRouterProvidersForTesting() {
|
|
97
|
-
const host = globalThis;
|
|
98
|
-
delete host[REGISTRY_SLOT];
|
|
99
|
-
delete host[LEGACY_V2_REGISTRY_SLOT];
|
|
100
|
-
}
|
|
101
|
-
export { createRouterProviderRealm, registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks, unsafe_resetRouterProvidersForTesting };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { RuntimePlugin } from '../common.js';
|
|
2
|
-
export type BoundaryDebugEntry = {
|
|
3
|
-
appId: string;
|
|
4
|
-
color?: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
mfName: string;
|
|
7
|
-
ownerTeam?: string;
|
|
8
|
-
packageName?: string;
|
|
9
|
-
role?: 'host' | 'vertical';
|
|
10
|
-
};
|
|
11
|
-
export type BoundaryDebugMetadata = {
|
|
12
|
-
appId: string;
|
|
13
|
-
boundaries: BoundaryDebugEntry[];
|
|
14
|
-
schemaVersion: 1;
|
|
15
|
-
};
|
|
16
|
-
export type BoundaryDebuggerControlMode = 'visible' | 'hidden-when-off' | 'hidden';
|
|
17
|
-
export type BoundaryDebuggerPluginOptions = {
|
|
18
|
-
controlMode?: BoundaryDebuggerControlMode;
|
|
19
|
-
enabledByDefault?: boolean;
|
|
20
|
-
labels?: Record<string, {
|
|
21
|
-
toggle: string;
|
|
22
|
-
}>;
|
|
23
|
-
legacySelector?: string;
|
|
24
|
-
metadata: BoundaryDebugMetadata;
|
|
25
|
-
storageKey?: string;
|
|
26
|
-
};
|
|
27
|
-
export declare const ultramodernBoundaryDebuggerPlugin: (options: BoundaryDebuggerPluginOptions) => RuntimePlugin;
|
|
28
|
-
export default ultramodernBoundaryDebuggerPlugin;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fork-owned runtime-context extension mechanism.
|
|
3
|
-
*
|
|
4
|
-
* Plugins must not add ad-hoc fields to `TRuntimeContext` /
|
|
5
|
-
* `TInternalRuntimeContext`. Instead they store state in a single internal
|
|
6
|
-
* slot (a `Map` keyed by symbol) attached to the context object under a
|
|
7
|
-
* symbol property, so nothing leaks into string-key enumeration
|
|
8
|
-
* (`Object.keys`, `JSON.stringify`, `{ ...context }` rest patterns over
|
|
9
|
-
* named keys).
|
|
10
|
-
*
|
|
11
|
-
* `Symbol.for` is used for both the slot and the extension keys so that the
|
|
12
|
-
* mechanism stays coherent even if this module is instantiated twice
|
|
13
|
-
* (e.g. esm/cjs interop in test runners).
|
|
14
|
-
*/
|
|
15
|
-
export interface RuntimeContextExtension<T> {
|
|
16
|
-
/** Stable identity of this extension. */
|
|
17
|
-
readonly key: symbol;
|
|
18
|
-
get(context: object): T | undefined;
|
|
19
|
-
set(context: object, value: T): void;
|
|
20
|
-
remove(context: object): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Removes the extension slot from a context object.
|
|
24
|
-
*
|
|
25
|
-
* The symbol slot crosses object spreads while remaining absent from string-key
|
|
26
|
-
* enumeration and JSON. Callers can still explicitly clear the original context.
|
|
27
|
-
*/
|
|
28
|
-
export declare function stripRuntimeContextExtensions(context: object): void;
|
|
29
|
-
/**
|
|
30
|
-
* Creates a typed accessor pair over the shared extension slot.
|
|
31
|
-
*
|
|
32
|
-
* The `id` must be globally unique (it is interned via `Symbol.for`); use a
|
|
33
|
-
* package-prefixed name such as `@modern-js/plugin-tanstack:router-state`.
|
|
34
|
-
*/
|
|
35
|
-
export declare function createRuntimeContextExtension<T>(id: string): RuntimeContextExtension<T>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fork-owned helmet state, stored via the runtime-context extension slot
|
|
3
|
-
* instead of an ad-hoc `_helmetContext` field on `TInternalRuntimeContext`.
|
|
4
|
-
*/
|
|
5
|
-
import type { HelmetServerState } from 'react-helmet-async';
|
|
6
|
-
export interface HelmetContextSlot {
|
|
7
|
-
helmet?: HelmetServerState | null;
|
|
8
|
-
}
|
|
9
|
-
export declare function getHelmetContext(context: object): HelmetContextSlot | undefined;
|
|
10
|
-
export declare function ensureHelmetContext(context: object): HelmetContextSlot;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { TInternalRuntimeContext } from '../context/index.js';
|
|
2
|
-
type RouteAssetManifest = {
|
|
3
|
-
assets?: string[];
|
|
4
|
-
};
|
|
5
|
-
type RouteManifestLike = {
|
|
6
|
-
routeAssets?: Record<string, RouteAssetManifest | undefined>;
|
|
7
|
-
};
|
|
8
|
-
type ScriptChunkLike = {
|
|
9
|
-
filename?: string;
|
|
10
|
-
url?: string;
|
|
11
|
-
};
|
|
12
|
-
export declare function getMatchedRouteChunks<T>(runtimeContext: TInternalRuntimeContext, routeManifest: RouteManifestLike | undefined, routeAssetToChunk: (asset: string) => T): T[];
|
|
13
|
-
export declare const orderHydrationScriptChunks: <T extends ScriptChunkLike>({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName, }: {
|
|
14
|
-
asyncEntryChunks: T[];
|
|
15
|
-
collectedChunks: T[];
|
|
16
|
-
matchedRouteChunks: T[];
|
|
17
|
-
entryName: string;
|
|
18
|
-
}) => T[];
|
|
19
|
-
export declare function injectBeforeHydrationEntryScript(template: string, scripts: string, entryName?: string): string;
|
|
20
|
-
export declare function replaceChunkJsPlaceholder(template: string, scripts: string, entryName?: string, placeholder?: string): string;
|
|
21
|
-
export declare function createRouteHydrationScriptTags(runtimeContext: TInternalRuntimeContext, entryName: string, options?: {
|
|
22
|
-
nonce?: string;
|
|
23
|
-
template?: string;
|
|
24
|
-
}): string;
|
|
25
|
-
export {};
|