remote-components 0.3.3 → 0.3.5
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/config/nextjs.cjs +86 -37
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +86 -37
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +5 -1
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +5 -1
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/html.cjs +861 -617
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +861 -617
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +700 -383
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +674 -357
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +34 -2
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +35 -3
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/react.cjs +641 -352
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +641 -352
- package/dist/host/react.js.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +42 -27
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +42 -27
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.js +31 -39
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +39 -3
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
- package/dist/internal/host/nextjs/image-shared.js +29 -3
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/nextjs/remote-component-links.cjs +24 -13
- package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -1
- package/dist/internal/host/nextjs/remote-component-links.d.ts +3 -0
- package/dist/internal/host/nextjs/remote-component-links.js +24 -13
- package/dist/internal/host/nextjs/remote-component-links.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +2 -1
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/lifecycle.cjs +69 -0
- package/dist/internal/host/shared/lifecycle.cjs.map +1 -0
- package/dist/internal/host/shared/lifecycle.d.ts +34 -0
- package/dist/internal/host/shared/lifecycle.js +44 -0
- package/dist/internal/host/shared/lifecycle.js.map +1 -0
- package/dist/internal/host/shared/pipeline.cjs +222 -0
- package/dist/internal/host/shared/pipeline.cjs.map +1 -0
- package/dist/internal/host/shared/pipeline.d.ts +153 -0
- package/dist/internal/host/shared/pipeline.js +200 -0
- package/dist/internal/host/shared/pipeline.js.map +1 -0
- package/dist/internal/host/shared/polyfill.cjs +8 -7
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.js +8 -7
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
- package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
- package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
- package/dist/internal/host/shared/shared-module-resolver.js +78 -0
- package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
- package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
- package/dist/internal/remote/nextjs/next-internals.js +26 -0
- package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
- package/dist/internal/runtime/html/apply-origin.cjs +11 -32
- package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
- package/dist/internal/runtime/html/apply-origin.js +11 -32
- package/dist/internal/runtime/html/apply-origin.js.map +1 -1
- package/dist/internal/runtime/html/html-spec.cjs +78 -0
- package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
- package/dist/internal/runtime/html/html-spec.d.ts +23 -0
- package/dist/internal/runtime/html/html-spec.js +41 -0
- package/dist/internal/runtime/html/html-spec.js.map +1 -0
- package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.js +29 -12
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
- package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
- package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
- package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
- package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
- package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/component-loader.js +28 -44
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
- package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/static-loader.js +15 -21
- package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
- package/dist/internal/runtime/namespace.cjs +82 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -0
- package/dist/internal/runtime/namespace.d.ts +5 -0
- package/dist/internal/runtime/namespace.js +58 -0
- package/dist/internal/runtime/namespace.js.map +1 -0
- package/dist/internal/runtime/rsc-imports.cjs +86 -0
- package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
- package/dist/internal/runtime/rsc-imports.d.ts +39 -0
- package/dist/internal/runtime/rsc-imports.js +50 -0
- package/dist/internal/runtime/rsc-imports.js.map +1 -0
- package/dist/internal/runtime/rsc-runtime.cjs +17 -0
- package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
- package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
- package/dist/internal/runtime/rsc-runtime.js +1 -0
- package/dist/internal/runtime/rsc-runtime.js.map +1 -0
- package/dist/internal/runtime/rsc.cjs +23 -12
- package/dist/internal/runtime/rsc.cjs.map +1 -1
- package/dist/internal/runtime/rsc.d.ts +19 -2
- package/dist/internal/runtime/rsc.js +20 -11
- package/dist/internal/runtime/rsc.js.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +17 -4
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +23 -1
- package/dist/internal/runtime/turbopack/module.js +16 -4
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
- package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
- package/dist/internal/runtime/turbopack/patterns.js +23 -7
- package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
- package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
- package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
- package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
- package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.cjs +21 -15
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +9 -2
- package/dist/internal/runtime/turbopack/shared-modules.js +24 -18
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +5 -41
- package/dist/internal/utils/logger.cjs +1 -1
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +2 -2
- package/dist/internal/utils/logger.js +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/remote/html.cjs +78 -22
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +78 -22
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +14 -55
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +24 -45
- package/dist/remote/nextjs/app.js.map +1 -1
- package/dist/types-59251814.d.ts +94 -0
- package/package.json +2 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { RemoteComponentMetadata } from '../../runtime/metadata.js';
|
|
2
|
+
import { ScriptDescriptor } from './asset-descriptors.js';
|
|
3
|
+
import { InternalResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
4
|
+
import { a as ConsumeLoaderPayload } from '../../../server-handoff-ce13bebc.js';
|
|
5
|
+
import { ParsedRemoteComponent } from '../../runtime/html/parse-remote-html.js';
|
|
6
|
+
import { M as MountOrUnmountFunction } from '../../../types-59251814.js';
|
|
7
|
+
import 'react';
|
|
8
|
+
import './config.js';
|
|
9
|
+
import './fetch-interceptors.js';
|
|
10
|
+
import '../server/types.js';
|
|
11
|
+
import '../nextjs/dom-flight.js';
|
|
12
|
+
import 'parse5/dist/tree-adapters/default';
|
|
13
|
+
import '../../runtime/turbopack/remote-scope.js';
|
|
14
|
+
import '../../runtime/constants.js';
|
|
15
|
+
|
|
16
|
+
type SharedModuleMap = Record<string, (bundle?: string) => Promise<unknown>>;
|
|
17
|
+
/**
|
|
18
|
+
* Input for {@link runPipeline} — the full post-fetch pipeline that starts
|
|
19
|
+
* from raw HTML.
|
|
20
|
+
*/
|
|
21
|
+
interface PipelineInput {
|
|
22
|
+
/** Resolved URL of the remote component. */
|
|
23
|
+
url: URL;
|
|
24
|
+
/** Raw HTML string returned by the remote. */
|
|
25
|
+
html: string;
|
|
26
|
+
/** Component name hint (may be refined during parsing). */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Abort signal — the pipeline checks this between async steps. */
|
|
29
|
+
signal: AbortSignal;
|
|
30
|
+
/** Host-provided shared module factories (resolved or promise). */
|
|
31
|
+
shared: Promise<SharedModuleMap> | SharedModuleMap;
|
|
32
|
+
/** URL rewriter for client-side asset URLs. */
|
|
33
|
+
resolveClientUrl?: InternalResolveClientUrl;
|
|
34
|
+
/** Shadow root or element to mount into (for script-based components). */
|
|
35
|
+
container?: ShadowRoot | HTMLElement | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Input for {@link runPipelineFromParsed} — the pipeline entry point for
|
|
39
|
+
* hosts that receive pre-parsed SSR data (e.g. the App Router client).
|
|
40
|
+
*/
|
|
41
|
+
interface ParsedPipelineInput {
|
|
42
|
+
/** Resolved URL of the remote component. */
|
|
43
|
+
url: URL;
|
|
44
|
+
/** Component name. */
|
|
45
|
+
name: string;
|
|
46
|
+
/** Abort signal. */
|
|
47
|
+
signal: AbortSignal;
|
|
48
|
+
/** Pre-resolved loader payload from the server component. */
|
|
49
|
+
payload: ConsumeLoaderPayload;
|
|
50
|
+
/** Host-provided shared module factories (resolved or promise). */
|
|
51
|
+
shared: Promise<SharedModuleMap> | SharedModuleMap;
|
|
52
|
+
/** Remote-requested shared modules. */
|
|
53
|
+
remoteShared?: Record<string, string>;
|
|
54
|
+
/** URL rewriter for client-side asset URLs. */
|
|
55
|
+
resolveClientUrl?: InternalResolveClientUrl;
|
|
56
|
+
/** Shadow root or element to mount into. */
|
|
57
|
+
container?: ShadowRoot | HTMLElement | null;
|
|
58
|
+
/** Optional RSC name override (used by App Router for scoped RSC data). */
|
|
59
|
+
rscName?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Successful dynamic component load — the component is a React element tree
|
|
63
|
+
* ready to render.
|
|
64
|
+
*/
|
|
65
|
+
interface PipelineLoaded {
|
|
66
|
+
status: 'loaded';
|
|
67
|
+
component: React.ReactNode;
|
|
68
|
+
metadata: RemoteComponentMetadata;
|
|
69
|
+
parsed: ParsedRemoteComponent;
|
|
70
|
+
doc: Document;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Successful static component load — mount/unmount functions are returned
|
|
74
|
+
* for the host to call.
|
|
75
|
+
*/
|
|
76
|
+
interface PipelineStatic {
|
|
77
|
+
status: 'static';
|
|
78
|
+
mount: Set<MountOrUnmountFunction>;
|
|
79
|
+
unmount: Set<MountOrUnmountFunction>;
|
|
80
|
+
metadata: RemoteComponentMetadata;
|
|
81
|
+
parsed: ParsedRemoteComponent;
|
|
82
|
+
doc: Document;
|
|
83
|
+
}
|
|
84
|
+
/** The load was aborted before it could complete. */
|
|
85
|
+
interface PipelineAborted {
|
|
86
|
+
status: 'aborted';
|
|
87
|
+
}
|
|
88
|
+
/** The load failed with an error. */
|
|
89
|
+
interface PipelineError {
|
|
90
|
+
status: 'error';
|
|
91
|
+
error: Error;
|
|
92
|
+
}
|
|
93
|
+
type PipelineResult = PipelineLoaded | PipelineStatic | PipelineAborted | PipelineError;
|
|
94
|
+
/**
|
|
95
|
+
* Intermediate result from {@link preparePipeline}. Hosts that need to run
|
|
96
|
+
* framework-specific logic between parse and load (e.g. inline script
|
|
97
|
+
* execution in the React host) use this to split the pipeline into two
|
|
98
|
+
* phases.
|
|
99
|
+
*/
|
|
100
|
+
interface PreparedPipeline {
|
|
101
|
+
doc: Document;
|
|
102
|
+
parsed: ParsedRemoteComponent;
|
|
103
|
+
/** Script descriptors ready to pass to `loadRemoteComponent`. */
|
|
104
|
+
scriptDescriptors: ScriptDescriptor[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Phase 1: Parse HTML, validate shared modules, and normalize URLs.
|
|
108
|
+
*
|
|
109
|
+
* This is the synchronous/cheap portion of the pipeline. Hosts that need to
|
|
110
|
+
* inject logic between parse and load (e.g. executing inline scripts) call
|
|
111
|
+
* this directly, then call {@link loadPrepared} when ready.
|
|
112
|
+
*/
|
|
113
|
+
declare function preparePipeline(input: {
|
|
114
|
+
html: string;
|
|
115
|
+
name: string;
|
|
116
|
+
url: URL;
|
|
117
|
+
shared: SharedModuleMap;
|
|
118
|
+
remoteShared?: Record<string, string>;
|
|
119
|
+
resolveClientUrl?: InternalResolveClientUrl;
|
|
120
|
+
}): PreparedPipeline;
|
|
121
|
+
/**
|
|
122
|
+
* Phase 2: Load the component from a prepared pipeline result.
|
|
123
|
+
*
|
|
124
|
+
* For dynamic components, delegates to `loadRemoteComponent`. For static
|
|
125
|
+
* components (`isRemoteComponent`), delegates to `loadStaticRemoteComponent`.
|
|
126
|
+
*/
|
|
127
|
+
declare function loadPrepared(input: {
|
|
128
|
+
prepared: PreparedPipeline;
|
|
129
|
+
url: URL;
|
|
130
|
+
signal: AbortSignal;
|
|
131
|
+
shared: Promise<SharedModuleMap> | SharedModuleMap;
|
|
132
|
+
resolveClientUrl?: InternalResolveClientUrl;
|
|
133
|
+
container?: ShadowRoot | HTMLElement | null;
|
|
134
|
+
rscName?: string;
|
|
135
|
+
}): Promise<PipelineResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Full post-fetch pipeline: parse → validate → normalize → load.
|
|
138
|
+
*
|
|
139
|
+
* Use this when starting from a raw HTML string (React host, HTML host).
|
|
140
|
+
*/
|
|
141
|
+
declare function runPipeline(input: PipelineInput): Promise<PipelineResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Pipeline entry point for pre-parsed SSR data (App Router client).
|
|
144
|
+
*
|
|
145
|
+
* Skips HTML parsing and goes straight to `loadRemoteComponent` with the
|
|
146
|
+
* pre-resolved payload from the server component.
|
|
147
|
+
*/
|
|
148
|
+
declare function runPipelineFromParsed(input: ParsedPipelineInput): Promise<{
|
|
149
|
+
status: 'loaded';
|
|
150
|
+
component: React.ReactNode;
|
|
151
|
+
} | PipelineAborted | PipelineError>;
|
|
152
|
+
|
|
153
|
+
export { ParsedPipelineInput, PipelineAborted, PipelineError, PipelineInput, PipelineLoaded, PipelineResult, PipelineStatic, PreparedPipeline, loadPrepared, preparePipeline, runPipeline, runPipelineFromParsed };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { buildHostShared } from "#internal/host/shared/shared-module-resolver";
|
|
2
|
+
import { applyOriginToNodes } from "#internal/runtime/html/apply-origin";
|
|
3
|
+
import {
|
|
4
|
+
parseRemoteComponentDocument
|
|
5
|
+
} from "#internal/runtime/html/parse-remote-html";
|
|
6
|
+
import { loadRemoteComponent } from "#internal/runtime/loaders/component-loader";
|
|
7
|
+
import { loadStaticRemoteComponent } from "#internal/runtime/loaders/static-loader";
|
|
8
|
+
import {
|
|
9
|
+
collapseDoubleSlashes,
|
|
10
|
+
REMOTE_COMPONENT_REGEX
|
|
11
|
+
} from "#internal/runtime/patterns";
|
|
12
|
+
import { escapeString } from "#internal/utils";
|
|
13
|
+
import { RemoteComponentsError } from "#internal/utils/error";
|
|
14
|
+
function preparePipeline(input) {
|
|
15
|
+
const parser = new DOMParser();
|
|
16
|
+
const doc = parser.parseFromString(input.html, "text/html");
|
|
17
|
+
const parsed = parseRemoteComponentDocument(doc, input.name, input.url);
|
|
18
|
+
const remoteShared = input.remoteShared ?? parsed.remoteShared;
|
|
19
|
+
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
20
|
+
throw new RemoteComponentsError(
|
|
21
|
+
remoteShared.__remote_components_missing_shared__
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
applyOriginToNodes(doc, input.url, input.resolveClientUrl);
|
|
25
|
+
const scriptDescriptors = buildScriptDescriptors(parsed.scripts, input.url);
|
|
26
|
+
return { doc, parsed, scriptDescriptors };
|
|
27
|
+
}
|
|
28
|
+
async function loadPrepared(input) {
|
|
29
|
+
const { prepared, url, signal, resolveClientUrl, container, rscName } = input;
|
|
30
|
+
const { doc, parsed, scriptDescriptors } = prepared;
|
|
31
|
+
if (signal.aborted) {
|
|
32
|
+
return { status: "aborted" };
|
|
33
|
+
}
|
|
34
|
+
const userShared = await input.shared;
|
|
35
|
+
if (signal.aborted) {
|
|
36
|
+
return { status: "aborted" };
|
|
37
|
+
}
|
|
38
|
+
if (parsed.isRemoteComponent) {
|
|
39
|
+
return loadStaticPath({
|
|
40
|
+
parsed,
|
|
41
|
+
doc,
|
|
42
|
+
url,
|
|
43
|
+
resolveClientUrl
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return loadDynamicPath({
|
|
47
|
+
parsed,
|
|
48
|
+
doc,
|
|
49
|
+
url,
|
|
50
|
+
scriptDescriptors,
|
|
51
|
+
shared: userShared,
|
|
52
|
+
resolveClientUrl,
|
|
53
|
+
container,
|
|
54
|
+
rscName
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function runPipeline(input) {
|
|
58
|
+
try {
|
|
59
|
+
const userShared = await input.shared;
|
|
60
|
+
if (input.signal.aborted) {
|
|
61
|
+
return { status: "aborted" };
|
|
62
|
+
}
|
|
63
|
+
const prepared = preparePipeline({
|
|
64
|
+
html: input.html,
|
|
65
|
+
name: input.name,
|
|
66
|
+
url: input.url,
|
|
67
|
+
shared: userShared,
|
|
68
|
+
resolveClientUrl: input.resolveClientUrl
|
|
69
|
+
});
|
|
70
|
+
return await loadPrepared({
|
|
71
|
+
prepared,
|
|
72
|
+
url: input.url,
|
|
73
|
+
signal: input.signal,
|
|
74
|
+
shared: userShared,
|
|
75
|
+
resolveClientUrl: input.resolveClientUrl,
|
|
76
|
+
container: input.container
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
status: "error",
|
|
81
|
+
error: error instanceof Error ? error : new RemoteComponentsError(String(error))
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function runPipelineFromParsed(input) {
|
|
86
|
+
try {
|
|
87
|
+
if (input.signal.aborted) {
|
|
88
|
+
return { status: "aborted" };
|
|
89
|
+
}
|
|
90
|
+
const remoteShared = input.remoteShared ?? input.payload.remoteShared ?? {};
|
|
91
|
+
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
92
|
+
throw new RemoteComponentsError(
|
|
93
|
+
remoteShared.__remote_components_missing_shared__
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const result = await loadRemoteComponent({
|
|
97
|
+
url: input.url,
|
|
98
|
+
name: input.name,
|
|
99
|
+
rscName: input.rscName,
|
|
100
|
+
bundle: input.payload.bundle,
|
|
101
|
+
route: input.payload.route,
|
|
102
|
+
runtime: input.payload.runtime,
|
|
103
|
+
data: input.payload.data,
|
|
104
|
+
nextData: input.payload.nextData,
|
|
105
|
+
scripts: input.payload.scripts,
|
|
106
|
+
shared: input.shared,
|
|
107
|
+
remoteShared,
|
|
108
|
+
container: input.container,
|
|
109
|
+
resolveClientUrl: input.resolveClientUrl
|
|
110
|
+
});
|
|
111
|
+
if (input.signal.aborted) {
|
|
112
|
+
return { status: "aborted" };
|
|
113
|
+
}
|
|
114
|
+
if (result.error) {
|
|
115
|
+
return { status: "error", error: result.error };
|
|
116
|
+
}
|
|
117
|
+
return { status: "loaded", component: result.component };
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
status: "error",
|
|
121
|
+
error: error instanceof Error ? error : new RemoteComponentsError(String(error))
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function buildScriptDescriptors(scripts, url) {
|
|
126
|
+
return scripts.map((script) => {
|
|
127
|
+
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
128
|
+
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(scriptSrc)?.groups ?? {
|
|
129
|
+
prefix: void 0,
|
|
130
|
+
id: scriptSrc
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
src: new URL(collapseDoubleSlashes(`${prefix ?? ""}${path}`), url).href
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async function loadStaticPath(input) {
|
|
138
|
+
const { parsed, doc, url, resolveClientUrl } = input;
|
|
139
|
+
const scripts = Array.from(
|
|
140
|
+
parsed.component.querySelectorAll("script")
|
|
141
|
+
);
|
|
142
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
143
|
+
scripts,
|
|
144
|
+
url,
|
|
145
|
+
resolveClientUrl
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
status: "static",
|
|
149
|
+
mount,
|
|
150
|
+
unmount,
|
|
151
|
+
metadata: parsed.metadata,
|
|
152
|
+
parsed,
|
|
153
|
+
doc
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function loadDynamicPath(input) {
|
|
157
|
+
const {
|
|
158
|
+
parsed,
|
|
159
|
+
doc,
|
|
160
|
+
url,
|
|
161
|
+
scriptDescriptors,
|
|
162
|
+
shared,
|
|
163
|
+
resolveClientUrl,
|
|
164
|
+
container
|
|
165
|
+
} = input;
|
|
166
|
+
const rscName = input.rscName ?? (parsed.rsc ? `__remote_component_rsc_${escapeString(url.href)}_${escapeString(parsed.name)}` : void 0);
|
|
167
|
+
const rscData = parsed.rsc ? (parsed.rsc.textContent || "").split("\n").filter(Boolean) : [];
|
|
168
|
+
const result = await loadRemoteComponent({
|
|
169
|
+
url,
|
|
170
|
+
name: parsed.name,
|
|
171
|
+
rscName,
|
|
172
|
+
bundle: parsed.metadata.bundle,
|
|
173
|
+
route: parsed.metadata.route,
|
|
174
|
+
runtime: parsed.metadata.runtime,
|
|
175
|
+
data: rscData,
|
|
176
|
+
nextData: parsed.nextData,
|
|
177
|
+
scripts: scriptDescriptors,
|
|
178
|
+
shared: buildHostShared(shared, resolveClientUrl),
|
|
179
|
+
remoteShared: parsed.remoteShared,
|
|
180
|
+
container,
|
|
181
|
+
resolveClientUrl
|
|
182
|
+
});
|
|
183
|
+
if (result.error) {
|
|
184
|
+
return { status: "error", error: result.error };
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
status: "loaded",
|
|
188
|
+
component: result.component,
|
|
189
|
+
metadata: parsed.metadata,
|
|
190
|
+
parsed,
|
|
191
|
+
doc
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export {
|
|
195
|
+
loadPrepared,
|
|
196
|
+
preparePipeline,
|
|
197
|
+
runPipeline,
|
|
198
|
+
runPipelineFromParsed
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/pipeline.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ScriptDescriptor } from '#internal/host/shared/asset-descriptors';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport { buildHostShared } from '#internal/host/shared/shared-module-resolver';\nimport { applyOriginToNodes } from '#internal/runtime/html/apply-origin';\nimport {\n type ParsedRemoteComponent,\n parseRemoteComponentDocument,\n} from '#internal/runtime/html/parse-remote-html';\nimport { loadRemoteComponent } from '#internal/runtime/loaders/component-loader';\nimport { loadStaticRemoteComponent } from '#internal/runtime/loaders/static-loader';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\nimport {\n collapseDoubleSlashes,\n REMOTE_COMPONENT_REGEX,\n} from '#internal/runtime/patterns';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { escapeString } from '#internal/utils';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ntype SharedModuleMap = Record<string, (bundle?: string) => Promise<unknown>>;\n\n/**\n * Input for {@link runPipeline} — the full post-fetch pipeline that starts\n * from raw HTML.\n */\nexport interface PipelineInput {\n /** Resolved URL of the remote component. */\n url: URL;\n /** Raw HTML string returned by the remote. */\n html: string;\n /** Component name hint (may be refined during parsing). */\n name: string;\n /** Abort signal — the pipeline checks this between async steps. */\n signal: AbortSignal;\n /** Host-provided shared module factories (resolved or promise). */\n shared: Promise<SharedModuleMap> | SharedModuleMap;\n /** URL rewriter for client-side asset URLs. */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Shadow root or element to mount into (for script-based components). */\n container?: ShadowRoot | HTMLElement | null;\n}\n\n/**\n * Input for {@link runPipelineFromParsed} — the pipeline entry point for\n * hosts that receive pre-parsed SSR data (e.g. the App Router client).\n */\nexport interface ParsedPipelineInput {\n /** Resolved URL of the remote component. */\n url: URL;\n /** Component name. */\n name: string;\n /** Abort signal. */\n signal: AbortSignal;\n /** Pre-resolved loader payload from the server component. */\n payload: ConsumeLoaderPayload;\n /** Host-provided shared module factories (resolved or promise). */\n shared: Promise<SharedModuleMap> | SharedModuleMap;\n /** Remote-requested shared modules. */\n remoteShared?: Record<string, string>;\n /** URL rewriter for client-side asset URLs. */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Shadow root or element to mount into. */\n container?: ShadowRoot | HTMLElement | null;\n /** Optional RSC name override (used by App Router for scoped RSC data). */\n rscName?: string;\n}\n\n/**\n * Successful dynamic component load — the component is a React element tree\n * ready to render.\n */\nexport interface PipelineLoaded {\n status: 'loaded';\n component: React.ReactNode;\n metadata: RemoteComponentMetadata;\n parsed: ParsedRemoteComponent;\n doc: Document;\n}\n\n/**\n * Successful static component load — mount/unmount functions are returned\n * for the host to call.\n */\nexport interface PipelineStatic {\n status: 'static';\n mount: Set<MountOrUnmountFunction>;\n unmount: Set<MountOrUnmountFunction>;\n metadata: RemoteComponentMetadata;\n parsed: ParsedRemoteComponent;\n doc: Document;\n}\n\n/** The load was aborted before it could complete. */\nexport interface PipelineAborted {\n status: 'aborted';\n}\n\n/** The load failed with an error. */\nexport interface PipelineError {\n status: 'error';\n error: Error;\n}\n\nexport type PipelineResult =\n | PipelineLoaded\n | PipelineStatic\n | PipelineAborted\n | PipelineError;\n\n/**\n * Intermediate result from {@link preparePipeline}. Hosts that need to run\n * framework-specific logic between parse and load (e.g. inline script\n * execution in the React host) use this to split the pipeline into two\n * phases.\n */\nexport interface PreparedPipeline {\n doc: Document;\n parsed: ParsedRemoteComponent;\n /** Script descriptors ready to pass to `loadRemoteComponent`. */\n scriptDescriptors: ScriptDescriptor[];\n}\n\n// ---------------------------------------------------------------------------\n// Pipeline phases\n// ---------------------------------------------------------------------------\n\n/**\n * Phase 1: Parse HTML, validate shared modules, and normalize URLs.\n *\n * This is the synchronous/cheap portion of the pipeline. Hosts that need to\n * inject logic between parse and load (e.g. executing inline scripts) call\n * this directly, then call {@link loadPrepared} when ready.\n */\nexport function preparePipeline(input: {\n html: string;\n name: string;\n url: URL;\n shared: SharedModuleMap;\n remoteShared?: Record<string, string>;\n resolveClientUrl?: InternalResolveClientUrl;\n}): PreparedPipeline {\n const parser = new DOMParser();\n const doc = parser.parseFromString(input.html, 'text/html');\n\n const parsed = parseRemoteComponentDocument(doc, input.name, input.url);\n\n // Validate shared modules — surface errors early before any script loading.\n // Only check *remote* shared modules here. The host-side marker\n // (`__remote_components_missing_shared__` in `input.shared`) is a callable\n // error signal that the host may intentionally leave in place when\n // `withRemoteComponentsConfig` is not used — blocking on it would break\n // framework-agnostic hosts that don't configure shared modules.\n const remoteShared = input.remoteShared ?? parsed.remoteShared;\n if ('__remote_components_missing_shared__' in remoteShared) {\n throw new RemoteComponentsError(\n remoteShared.__remote_components_missing_shared__,\n );\n }\n\n applyOriginToNodes(doc, input.url, input.resolveClientUrl);\n\n const scriptDescriptors = buildScriptDescriptors(parsed.scripts, input.url);\n\n return { doc, parsed, scriptDescriptors };\n}\n\n/**\n * Phase 2: Load the component from a prepared pipeline result.\n *\n * For dynamic components, delegates to `loadRemoteComponent`. For static\n * components (`isRemoteComponent`), delegates to `loadStaticRemoteComponent`.\n */\nexport async function loadPrepared(input: {\n prepared: PreparedPipeline;\n url: URL;\n signal: AbortSignal;\n shared: Promise<SharedModuleMap> | SharedModuleMap;\n resolveClientUrl?: InternalResolveClientUrl;\n container?: ShadowRoot | HTMLElement | null;\n rscName?: string;\n}): Promise<PipelineResult> {\n const { prepared, url, signal, resolveClientUrl, container, rscName } = input;\n const { doc, parsed, scriptDescriptors } = prepared;\n\n if (signal.aborted) {\n return { status: 'aborted' };\n }\n\n const userShared = await input.shared;\n if (signal.aborted) {\n return { status: 'aborted' };\n }\n\n if (parsed.isRemoteComponent) {\n return loadStaticPath({\n parsed,\n doc,\n url,\n resolveClientUrl,\n });\n }\n\n return loadDynamicPath({\n parsed,\n doc,\n url,\n scriptDescriptors,\n shared: userShared,\n resolveClientUrl,\n container,\n rscName,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Full pipeline entry points\n// ---------------------------------------------------------------------------\n\n/**\n * Full post-fetch pipeline: parse → validate → normalize → load.\n *\n * Use this when starting from a raw HTML string (React host, HTML host).\n */\nexport async function runPipeline(\n input: PipelineInput,\n): Promise<PipelineResult> {\n try {\n const userShared = await input.shared;\n if (input.signal.aborted) {\n return { status: 'aborted' };\n }\n\n const prepared = preparePipeline({\n html: input.html,\n name: input.name,\n url: input.url,\n shared: userShared,\n resolveClientUrl: input.resolveClientUrl,\n });\n\n return await loadPrepared({\n prepared,\n url: input.url,\n signal: input.signal,\n shared: userShared,\n resolveClientUrl: input.resolveClientUrl,\n container: input.container,\n });\n } catch (error) {\n return {\n status: 'error',\n error:\n error instanceof Error\n ? error\n : new RemoteComponentsError(String(error)),\n };\n }\n}\n\n/**\n * Pipeline entry point for pre-parsed SSR data (App Router client).\n *\n * Skips HTML parsing and goes straight to `loadRemoteComponent` with the\n * pre-resolved payload from the server component.\n */\nexport async function runPipelineFromParsed(\n input: ParsedPipelineInput,\n): Promise<\n | { status: 'loaded'; component: React.ReactNode }\n | PipelineAborted\n | PipelineError\n> {\n try {\n if (input.signal.aborted) {\n return { status: 'aborted' };\n }\n\n const remoteShared = input.remoteShared ?? input.payload.remoteShared ?? {};\n\n if ('__remote_components_missing_shared__' in remoteShared) {\n throw new RemoteComponentsError(\n remoteShared.__remote_components_missing_shared__,\n );\n }\n\n const result = await loadRemoteComponent({\n url: input.url,\n name: input.name,\n rscName: input.rscName,\n bundle: input.payload.bundle,\n route: input.payload.route,\n runtime: input.payload.runtime,\n data: input.payload.data,\n nextData: input.payload.nextData,\n scripts: input.payload.scripts,\n shared: input.shared,\n remoteShared,\n container: input.container,\n resolveClientUrl: input.resolveClientUrl,\n });\n\n if (input.signal.aborted) {\n return { status: 'aborted' };\n }\n\n if (result.error) {\n return { status: 'error', error: result.error };\n }\n return { status: 'loaded', component: result.component };\n } catch (error) {\n return {\n status: 'error',\n error:\n error instanceof Error\n ? error\n : new RemoteComponentsError(String(error)),\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Converts parsed `<script>` elements into the `ScriptDescriptor[]` format\n * expected by `loadRemoteComponent`. Handles the `[bundle] id` URL format\n * and collapses double slashes.\n */\nfunction buildScriptDescriptors(\n scripts: HTMLScriptElement[],\n url: URL,\n): ScriptDescriptor[] {\n return scripts.map((script) => {\n const scriptSrc =\n script.getAttribute('data-src') ||\n script.getAttribute('src') ||\n script.src;\n const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(scriptSrc)\n ?.groups ?? {\n prefix: undefined,\n id: scriptSrc,\n };\n return {\n src: new URL(collapseDoubleSlashes(`${prefix ?? ''}${path}`), url).href,\n };\n });\n}\n\nasync function loadStaticPath(input: {\n parsed: ParsedRemoteComponent;\n doc: Document;\n url: URL;\n resolveClientUrl?: InternalResolveClientUrl;\n}): Promise<PipelineStatic> {\n const { parsed, doc, url, resolveClientUrl } = input;\n const scripts = Array.from(\n parsed.component.querySelectorAll<HTMLScriptElement>('script'),\n );\n const { mount, unmount } = await loadStaticRemoteComponent(\n scripts,\n url,\n resolveClientUrl,\n );\n return {\n status: 'static',\n mount,\n unmount,\n metadata: parsed.metadata,\n parsed,\n doc,\n };\n}\n\nasync function loadDynamicPath(input: {\n parsed: ParsedRemoteComponent;\n doc: Document;\n url: URL;\n scriptDescriptors: ScriptDescriptor[];\n shared: SharedModuleMap;\n resolveClientUrl?: InternalResolveClientUrl;\n container?: ShadowRoot | HTMLElement | null;\n rscName?: string;\n}): Promise<PipelineLoaded | PipelineError> {\n const {\n parsed,\n doc,\n url,\n scriptDescriptors,\n shared,\n resolveClientUrl,\n container,\n } = input;\n\n const rscName =\n input.rscName ??\n (parsed.rsc\n ? `__remote_component_rsc_${escapeString(url.href)}_${escapeString(parsed.name)}`\n : undefined);\n\n const rscData = parsed.rsc\n ? (parsed.rsc.textContent || '').split('\\n').filter(Boolean)\n : [];\n\n const result = await loadRemoteComponent({\n url,\n name: parsed.name,\n rscName,\n bundle: parsed.metadata.bundle,\n route: parsed.metadata.route,\n runtime: parsed.metadata.runtime,\n data: rscData,\n nextData: parsed.nextData,\n scripts: scriptDescriptors,\n shared: buildHostShared(shared, resolveClientUrl),\n remoteShared: parsed.remoteShared,\n container,\n resolveClientUrl,\n });\n\n if (result.error) {\n return { status: 'error', error: result.error };\n }\n return {\n status: 'loaded',\n component: result.component,\n metadata: parsed.metadata,\n parsed,\n doc,\n };\n}\n"],"mappings":"AAGA,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC,SAAS,iCAAiC;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAwH/B,SAAS,gBAAgB,OAOX;AACnB,QAAM,SAAS,IAAI,UAAU;AAC7B,QAAM,MAAM,OAAO,gBAAgB,MAAM,MAAM,WAAW;AAE1D,QAAM,SAAS,6BAA6B,KAAK,MAAM,MAAM,MAAM,GAAG;AAQtE,QAAM,eAAe,MAAM,gBAAgB,OAAO;AAClD,MAAI,0CAA0C,cAAc;AAC1D,UAAM,IAAI;AAAA,MACR,aAAa;AAAA,IACf;AAAA,EACF;AAEA,qBAAmB,KAAK,MAAM,KAAK,MAAM,gBAAgB;AAEzD,QAAM,oBAAoB,uBAAuB,OAAO,SAAS,MAAM,GAAG;AAE1E,SAAO,EAAE,KAAK,QAAQ,kBAAkB;AAC1C;AAQA,eAAsB,aAAa,OAQP;AAC1B,QAAM,EAAE,UAAU,KAAK,QAAQ,kBAAkB,WAAW,QAAQ,IAAI;AACxE,QAAM,EAAE,KAAK,QAAQ,kBAAkB,IAAI;AAE3C,MAAI,OAAO,SAAS;AAClB,WAAO,EAAE,QAAQ,UAAU;AAAA,EAC7B;AAEA,QAAM,aAAa,M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AAO,UAAU,iBAAoC,QAAQ;AAAA,EAC/D;AACA,QAAM,EAAE,OAAO,QAAQ,IAAI,MAAM;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,IACjB;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAe,gBAAgB,OASa;AAC1C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,UACJ,MAAM,YACL,OAAO,MACJ,0BAA0B,aAAa,IAAI,IAAI,KAAK,aAAa,OAAO,IAAI,MAC5E;AAEN,QAAM,UAAU,OAAO,OAClB,OAAO,IAAI,eAAe,IAAI,MAAM,IAAI,EAAE,OAAO,OAAO,IACzD,CAAC;AAEL,QAAM,SAAS,MAAM,oBAAoB;AAAA,IACvC;AAAA,IACA,MAAM,OAAO;AAAA,IACb;AAAA,IACA,QAAQ,OAAO,SAAS;AAAA,IACxB,OAAO,OAAO,SAAS;AAAA,IACvB,SAAS,OAAO,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,UAAU,OAAO;AAAA,IACjB,SAAS;AAAA,IACT,QAAQ,gBAAgB,QAAQ,gBAAgB;AAAA,IAChD,cAAc,OAAO;AAAA,IACrB;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,OAAO,OAAO;AAChB,WAAO,EAAE,QAAQ,SAAS,OAAO,OAAO,MAAM;AAAA,EAChD;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,WAAW,OAAO;AAAA,IAClB,UAAU,OAAO;AAAA,IACjB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -23,11 +23,12 @@ __export(polyfill_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(polyfill_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_remote_image_loader = require("#internal/host/shared/remote-image-loader");
|
|
26
|
+
var import_namespace = require("#internal/runtime/namespace");
|
|
26
27
|
var import_logger = require("#internal/utils/logger");
|
|
27
28
|
function sharedPolyfills(shared, resolveClientUrl) {
|
|
28
|
-
const
|
|
29
|
+
const hostShared = (0, import_namespace.getNamespace)().hostSharedModules;
|
|
29
30
|
const polyfill = {
|
|
30
|
-
"next/dist/client/components/navigation":
|
|
31
|
+
"next/dist/client/components/navigation": hostShared["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
|
|
31
32
|
useRouter() {
|
|
32
33
|
return {
|
|
33
34
|
push: (routerUrl) => {
|
|
@@ -58,7 +59,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
58
59
|
},
|
|
59
60
|
__esModule: true
|
|
60
61
|
})),
|
|
61
|
-
"next/dist/client/app-dir/link":
|
|
62
|
+
"next/dist/client/app-dir/link": hostShared["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
|
|
62
63
|
default: ({
|
|
63
64
|
scroll: _,
|
|
64
65
|
replace,
|
|
@@ -108,7 +109,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
108
109
|
},
|
|
109
110
|
__esModule: true
|
|
110
111
|
})),
|
|
111
|
-
"next/dist/client/app-dir/form":
|
|
112
|
+
"next/dist/client/app-dir/form": hostShared["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
|
|
112
113
|
default: () => {
|
|
113
114
|
throw new Error("Next.js <Form> component not implemented");
|
|
114
115
|
},
|
|
@@ -119,17 +120,17 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
119
120
|
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
120
121
|
// placeholders, error handling) while routing image optimization through the
|
|
121
122
|
// remote app's /_next/image endpoint.
|
|
122
|
-
"next/dist/shared/lib/image-loader":
|
|
123
|
+
"next/dist/shared/lib/image-loader": hostShared["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
|
|
123
124
|
default: (0, import_remote_image_loader.createRemoteImageLoader)(bundle, resolveClientUrl),
|
|
124
125
|
__esModule: true
|
|
125
126
|
})),
|
|
126
|
-
"next/dist/client/script":
|
|
127
|
+
"next/dist/client/script": hostShared["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
|
|
127
128
|
// TODO: implement <Script> component for non-Next.js host applications
|
|
128
129
|
// do not throw an error for now
|
|
129
130
|
default: () => null,
|
|
130
131
|
__esModule: true
|
|
131
132
|
})),
|
|
132
|
-
"next/router":
|
|
133
|
+
"next/router": hostShared["next/router"] ?? shared?.["next/router"] ?? (() => (
|
|
133
134
|
// TODO: incomplete implementation
|
|
134
135
|
Promise.resolve({
|
|
135
136
|
useRouter() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport { logWarn } from '#internal/utils/logger';\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport { logWarn } from '#internal/utils/logger';\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const hostShared = getNamespace().hostSharedModules;\n const polyfill = {\n 'next/dist/client/components/navigation':\n hostShared['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n hostShared['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n logWarn(\n 'Polyfill',\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n hostShared['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n // Instead of replacing next/image entirely, we let the real Next.js Image\n // component load from the remote bundle and only replace its default loader.\n // This gives us full next/image fidelity (fill, priority, srcSet, blur\n // placeholders, error handling) while routing image optimization through the\n // remote app's /_next/image endpoint.\n 'next/dist/shared/lib/image-loader':\n hostShared['next/dist/shared/lib/image-loader'] ??\n shared?.['next/dist/shared/lib/image-loader'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n })),\n 'next/dist/client/script':\n hostShared['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n hostShared['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/esm/shared/lib/image-loader'] = polyfill[\n 'next/dist/shared/lib/image-loader'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsEc;AArEd,iCAAwC;AACxC,uBAA6B;AAE7B,oBAAwB;AAKjB,SAAS,gBACd,QACA,kBACA;AACA,QAAM,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UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,IACL,qCAAqC,MACnC,QAAQ,QAAQ;AAAA,MACd,SAAS;AAAA,QACP,KAAK;AAAA,UACH,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,EACL;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,uCAAuC,IAAI,SAClD,mCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createRemoteImageLoader } from "#internal/host/shared/remote-image-loader";
|
|
3
|
+
import { getNamespace } from "#internal/runtime/namespace";
|
|
3
4
|
import { logWarn } from "#internal/utils/logger";
|
|
4
5
|
function sharedPolyfills(shared, resolveClientUrl) {
|
|
5
|
-
const
|
|
6
|
+
const hostShared = getNamespace().hostSharedModules;
|
|
6
7
|
const polyfill = {
|
|
7
|
-
"next/dist/client/components/navigation":
|
|
8
|
+
"next/dist/client/components/navigation": hostShared["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
|
|
8
9
|
useRouter() {
|
|
9
10
|
return {
|
|
10
11
|
push: (routerUrl) => {
|
|
@@ -35,7 +36,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
35
36
|
},
|
|
36
37
|
__esModule: true
|
|
37
38
|
})),
|
|
38
|
-
"next/dist/client/app-dir/link":
|
|
39
|
+
"next/dist/client/app-dir/link": hostShared["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
|
|
39
40
|
default: ({
|
|
40
41
|
scroll: _,
|
|
41
42
|
replace,
|
|
@@ -85,7 +86,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
85
86
|
},
|
|
86
87
|
__esModule: true
|
|
87
88
|
})),
|
|
88
|
-
"next/dist/client/app-dir/form":
|
|
89
|
+
"next/dist/client/app-dir/form": hostShared["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
|
|
89
90
|
default: () => {
|
|
90
91
|
throw new Error("Next.js <Form> component not implemented");
|
|
91
92
|
},
|
|
@@ -96,17 +97,17 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
96
97
|
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
97
98
|
// placeholders, error handling) while routing image optimization through the
|
|
98
99
|
// remote app's /_next/image endpoint.
|
|
99
|
-
"next/dist/shared/lib/image-loader":
|
|
100
|
+
"next/dist/shared/lib/image-loader": hostShared["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
|
|
100
101
|
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
101
102
|
__esModule: true
|
|
102
103
|
})),
|
|
103
|
-
"next/dist/client/script":
|
|
104
|
+
"next/dist/client/script": hostShared["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
|
|
104
105
|
// TODO: implement <Script> component for non-Next.js host applications
|
|
105
106
|
// do not throw an error for now
|
|
106
107
|
default: () => null,
|
|
107
108
|
__esModule: true
|
|
108
109
|
})),
|
|
109
|
-
"next/router":
|
|
110
|
+
"next/router": hostShared["next/router"] ?? shared?.["next/router"] ?? (() => (
|
|
110
111
|
// TODO: incomplete implementation
|
|
111
112
|
Promise.resolve({
|
|
112
113
|
useRouter() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport { logWarn } from '#internal/utils/logger';\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport { logWarn } from '#internal/utils/logger';\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const hostShared = getNamespace().hostSharedModules;\n const polyfill = {\n 'next/dist/client/components/navigation':\n hostShared['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n hostShared['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n logWarn(\n 'Polyfill',\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n hostShared['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n // Instead of replacing next/image entirely, we let the real Next.js Image\n // component load from the remote bundle and only replace its default loader.\n // This gives us full next/image fidelity (fill, priority, srcSet, blur\n // placeholders, error handling) while routing image optimization through the\n // remote app's /_next/image endpoint.\n 'next/dist/shared/lib/image-loader':\n hostShared['next/dist/shared/lib/image-loader'] ??\n shared?.['next/dist/shared/lib/image-loader'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n })),\n 'next/dist/client/script':\n hostShared['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n hostShared['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/esm/shared/lib/image-loader'] = polyfill[\n 'next/dist/shared/lib/image-loader'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":"AAsEc;AArEd,SAAS,+BAA+B;AACxC,SAAS,oBAAoB;AAE7B,SAAS,eAAe;AAKjB,SAAS,gBACd,QACA,kBACA;AACA,QAAM,aAAa,aAAa,EAAE;AAClC,QAAM,WAAW;AAAA,IACf,0CACE,WAAW,iBAAiB,KAC5B,SAAS,iBAAiB,MACzB,MACC,QAAQ,QAAQ;AAAA,MACd,YAAY;AACV,eAAO;AAAA,UACL,MAAM,CAAC,cAAsB;AAC3B,oBAAQ,UAAU,CAAC,GAAG,IAAI,SAAS;AAAA,UACrC;AAAA,UACA,SAAS,CAAC,cAAsB;AAC9B,oBAAQ,aAAa,CAAC,GAAG,IAAI,SAAS;AAAA,UACxC;AAAA,UACA,MAAM,MAAM;AACV,oBAAQ,KAAK;AAAA,UACf;AAAA,QACF;AAAA,MACF;AAAA,MACA,cAAc;AACZ,eAAO,SAAS;AAAA,MAClB;AAAA,MACA,YAAY;AACV,eAAO,CAAC;AAAA,MACV;AAAA,MACA,kBAAkB;AAChB,eAAO,IAAI,gBAAgB,SAAS,MAAM;AAAA,MAC5C;AAAA,MACA,2BAA2B;AACzB,eAAO;AAAA,MACT;AAAA,MACA,4BAA4B;AAC1B,eAAO,CAAC;AAAA,MACV;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,IACL,iCACE,WAAW,WAAW,KACtB,SAAS,WAAW,MACnB,MACC,QAAQ,QAAQ;AAAA,MACd,SAAS,CAAC;AAAA,QACR,QAAQ;AAAA,QACR;AAA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