@bleedingdev/modern-js-runtime 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10

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 (207) hide show
  1. package/dist/cjs/cli/code.js +3 -1
  2. package/dist/cjs/cli/ssr/index.js +2 -74
  3. package/dist/cjs/core/browser/hydrate.js +6 -1
  4. package/dist/cjs/core/context/index.js +4 -43
  5. package/dist/cjs/core/context/public.js +4 -7
  6. package/dist/cjs/core/context/runtime.js +17 -5
  7. package/dist/cjs/core/react/wrapper.js +22 -65
  8. package/dist/cjs/core/server/helmet.js +5 -4
  9. package/dist/cjs/core/server/requestResponse.js +4 -4
  10. package/dist/cjs/core/server/routerCleanup.js +2 -2
  11. package/dist/cjs/core/server/shared.js +171 -4
  12. package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
  13. package/dist/cjs/core/server/stream/beforeTemplate.js +34 -25
  14. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +28 -21
  15. package/dist/cjs/core/server/stream/createReadableStream.js +208 -123
  16. package/dist/cjs/core/server/stream/createReadableStream.worker.js +159 -90
  17. package/dist/cjs/core/server/stream/deferredScript.js +3 -3
  18. package/dist/cjs/core/server/stream/shared.js +2 -2
  19. package/dist/cjs/core/server/string/index.js +100 -64
  20. package/dist/cjs/core/server/string/loadable.js +34 -19
  21. package/dist/cjs/core/server/string/ssrData.js +5 -12
  22. package/dist/cjs/core/server/utils.js +1 -2
  23. package/dist/cjs/document/cli/index.js +1 -2
  24. package/dist/cjs/exports/head.js +7 -14
  25. package/dist/cjs/router/runtime/PrefetchLink.js +67 -123
  26. package/dist/cjs/router/runtime/hooks.js +13 -2
  27. package/dist/cjs/router/runtime/internal.js +7 -45
  28. package/dist/cjs/router/runtime/plugin.js +2 -8
  29. package/dist/cjs/router/runtime/plugin.node.js +2 -30
  30. package/dist/cjs/router/runtime/redirect.js +1 -1
  31. package/dist/esm/cli/code.mjs +3 -1
  32. package/dist/esm/cli/ssr/index.mjs +3 -72
  33. package/dist/esm/core/browser/hydrate.mjs +7 -2
  34. package/dist/esm/core/context/index.mjs +2 -5
  35. package/dist/esm/core/context/public.mjs +1 -5
  36. package/dist/esm/core/context/runtime.mjs +13 -4
  37. package/dist/esm/core/react/wrapper.mjs +21 -67
  38. package/dist/esm/core/server/helmet.mjs +5 -4
  39. package/dist/esm/core/server/requestResponse.mjs +3 -3
  40. package/dist/esm/core/server/routerCleanup.mjs +1 -1
  41. package/dist/esm/core/server/shared.mjs +153 -1
  42. package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
  43. package/dist/esm/core/server/stream/beforeTemplate.mjs +37 -28
  44. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +31 -24
  45. package/dist/esm/core/server/stream/createReadableStream.mjs +207 -122
  46. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +149 -90
  47. package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
  48. package/dist/esm/core/server/stream/shared.mjs +2 -2
  49. package/dist/esm/core/server/string/index.mjs +104 -68
  50. package/dist/esm/core/server/string/loadable.mjs +34 -19
  51. package/dist/esm/core/server/string/ssrData.mjs +5 -12
  52. package/dist/esm/core/server/utils.mjs +1 -2
  53. package/dist/esm/document/cli/index.mjs +2 -3
  54. package/dist/esm/exports/head.mjs +7 -14
  55. package/dist/esm/router/runtime/PrefetchLink.mjs +68 -124
  56. package/dist/esm/router/runtime/hooks.mjs +9 -1
  57. package/dist/esm/router/runtime/internal.mjs +2 -33
  58. package/dist/esm/router/runtime/plugin.mjs +1 -7
  59. package/dist/esm/router/runtime/plugin.node.mjs +1 -29
  60. package/dist/esm/router/runtime/redirect.mjs +1 -1
  61. package/dist/esm-node/cli/code.mjs +3 -1
  62. package/dist/esm-node/cli/ssr/index.mjs +3 -72
  63. package/dist/esm-node/core/browser/hydrate.mjs +7 -2
  64. package/dist/esm-node/core/context/index.mjs +2 -5
  65. package/dist/esm-node/core/context/public.mjs +1 -5
  66. package/dist/esm-node/core/context/runtime.mjs +13 -4
  67. package/dist/esm-node/core/react/wrapper.mjs +21 -67
  68. package/dist/esm-node/core/server/helmet.mjs +5 -4
  69. package/dist/esm-node/core/server/requestResponse.mjs +3 -3
  70. package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
  71. package/dist/esm-node/core/server/shared.mjs +153 -1
  72. package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
  73. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +37 -28
  74. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +31 -24
  75. package/dist/esm-node/core/server/stream/createReadableStream.mjs +207 -122
  76. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +149 -90
  77. package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
  78. package/dist/esm-node/core/server/stream/shared.mjs +2 -2
  79. package/dist/esm-node/core/server/string/index.mjs +104 -68
  80. package/dist/esm-node/core/server/string/loadable.mjs +34 -19
  81. package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
  82. package/dist/esm-node/core/server/utils.mjs +1 -2
  83. package/dist/esm-node/document/cli/index.mjs +2 -3
  84. package/dist/esm-node/exports/head.mjs +7 -14
  85. package/dist/esm-node/router/runtime/PrefetchLink.mjs +68 -124
  86. package/dist/esm-node/router/runtime/hooks.mjs +9 -1
  87. package/dist/esm-node/router/runtime/internal.mjs +2 -33
  88. package/dist/esm-node/router/runtime/plugin.mjs +1 -7
  89. package/dist/esm-node/router/runtime/plugin.node.mjs +1 -29
  90. package/dist/esm-node/router/runtime/redirect.mjs +1 -1
  91. package/dist/types/cli/index.d.ts +7 -7
  92. package/dist/types/cli/ssr/index.d.ts +0 -3
  93. package/dist/types/core/browser/hydrate.d.ts +1 -1
  94. package/dist/types/core/browser/index.d.ts +1 -1
  95. package/dist/types/core/compat/hooks.d.ts +1 -1
  96. package/dist/types/core/compat/index.d.ts +1 -1
  97. package/dist/types/core/compat/requestContext.d.ts +3 -3
  98. package/dist/types/core/config.d.ts +1 -1
  99. package/dist/types/core/context/index.d.ts +8 -10
  100. package/dist/types/core/context/monitors/index.d.ts +1 -1
  101. package/dist/types/core/context/monitors/index.server.d.ts +1 -1
  102. package/dist/types/core/context/public.d.ts +1 -23
  103. package/dist/types/core/context/runtime.d.ts +27 -3
  104. package/dist/types/core/context/serverPayload/index.d.ts +1 -1
  105. package/dist/types/core/index.d.ts +5 -5
  106. package/dist/types/core/plugin/index.d.ts +1 -1
  107. package/dist/types/core/plugin/types.d.ts +2 -2
  108. package/dist/types/core/react/wrapper.d.ts +7 -1
  109. package/dist/types/core/server/helmet.d.ts +4 -5
  110. package/dist/types/core/server/index.d.ts +2 -2
  111. package/dist/types/core/server/react/index.d.ts +2 -2
  112. package/dist/types/core/server/requestHandler.d.ts +3 -3
  113. package/dist/types/core/server/requestResponse.d.ts +3 -3
  114. package/dist/types/core/server/routerCleanup.d.ts +2 -2
  115. package/dist/types/core/server/server.d.ts +4 -4
  116. package/dist/types/core/server/shared.d.ts +25 -2
  117. package/dist/types/core/server/stream/afterTemplate.d.ts +5 -4
  118. package/dist/types/core/server/stream/beforeTemplate.d.ts +6 -3
  119. package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +6 -3
  120. package/dist/types/core/server/stream/createReadableStream.d.ts +1 -1
  121. package/dist/types/core/server/stream/createReadableStream.worker.d.ts +1 -1
  122. package/dist/types/core/server/stream/index.d.ts +1 -1
  123. package/dist/types/core/server/stream/shared.d.ts +5 -5
  124. package/dist/types/core/server/stream/template.d.ts +2 -2
  125. package/dist/types/core/server/string/index.d.ts +1 -1
  126. package/dist/types/core/server/string/loadable.d.ts +7 -4
  127. package/dist/types/core/server/string/ssrData.d.ts +5 -4
  128. package/dist/types/core/server/string/types.d.ts +2 -6
  129. package/dist/types/core/server/tracer.d.ts +1 -1
  130. package/dist/types/core/server/utils.d.ts +2 -2
  131. package/dist/types/core/types.d.ts +2 -3
  132. package/dist/types/document/index.d.ts +12 -12
  133. package/dist/types/exports/config-routes.d.ts +1 -1
  134. package/dist/types/exports/head.d.ts +2 -2
  135. package/dist/types/index.d.ts +9 -9
  136. package/dist/types/internal.d.ts +1 -1
  137. package/dist/types/react-server.d.ts +3 -3
  138. package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -1
  139. package/dist/types/router/cli/handler.d.ts +1 -1
  140. package/dist/types/router/cli/index.d.ts +3 -3
  141. package/dist/types/router/index.d.ts +1 -1
  142. package/dist/types/router/internal.d.ts +2 -2
  143. package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
  144. package/dist/types/router/runtime/hooks.d.ts +19 -2
  145. package/dist/types/router/runtime/index.d.ts +4 -4
  146. package/dist/types/router/runtime/internal.d.ts +5 -22
  147. package/dist/types/router/runtime/plugin.d.ts +3 -3
  148. package/dist/types/router/runtime/plugin.node.d.ts +3 -3
  149. package/dist/types/router/runtime/rsc-router.d.ts +3 -3
  150. package/dist/types/router/runtime/types.d.ts +2 -43
  151. package/dist/types/router/runtime/utils.d.ts +1 -1
  152. package/package.json +19 -47
  153. package/rstest.config.mts +32 -2
  154. package/dist/cjs/boundary-debugger/index.js +0 -317
  155. package/dist/cjs/core/context/extensions.js +0 -74
  156. package/dist/cjs/core/context/helmetContext.js +0 -54
  157. package/dist/cjs/core/server/federatedCss.js +0 -58
  158. package/dist/cjs/core/server/scriptOrder.js +0 -140
  159. package/dist/cjs/module-federation/consume-surface.js +0 -199
  160. package/dist/cjs/module-federation/distributed-ssr.js +0 -135
  161. package/dist/cjs/module-federation/index.js +0 -316
  162. package/dist/cjs/module-federation/last-known-good.js +0 -157
  163. package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
  164. package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
  165. package/dist/cjs/router/runtime/lifecycle.js +0 -167
  166. package/dist/cjs/router/runtime/provider.js +0 -153
  167. package/dist/esm/boundary-debugger/index.mjs +0 -277
  168. package/dist/esm/core/context/extensions.mjs +0 -33
  169. package/dist/esm/core/context/helmetContext.mjs +0 -13
  170. package/dist/esm/core/server/federatedCss.mjs +0 -20
  171. package/dist/esm/core/server/scriptOrder.mjs +0 -90
  172. package/dist/esm/module-federation/consume-surface.mjs +0 -158
  173. package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
  174. package/dist/esm/module-federation/index.mjs +0 -115
  175. package/dist/esm/module-federation/last-known-good.mjs +0 -113
  176. package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
  177. package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
  178. package/dist/esm/router/runtime/lifecycle.mjs +0 -105
  179. package/dist/esm/router/runtime/provider.mjs +0 -100
  180. package/dist/esm-node/boundary-debugger/index.mjs +0 -278
  181. package/dist/esm-node/core/context/extensions.mjs +0 -34
  182. package/dist/esm-node/core/context/helmetContext.mjs +0 -14
  183. package/dist/esm-node/core/server/federatedCss.mjs +0 -21
  184. package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
  185. package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
  186. package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
  187. package/dist/esm-node/module-federation/index.mjs +0 -116
  188. package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
  189. package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
  190. package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
  191. package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
  192. package/dist/esm-node/router/runtime/provider.mjs +0 -101
  193. package/dist/types/boundary-debugger/index.d.ts +0 -28
  194. package/dist/types/core/context/extensions.d.ts +0 -35
  195. package/dist/types/core/context/helmetContext.d.ts +0 -10
  196. package/dist/types/core/server/federatedCss.d.ts +0 -5
  197. package/dist/types/core/server/scriptOrder.d.ts +0 -25
  198. package/dist/types/module-federation/consume-surface.d.ts +0 -104
  199. package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
  200. package/dist/types/module-federation/index.d.ts +0 -71
  201. package/dist/types/module-federation/last-known-good.d.ts +0 -52
  202. package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
  203. package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
  204. package/dist/types/router/runtime/lifecycle.d.ts +0 -27
  205. package/dist/types/router/runtime/provider.d.ts +0 -78
  206. /package/dist/esm/{rslib-runtime.mjs → rslib-runtime~1.mjs} +0 -0
  207. /package/dist/esm-node/{rslib-runtime.mjs → rslib-runtime~0.mjs} +0 -0
