@bleedingdev/modern-js-renderer-octane 3.9.3-ultramodern.8 → 3.9.3-ultramodern.9
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/client.js +56 -6
- package/dist/cjs/entry-application.js +7 -2
- package/dist/cjs/entry-client.js +3 -0
- package/dist/cjs/entry-server.js +11 -3
- package/dist/cjs/federation.js +108 -6
- package/dist/cjs/i18n/LocalizedLink.js +24 -33
- package/dist/cjs/i18n/index.js +0 -3
- package/dist/cjs/i18n-external-snapshot.js +645 -0
- package/dist/cjs/plugin/index.js +1 -1
- package/dist/cjs/plugin/profile.js +5 -4
- package/dist/cjs/router-external-snapshot.js +263 -0
- package/dist/cjs/server.js +15 -2
- package/dist/cjs/worker-federation-context.js +63 -0
- package/dist/cjs/worker-federation-contexts.js +97 -0
- package/dist/cjs/worker-federation.js +97 -0
- package/dist/esm/client.mjs +56 -6
- package/dist/esm/entry-application.mjs +7 -2
- package/dist/esm/entry-client.mjs +3 -0
- package/dist/esm/entry-server.mjs +8 -3
- package/dist/esm/federation.mjs +110 -8
- package/dist/esm/i18n/LocalizedLink.mjs +24 -30
- package/dist/esm/i18n/index.mjs +1 -1
- package/dist/esm/i18n-external-snapshot.mjs +576 -0
- package/dist/esm/router-external-snapshot.mjs +216 -0
- package/dist/esm/server.mjs +15 -2
- package/dist/esm/worker-federation-context.mjs +19 -0
- package/dist/esm/worker-federation-contexts.mjs +47 -0
- package/dist/esm/worker-federation.mjs +59 -0
- package/dist/esm-node/plugin/index.mjs +1 -1
- package/dist/esm-node/plugin/profile.mjs +5 -4
- package/dist/types/client.d.ts +5 -1
- package/dist/types/entry-client.d.ts +2 -0
- package/dist/types/entry-server.d.ts +4 -1
- package/dist/types/federation.d.ts +2 -0
- package/dist/types/i18n/LocalizedLink.d.ts +5 -32
- package/dist/types/i18n/context.d.ts +1 -1
- package/dist/types/i18n/index.d.ts +1 -1
- package/dist/types/i18n-external-snapshot.d.ts +43 -0
- package/dist/types/router-external-snapshot.d.ts +10 -0
- package/dist/types/server.d.ts +3 -0
- package/dist/types/worker-federation-context.d.ts +34 -0
- package/dist/types/worker-federation-contexts.d.ts +25 -0
- package/dist/types/worker-federation.d.ts +20 -0
- package/package.json +69 -12
- package/src/client.ts +99 -16
- package/src/entry-application.ts +7 -3
- package/src/entry-client.ts +10 -0
- package/src/entry-server.ts +17 -6
- package/src/federation.ts +159 -15
- package/src/i18n/LocalizedLink.ts +46 -72
- package/src/i18n/context.ts +1 -1
- package/src/i18n/index.ts +1 -5
- package/src/i18n-external-snapshot.ts +803 -0
- package/src/plugin/compiler-manifest.cjs +27 -1
- package/src/plugin/index.ts +1 -1
- package/src/plugin/profile.ts +6 -4
- package/src/router-external-snapshot.ts +306 -0
- package/src/server.ts +29 -4
- package/src/worker-federation-context.ts +51 -0
- package/src/worker-federation-contexts.ts +91 -0
- package/src/worker-federation.ts +120 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { NativeWorkerDispatchOptions } from '@modern-js/renderer-core/server';
|
|
2
|
+
import {
|
|
3
|
+
type AdmitWorkerRendererContract,
|
|
4
|
+
createWorkerFederationHandler,
|
|
5
|
+
createWorkerFederationTransport,
|
|
6
|
+
} from '@modern-js/renderer-core/worker-federation';
|
|
7
|
+
import {
|
|
8
|
+
type ExternalSnapshotRenderOptions,
|
|
9
|
+
prepareExternalSnapshotRequest,
|
|
10
|
+
releasePreparedExternalSnapshotRequest,
|
|
11
|
+
renderExternalSnapshot,
|
|
12
|
+
type ServerRenderNode,
|
|
13
|
+
serializeExternalSnapshot,
|
|
14
|
+
} from 'octane/server';
|
|
15
|
+
import { createFederationScope, FederationContext } from './federation-context';
|
|
16
|
+
import { WorkerFederationContext } from './worker-federation-context';
|
|
17
|
+
|
|
18
|
+
type NativeSnapshotRequest = Awaited<
|
|
19
|
+
ReturnType<typeof prepareExternalSnapshotRequest>
|
|
20
|
+
>;
|
|
21
|
+
type HandlerOptions = Parameters<
|
|
22
|
+
typeof createWorkerFederationHandler<NativeSnapshotRequest>
|
|
23
|
+
>[0];
|
|
24
|
+
|
|
25
|
+
function isNativeWorkerComponent(
|
|
26
|
+
value: unknown,
|
|
27
|
+
): value is Extract<ServerRenderNode, (props: never) => unknown> {
|
|
28
|
+
return typeof value === 'function';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The compiled registry pins its renderer publication and literal imports. */
|
|
32
|
+
export interface OctaneWorkerFederationRegistry {
|
|
33
|
+
initialize(
|
|
34
|
+
options: Omit<HandlerOptions, 'publication' | 'exposes'> & {
|
|
35
|
+
publication: unknown;
|
|
36
|
+
},
|
|
37
|
+
): (request: Request) => Promise<Response | undefined>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Created per dispatch; no publisher or native snapshot cache crosses documents. */
|
|
41
|
+
export function createNativeWorkerFederationRuntime<Bindings extends object>(
|
|
42
|
+
options: NativeWorkerDispatchOptions<Bindings>,
|
|
43
|
+
compiler: {
|
|
44
|
+
readonly admitRendererContract: AdmitWorkerRendererContract;
|
|
45
|
+
readonly registry?: OctaneWorkerFederationRegistry;
|
|
46
|
+
},
|
|
47
|
+
) {
|
|
48
|
+
const { resources } = options;
|
|
49
|
+
const bindings = options.bindings;
|
|
50
|
+
const transport = resources.workerFederationServices?.length
|
|
51
|
+
? createWorkerFederationTransport({
|
|
52
|
+
admitRendererContract: compiler.admitRendererContract,
|
|
53
|
+
services: resources.workerFederationServices.map(service => {
|
|
54
|
+
const binding: unknown =
|
|
55
|
+
bindings && Reflect.get(bindings, service.binding);
|
|
56
|
+
if (
|
|
57
|
+
!binding ||
|
|
58
|
+
(typeof binding !== 'object' && typeof binding !== 'function') ||
|
|
59
|
+
!('fetch' in binding) ||
|
|
60
|
+
typeof binding.fetch !== 'function'
|
|
61
|
+
)
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Native Worker federation requires service binding ${service.binding}.`,
|
|
64
|
+
);
|
|
65
|
+
return { ...service, fetch: binding.fetch.bind(binding) };
|
|
66
|
+
}),
|
|
67
|
+
})
|
|
68
|
+
: undefined;
|
|
69
|
+
let handle: ((request: Request) => Promise<Response | undefined>) | undefined;
|
|
70
|
+
if (resources.workerFederation) {
|
|
71
|
+
if (!compiler.registry || !resources.workerFederationManifestUrl)
|
|
72
|
+
throw new Error(
|
|
73
|
+
'Native Worker federation requires its compiled expose registry and pinned manifest URL.',
|
|
74
|
+
);
|
|
75
|
+
handle = compiler.registry.initialize({
|
|
76
|
+
publication: resources.workerFederation.worker,
|
|
77
|
+
manifestUrl: resources.workerFederationManifestUrl,
|
|
78
|
+
admitRendererContract: compiler.admitRendererContract,
|
|
79
|
+
admitNativeRequest(payload, { admitted, signal }) {
|
|
80
|
+
const initializeContexts: ExternalSnapshotRenderOptions['initializeContexts'] =
|
|
81
|
+
transport
|
|
82
|
+
? (provide, request) => {
|
|
83
|
+
provide(
|
|
84
|
+
FederationContext,
|
|
85
|
+
createFederationScope(undefined, true, request.nonce),
|
|
86
|
+
);
|
|
87
|
+
provide(WorkerFederationContext, {
|
|
88
|
+
transport,
|
|
89
|
+
locale: admitted.locale,
|
|
90
|
+
signal,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
: undefined;
|
|
94
|
+
return prepareExternalSnapshotRequest(payload, {
|
|
95
|
+
authority: admitted.coordinate.native,
|
|
96
|
+
signal,
|
|
97
|
+
...(initializeContexts ? { initializeContexts } : {}),
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
releaseNativeRequest: releasePreparedExternalSnapshotRequest,
|
|
101
|
+
async renderNativeSnapshot(module, request, { admitted }) {
|
|
102
|
+
const component =
|
|
103
|
+
module && typeof module === 'object' && 'default' in module
|
|
104
|
+
? module.default
|
|
105
|
+
: undefined;
|
|
106
|
+
if (!isNativeWorkerComponent(component))
|
|
107
|
+
throw new TypeError(
|
|
108
|
+
`Native Worker expose ${admitted.expose} requires a default Octane component.`,
|
|
109
|
+
);
|
|
110
|
+
return serializeExternalSnapshot(
|
|
111
|
+
await renderExternalSnapshot(component, request),
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
transport,
|
|
118
|
+
handleRequest: handle ?? (() => Promise.resolve(undefined)),
|
|
119
|
+
};
|
|
120
|
+
}
|