@@ -1,159 +0,0 @@
1
- import "node:module";
2
- import { classifyModuleFederationFallback, createModuleFederationFallbackTelemetry, emitModuleFederationFallbackTelemetry } from "./index.mjs";
3
- import { createDiscoveryError, formatSurfaceRef, parseSurfaceRef, validateSurfaceRef } from "./surface-resolution-types.mjs";
4
- function classifyDiscoveryError(code) {
5
- switch(code){
6
- case 'major-not-published':
7
- case 'stale-record':
8
- return 'version-skew';
9
- case 'identity-mismatch':
10
- return 'contract';
11
- case 'unknown-unit':
12
- case 'unknown-surface':
13
- case 'provider-unavailable':
14
- return 'remote-unavailable';
15
- default:
16
- return 'remote-unavailable';
17
- }
18
- }
19
- function toRemoteString(ref) {
20
- return void 0 === validateSurfaceRef(ref) ? formatSurfaceRef(ref) : `${ref.unitId}#${ref.surfaceId}`;
21
- }
22
- async function reportFailure(options, ref, base) {
23
- const remote = toRemoteString(ref);
24
- const telemetry = createModuleFederationFallbackTelemetry({
25
- appName: options.appName,
26
- classification: base.classification,
27
- error: base.error ?? base.discoveryError,
28
- metadata: {
29
- env: options.env,
30
- surfaceRef: remote,
31
- ...base.discoveryError ? {
32
- discoveryErrorCode: base.discoveryError.code
33
- } : {},
34
- ...base.resolved ? {
35
- buildMarker: base.resolved.buildMarker
36
- } : {}
37
- },
38
- phase: base.phase,
39
- remote,
40
- status: 'degraded'
41
- });
42
- try {
43
- await emitModuleFederationFallbackTelemetry({
44
- appName: options.appName,
45
- classification: base.classification,
46
- error: base.error ?? base.discoveryError,
47
- metadata: telemetry.metadata,
48
- phase: base.phase,
49
- remote,
50
- status: 'degraded'
51
- }, options.telemetry ?? {});
52
- } catch {}
53
- const failure = {
54
- ref,
55
- env: options.env,
56
- phase: base.phase,
57
- classification: base.classification,
58
- telemetry
59
- };
60
- if (base.discoveryError) failure.discoveryError = base.discoveryError;
61
- if (void 0 !== base.error) failure.error = base.error;
62
- if (base.resolved) failure.resolved = base.resolved;
63
- const critical = (options.classification ?? 'critical') === 'critical';
64
- const reason = base.discoveryError ?? (void 0 !== base.error ? base.error : createDiscoveryError('identity-mismatch', remote, `resolved record for "${remote}" is incompatible`, {
65
- env: options.env
66
- }));
67
- let degradedValue;
68
- try {
69
- degradedValue = await options.degraded(failure);
70
- } catch (handlerError) {
71
- try {
72
- await emitModuleFederationFallbackTelemetry({
73
- appName: options.appName,
74
- classification: base.classification,
75
- error: handlerError,
76
- metadata: {
77
- ...telemetry.metadata,
78
- degradedHandlerFailed: true
79
- },
80
- phase: base.phase,
81
- remote,
82
- status: 'failed'
83
- }, options.telemetry ?? {});
84
- } catch {}
85
- if (critical) throw reason;
86
- return;
87
- }
88
- if (critical) throw reason;
89
- return degradedValue;
90
- }
91
- async function consumeSurface(options) {
92
- let ref;
93
- if ('string' == typeof options.ref) {
94
- const parsed = parseSurfaceRef(options.ref);
95
- if (!parsed.ok) {
96
- const hashIndex = options.ref.indexOf('#');
97
- const echoed = -1 === hashIndex ? {
98
- unitId: options.ref,
99
- surfaceId: ''
100
- } : {
101
- unitId: options.ref.slice(0, hashIndex),
102
- surfaceId: options.ref.slice(hashIndex + 1)
103
- };
104
- return reportFailure(options, echoed, {
105
- phase: 'discovery',
106
- classification: 'remote-unavailable',
107
- discoveryError: createDiscoveryError('unknown-surface', options.ref, `SurfaceRef "${options.ref}" is not a valid canonical reference (${parsed.error.code}).`, {
108
- parseError: parsed.error,
109
- env: options.env
110
- })
111
- });
112
- }
113
- ref = parsed.ref;
114
- } else ref = options.ref;
115
- let resolution;
116
- try {
117
- resolution = await options.provider.resolve(ref, options.env);
118
- } catch (error) {
119
- return reportFailure(options, ref, {
120
- phase: 'discovery',
121
- classification: classifyModuleFederationFallback(error),
122
- error
123
- });
124
- }
125
- if (!resolution.ok) return reportFailure(options, ref, {
126
- phase: 'discovery',
127
- classification: classifyDiscoveryError(resolution.error.code),
128
- discoveryError: resolution.error
129
- });
130
- const resolved = resolution.unit;
131
- if ('incompatible' === resolved.compatibility.status) return reportFailure(options, ref, {
132
- phase: 'discovery',
133
- classification: 'contract',
134
- resolved
135
- });
136
- try {
137
- return await options.load({
138
- resolved,
139
- ref,
140
- env: options.env
141
- });
142
- } catch (error) {
143
- return reportFailure(options, ref, {
144
- phase: 'load',
145
- classification: classifyModuleFederationFallback(error),
146
- error,
147
- resolved
148
- });
149
- }
150
- }
151
- function createSurfaceConsumer(base) {
152
- return function(options) {
153
- return consumeSurface({
154
- ...base,
155
- ...options
156
- });
157
- };
158
- }
159
- export { consumeSurface, createSurfaceConsumer };
@@ -1,83 +0,0 @@
1
- import "node:module";
2
- import { jsx } from "react/jsx-runtime";
3
- import { useRuntimeContext } from "../core/context/runtime.mjs";
4
- const DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY = '__modernDistributedSsrFragments';
5
- const DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY = '__modernDistributedSsrFragmentRequest';
6
- function distributedSsrFragmentKey(remote, expose) {
7
- return `${remote}::${expose}`;
8
- }
9
- function getDistributedSsrFragmentContext(response) {
10
- const locals = response?.locals;
11
- if ('object' != typeof locals || null === locals) return;
12
- const context = DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY] : void 0;
13
- if ('object' != typeof context || null === context) return;
14
- return context;
15
- }
16
- function useDistributedSsrFragmentProps({ boundaryId, expose }) {
17
- const runtimeContext = useRuntimeContext();
18
- const locals = runtimeContext.requestContext?.response?.locals;
19
- const request = 'object' == typeof locals && null !== locals && DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY] : void 0;
20
- if ('object' != typeof request || null === request || !('boundaryId' in request) || request.boundaryId !== boundaryId || !('expose' in request) || request.expose !== expose) throw new Error(`Distributed SSR fragment request contract mismatch for ${boundaryId} ${expose}.`);
21
- const props = 'props' in request ? request.props : void 0;
22
- if ('object' != typeof props || null === props || Array.isArray(props)) throw new Error(`Distributed SSR fragment request props must be an object for ${boundaryId} ${expose}.`);
23
- return props;
24
- }
25
- function isThenable(value) {
26
- return void 0 !== value && 'then' in value && 'function' == typeof value.then;
27
- }
28
- function DistributedSsrBoundary({ children, expose, fallback, fragmentProps, remote }) {
29
- const runtimeContext = useRuntimeContext();
30
- const key = distributedSsrFragmentKey(remote, expose);
31
- const attributes = {
32
- 'data-modern-distributed-ssr-boundary': key
33
- };
34
- if (runtimeContext.isBrowser) return /*#__PURE__*/ jsx("div", {
35
- ...attributes,
36
- children: children
37
- });
38
- const fragmentContext = getDistributedSsrFragmentContext(runtimeContext.requestContext?.response);
39
- if (void 0 === fragmentContext) return /*#__PURE__*/ jsx("div", {
40
- ...attributes,
41
- children: children
42
- });
43
- const resolverFragmentProps = void 0 === fragmentProps ? {} : Object.fromEntries(Object.entries(fragmentProps));
44
- const fragmentOrPromise = fragmentContext.resolve?.(remote, expose, resolverFragmentProps) ?? fragmentContext.fragments?.[key];
45
- if (isThenable(fragmentOrPromise)) throw fragmentOrPromise;
46
- const fragment = fragmentOrPromise;
47
- if (fragment?.status === 'ready') return /*#__PURE__*/ jsx("div", {
48
- ...attributes,
49
- "data-modern-distributed-ssr-build": fragment.buildMarker,
50
- "data-modern-distributed-ssr-digest": fragment.digest,
51
- "data-modern-distributed-ssr-status": "ready",
52
- dangerouslySetInnerHTML: {
53
- __html: fragment.html
54
- }
55
- });
56
- return /*#__PURE__*/ jsx("div", {
57
- ...attributes,
58
- "data-modern-distributed-ssr-reason": fragment?.reason ?? 'missing',
59
- "data-modern-distributed-ssr-status": "degraded",
60
- children: fallback
61
- });
62
- }
63
- function createDistributedSsrComponent({ createComponent, expose, fallback, remote }) {
64
- let RemoteComponent;
65
- function DeferredRemoteComponent(props) {
66
- RemoteComponent ??= createComponent();
67
- return /*#__PURE__*/ jsx(RemoteComponent, {
68
- ...props
69
- });
70
- }
71
- return function(props) {
72
- return /*#__PURE__*/ jsx(DistributedSsrBoundary, {
73
- expose: expose,
74
- fallback: fallback,
75
- fragmentProps: props,
76
- remote: remote,
77
- children: /*#__PURE__*/ jsx(DeferredRemoteComponent, {
78
- ...props
79
- })
80
- });
81
- };
82
- }
83
- export { DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY, DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY, DistributedSsrBoundary, createDistributedSsrComponent, distributedSsrFragmentKey, useDistributedSsrFragmentProps };
@@ -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 };