remote-components 0.3.5 → 0.3.7
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/app-63L5THIQ.js +12 -0
- package/dist/app-63L5THIQ.js.map +1 -0
- package/dist/app-A5QE7XRH.cjs +12 -0
- package/dist/app-A5QE7XRH.cjs.map +1 -0
- package/dist/chunk-52BJ7VFA.js +202 -0
- package/dist/chunk-52BJ7VFA.js.map +1 -0
- package/dist/chunk-AWWWK2ZY.cjs +670 -0
- package/dist/chunk-AWWWK2ZY.cjs.map +1 -0
- package/dist/chunk-CTUJSWCM.js +215 -0
- package/dist/chunk-CTUJSWCM.js.map +1 -0
- package/dist/chunk-D5GNZB6O.js +61 -0
- package/dist/chunk-D5GNZB6O.js.map +1 -0
- package/dist/chunk-ENYGL5CO.js +11 -0
- package/dist/chunk-ENYGL5CO.js.map +1 -0
- package/dist/chunk-GAXJTFBV.js +20 -0
- package/dist/chunk-GAXJTFBV.js.map +1 -0
- package/dist/chunk-GBFUPMMI.js +670 -0
- package/dist/chunk-GBFUPMMI.js.map +1 -0
- package/dist/chunk-I47KE3EC.cjs +703 -0
- package/dist/chunk-I47KE3EC.cjs.map +1 -0
- package/dist/chunk-KE7QPAQ4.cjs +21 -0
- package/dist/chunk-KE7QPAQ4.cjs.map +1 -0
- package/dist/chunk-LCXO7BUY.cjs +57 -0
- package/dist/chunk-LCXO7BUY.cjs.map +1 -0
- package/dist/chunk-LQ7VQ74E.js +155 -0
- package/dist/chunk-LQ7VQ74E.js.map +1 -0
- package/dist/chunk-N5VQR2PW.cjs +215 -0
- package/dist/chunk-N5VQR2PW.cjs.map +1 -0
- package/dist/chunk-NZAB7REE.js +703 -0
- package/dist/chunk-NZAB7REE.js.map +1 -0
- package/dist/chunk-QKB74MLO.js +709 -0
- package/dist/chunk-QKB74MLO.js.map +1 -0
- package/dist/chunk-RJW3EZJP.cjs +709 -0
- package/dist/chunk-RJW3EZJP.cjs.map +1 -0
- package/dist/chunk-RUWR74XQ.cjs +152 -0
- package/dist/chunk-RUWR74XQ.cjs.map +1 -0
- package/dist/chunk-S2A4TFLS.js +152 -0
- package/dist/chunk-S2A4TFLS.js.map +1 -0
- package/dist/chunk-SHFJ5OQA.cjs +11 -0
- package/dist/chunk-SHFJ5OQA.cjs.map +1 -0
- package/dist/chunk-SJM7AAGU.js +358 -0
- package/dist/chunk-SJM7AAGU.js.map +1 -0
- package/dist/chunk-SZFCBE54.js +57 -0
- package/dist/chunk-SZFCBE54.js.map +1 -0
- package/dist/chunk-T64P7BAG.cjs +202 -0
- package/dist/chunk-T64P7BAG.cjs.map +1 -0
- package/dist/chunk-TCFLEBQM.cjs +20 -0
- package/dist/chunk-TCFLEBQM.cjs.map +1 -0
- package/dist/chunk-TZT7DLO5.cjs +155 -0
- package/dist/chunk-TZT7DLO5.cjs.map +1 -0
- package/dist/chunk-X6W464D6.cjs +358 -0
- package/dist/chunk-X6W464D6.cjs.map +1 -0
- package/dist/chunk-X6YKUJKH.js +21 -0
- package/dist/chunk-X6YKUJKH.js.map +1 -0
- package/dist/chunk-Z2SLBFQL.cjs +61 -0
- package/dist/chunk-Z2SLBFQL.cjs.map +1 -0
- package/dist/config/nextjs.cjs +74 -355
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +25 -271
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +12 -240
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +6 -207
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/html.cjs +128 -2494
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +45 -2382
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +53 -2939
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +31 -2894
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/proxy/client.cjs +8 -38
- package/dist/host/proxy/client.cjs.map +1 -1
- package/dist/host/proxy/client.js +4 -7
- package/dist/host/proxy/client.js.map +1 -1
- package/dist/host/proxy.cjs +19 -56
- package/dist/host/proxy.cjs.map +1 -1
- package/dist/host/proxy.js +8 -20
- package/dist/host/proxy.js.map +1 -1
- package/dist/host/react.cjs +17 -2870
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +13 -2837
- package/dist/host/react.js.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +27 -15
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -5
- package/dist/internal/config/webpack/next-client-pages-loader.js +27 -15
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.d.ts +1 -1
- package/dist/internal/host/react/context.d.ts +2 -2
- package/dist/internal/host/server/fetch-remote-component.cjs +1 -18
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +1 -18
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/pipeline.d.ts +2 -2
- package/dist/internal/runtime/loaders/component-loader.cjs +5 -2
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.d.ts +2 -2
- package/dist/internal/runtime/loaders/component-loader.js +5 -2
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.d.ts +2 -1
- package/dist/internal/runtime/namespace.cjs +1 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -1
- package/dist/internal/runtime/namespace.d.ts +2 -1
- package/dist/internal/runtime/namespace.js +1 -0
- package/dist/internal/runtime/namespace.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.cjs +1 -5
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +1 -5
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/runtime/types.d.ts +2 -1
- package/dist/internal/utils.cjs +1 -1
- package/dist/internal/utils.cjs.map +1 -1
- package/dist/internal/utils.d.ts +5 -5
- package/dist/internal/utils.js +1 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/remote/html.cjs +15 -314
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +7 -305
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/middleware.cjs +16 -41
- package/dist/remote/middleware.cjs.map +1 -1
- package/dist/script-D5AD7HLV.cjs +26 -0
- package/dist/script-D5AD7HLV.cjs.map +1 -0
- package/dist/script-VPOI7ARP.js +26 -0
- package/dist/script-VPOI7ARP.js.map +1 -0
- package/dist/{server-handoff-ce13bebc.d.ts → server-handoff-8c89b856.d.ts} +2 -2
- package/dist/static-loader-OHSAUD62.js +11 -0
- package/dist/static-loader-OHSAUD62.js.map +1 -0
- package/dist/static-loader-UDIXK5MV.cjs +11 -0
- package/dist/static-loader-UDIXK5MV.cjs.map +1 -0
- package/dist/turbopack-5LW6V6IT.js +55 -0
- package/dist/turbopack-5LW6V6IT.js.map +1 -0
- package/dist/turbopack-KRKECGY2.cjs +55 -0
- package/dist/turbopack-KRKECGY2.cjs.map +1 -0
- package/dist/{types-59251814.d.ts → types-8b0edd78.d.ts} +7 -0
- package/dist/webpack-NPZNXRNL.js +92 -0
- package/dist/webpack-NPZNXRNL.js.map +1 -0
- package/dist/webpack-TTZDARNY.cjs +92 -0
- package/dist/webpack-TTZDARNY.cjs.map +1 -0
- package/package.json +9 -2
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bindResolveClientUrl,
|
|
3
|
+
createHostState,
|
|
4
|
+
fetchWithHooks,
|
|
5
|
+
getClientOrServerUrl,
|
|
6
|
+
loadPrepared,
|
|
7
|
+
makeReactEmitter,
|
|
8
|
+
preparePipeline,
|
|
9
|
+
resolveNameFromSrc
|
|
10
|
+
} from "./chunk-NZAB7REE.js";
|
|
11
|
+
import {
|
|
12
|
+
loadStaticRemoteComponent
|
|
13
|
+
} from "./chunk-LQ7VQ74E.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_COMPONENT_NAME,
|
|
16
|
+
DEFAULT_ROUTE,
|
|
17
|
+
RUNTIME_SCRIPT,
|
|
18
|
+
RUNTIME_WEBPACK,
|
|
19
|
+
attrToProp,
|
|
20
|
+
escapeString
|
|
21
|
+
} from "./chunk-SJM7AAGU.js";
|
|
22
|
+
import {
|
|
23
|
+
getNamespace
|
|
24
|
+
} from "./chunk-D5GNZB6O.js";
|
|
25
|
+
import {
|
|
26
|
+
RemoteComponentsError,
|
|
27
|
+
errorFromFailedFetch,
|
|
28
|
+
isAbortError
|
|
29
|
+
} from "./chunk-S2A4TFLS.js";
|
|
30
|
+
|
|
31
|
+
// src/host/react/index.tsx
|
|
32
|
+
import {
|
|
33
|
+
startTransition,
|
|
34
|
+
useEffect,
|
|
35
|
+
useId,
|
|
36
|
+
useLayoutEffect as useLayoutEffect2,
|
|
37
|
+
useMemo as useMemo2,
|
|
38
|
+
useRef as useRef2,
|
|
39
|
+
useState as useState2
|
|
40
|
+
} from "react";
|
|
41
|
+
import { createPortal } from "react-dom";
|
|
42
|
+
import { useRemoteComponentsContext as useRemoteComponentsContext2 } from "#internal/host/react/context";
|
|
43
|
+
|
|
44
|
+
// src/runtime/html/set-attributes-from-props.ts
|
|
45
|
+
var DOMAttributeNames = {
|
|
46
|
+
acceptCharset: "accept-charset",
|
|
47
|
+
className: "class",
|
|
48
|
+
htmlFor: "for",
|
|
49
|
+
httpEquiv: "http-equiv",
|
|
50
|
+
noModule: "noModule"
|
|
51
|
+
};
|
|
52
|
+
var ignoreProps = [
|
|
53
|
+
"onLoad",
|
|
54
|
+
"onReady",
|
|
55
|
+
"dangerouslySetInnerHTML",
|
|
56
|
+
"children",
|
|
57
|
+
"onError",
|
|
58
|
+
"strategy",
|
|
59
|
+
"stylesheets"
|
|
60
|
+
];
|
|
61
|
+
function isBooleanScriptAttribute(attr) {
|
|
62
|
+
return ["async", "defer", "noModule"].includes(attr);
|
|
63
|
+
}
|
|
64
|
+
function setAttributesFromProps(el, props) {
|
|
65
|
+
for (const [p, value] of Object.entries(props)) {
|
|
66
|
+
if (!Object.hasOwn(props, p))
|
|
67
|
+
continue;
|
|
68
|
+
if (ignoreProps.includes(p))
|
|
69
|
+
continue;
|
|
70
|
+
if (value === void 0) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const attr = DOMAttributeNames[p] || p.toLowerCase();
|
|
74
|
+
if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
|
|
75
|
+
el[attr] = Boolean(value);
|
|
76
|
+
} else {
|
|
77
|
+
el.setAttribute(attr, String(value));
|
|
78
|
+
}
|
|
79
|
+
if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
|
|
80
|
+
el.setAttribute(attr, "");
|
|
81
|
+
el.removeAttribute(attr);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/host/react/hooks/use-resolve-client-url.ts
|
|
87
|
+
import { useMemo } from "react";
|
|
88
|
+
import { useRemoteComponentsContext } from "#internal/host/react/context";
|
|
89
|
+
function useResolveClientUrl(prop, urlHref) {
|
|
90
|
+
const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
|
|
91
|
+
const raw = prop ?? contextValue;
|
|
92
|
+
return useMemo(() => bindResolveClientUrl(raw, urlHref), [raw, urlHref]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/host/react/hooks/use-shadow-root.ts
|
|
96
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
97
|
+
function useShadowRoot({
|
|
98
|
+
isolate,
|
|
99
|
+
mode,
|
|
100
|
+
keySuffix
|
|
101
|
+
}) {
|
|
102
|
+
const shadowRootContainerRef = useRef(null);
|
|
103
|
+
const [shadowRoot, setShadowRoot] = useState(() => {
|
|
104
|
+
const shadowRoots = getNamespace().shadowRoots;
|
|
105
|
+
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
106
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
107
|
+
)?.shadowRoot ?? shadowRoots[keySuffix] ?? null : null;
|
|
108
|
+
shadowRoots[keySuffix] = null;
|
|
109
|
+
return ssrShadowRoot;
|
|
110
|
+
});
|
|
111
|
+
useLayoutEffect(() => {
|
|
112
|
+
const shadowRoots = getNamespace().shadowRoots;
|
|
113
|
+
if (isolate !== false && typeof document !== "undefined" && (!shadowRoot || !shadowRoot.isConnected)) {
|
|
114
|
+
let shadowRootElement = null;
|
|
115
|
+
const element = document.querySelector(
|
|
116
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
117
|
+
);
|
|
118
|
+
shadowRootElement = shadowRoots[keySuffix] ?? element?.shadowRoot ?? null;
|
|
119
|
+
if (!shadowRootElement && element) {
|
|
120
|
+
try {
|
|
121
|
+
shadowRootElement = element.attachShadow({ mode });
|
|
122
|
+
shadowRoots[keySuffix] = shadowRootElement;
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (shadowRootElement) {
|
|
127
|
+
shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
|
|
128
|
+
node.remove();
|
|
129
|
+
});
|
|
130
|
+
setShadowRoot(shadowRootElement);
|
|
131
|
+
}
|
|
132
|
+
} else if (isolate === false && shadowRoot) {
|
|
133
|
+
shadowRoots[keySuffix] = null;
|
|
134
|
+
setShadowRoot(null);
|
|
135
|
+
}
|
|
136
|
+
}, [isolate, shadowRoot, mode, keySuffix]);
|
|
137
|
+
return { shadowRoot, shadowRootContainerRef };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/host/react/utils/extract-remote-html.ts
|
|
141
|
+
var DUMMY_FALLBACK = "http://remote-components-dummy-fallback";
|
|
142
|
+
function getRemoteComponentHtml(html) {
|
|
143
|
+
if (typeof document === "undefined")
|
|
144
|
+
return html;
|
|
145
|
+
const parser = new DOMParser();
|
|
146
|
+
const temp = parser.parseFromString(html, "text/html");
|
|
147
|
+
const ssrRemoteComponentContainer = temp.querySelector(
|
|
148
|
+
'div[id^="__REMOTE_COMPONENT"]'
|
|
149
|
+
);
|
|
150
|
+
if (ssrRemoteComponentContainer) {
|
|
151
|
+
return ssrRemoteComponentContainer.innerHTML;
|
|
152
|
+
}
|
|
153
|
+
const remoteComponentContainer = temp.querySelectorAll(
|
|
154
|
+
`div[data-bundle][data-route][data-runtime][id^="${DEFAULT_COMPONENT_NAME}"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
|
|
155
|
+
);
|
|
156
|
+
if (remoteComponentContainer.length > 0) {
|
|
157
|
+
return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
|
|
158
|
+
}
|
|
159
|
+
return "";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/host/react/index.tsx
|
|
163
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
164
|
+
import { createElement } from "react";
|
|
165
|
+
function ConsumeRemoteComponent({
|
|
166
|
+
src,
|
|
167
|
+
isolate,
|
|
168
|
+
mode = "open",
|
|
169
|
+
reset,
|
|
170
|
+
credentials: credentialsProp,
|
|
171
|
+
name: nameProp = DEFAULT_COMPONENT_NAME,
|
|
172
|
+
shared: sharedProp,
|
|
173
|
+
children,
|
|
174
|
+
onBeforeLoad,
|
|
175
|
+
onLoad,
|
|
176
|
+
onError,
|
|
177
|
+
onChange,
|
|
178
|
+
onRequest,
|
|
179
|
+
onResponse,
|
|
180
|
+
resolveClientUrl: resolveClientUrlProp
|
|
181
|
+
}) {
|
|
182
|
+
const instanceId = useId();
|
|
183
|
+
const { credentials: contextCredentials, shared: contextShared } = useRemoteComponentsContext2();
|
|
184
|
+
const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
|
|
185
|
+
const shared = sharedProp ?? contextShared ?? {};
|
|
186
|
+
const emitter = useMemo2(
|
|
187
|
+
() => makeReactEmitter({ onBeforeLoad, onLoad, onError, onChange }),
|
|
188
|
+
[onBeforeLoad, onLoad, onError, onChange]
|
|
189
|
+
);
|
|
190
|
+
const name = useMemo2(
|
|
191
|
+
() => resolveNameFromSrc(src, nameProp),
|
|
192
|
+
[src, nameProp]
|
|
193
|
+
);
|
|
194
|
+
const [data, setData] = useState2(
|
|
195
|
+
null
|
|
196
|
+
);
|
|
197
|
+
const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
198
|
+
const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);
|
|
199
|
+
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
200
|
+
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
201
|
+
data?.name ?? name
|
|
202
|
+
)}_${escapeString(instanceId)}`;
|
|
203
|
+
const [remoteComponent, setRemoteComponent] = useState2(null);
|
|
204
|
+
const { shadowRoot, shadowRootContainerRef } = useShadowRoot({
|
|
205
|
+
isolate,
|
|
206
|
+
mode,
|
|
207
|
+
keySuffix
|
|
208
|
+
});
|
|
209
|
+
const htmlRef = useRef2(
|
|
210
|
+
typeof document !== "undefined" ? document.querySelector(
|
|
211
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
212
|
+
)?.shadowRoot?.innerHTML ?? document.getElementById(`__REMOTE_COMPONENT${name}`)?.innerHTML ?? document.querySelector(`div[data-bundle][data-route][id^="${name}"]`)?.innerHTML ?? document.querySelector("div[data-bundle][data-route]")?.innerHTML : null
|
|
213
|
+
);
|
|
214
|
+
const endTemplateRef = useRef2(null);
|
|
215
|
+
const childrenRef = useRef2(
|
|
216
|
+
typeof document !== "undefined" ? (() => {
|
|
217
|
+
let el = document.querySelector(`template[id="${name}_start"]`);
|
|
218
|
+
const elements = [];
|
|
219
|
+
while (el && el.id !== `${name}_end`) {
|
|
220
|
+
if (el.id !== `${name}_start` && !el.getAttribute("data-remote-component")) {
|
|
221
|
+
elements.push(el);
|
|
222
|
+
}
|
|
223
|
+
el = el.nextElementSibling;
|
|
224
|
+
}
|
|
225
|
+
return elements;
|
|
226
|
+
})() : []
|
|
227
|
+
);
|
|
228
|
+
const hostStateRef = useRef2(createHostState());
|
|
229
|
+
const componentHydrationHtml = useRef2(null);
|
|
230
|
+
const prevRemoteComponentContainerRef = useRef2(null);
|
|
231
|
+
const unmountRef = useRef2(null);
|
|
232
|
+
useLayoutEffect2(() => {
|
|
233
|
+
return () => {
|
|
234
|
+
delete getNamespace().shadowRoots[keySuffix];
|
|
235
|
+
};
|
|
236
|
+
}, [keySuffix]);
|
|
237
|
+
useLayoutEffect2(() => {
|
|
238
|
+
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
239
|
+
childrenRef.current.forEach((el) => {
|
|
240
|
+
el.remove();
|
|
241
|
+
});
|
|
242
|
+
childrenRef.current = [];
|
|
243
|
+
}
|
|
244
|
+
}, [remoteComponent]);
|
|
245
|
+
useLayoutEffect2(() => {
|
|
246
|
+
if (shadowRoot && remoteComponent) {
|
|
247
|
+
const resetStyles = shadowRoot.querySelectorAll(
|
|
248
|
+
"style[data-remote-components-reset]"
|
|
249
|
+
);
|
|
250
|
+
if (resetStyles.length > 1) {
|
|
251
|
+
resetStyles.forEach((style, index) => {
|
|
252
|
+
if (index > 0 && style.getAttribute("data-remote-components-reset") !== "react") {
|
|
253
|
+
style.remove();
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
htmlRef.current = null;
|
|
258
|
+
let el = shadowRoot.childNodes[0] ?? null;
|
|
259
|
+
while (el && (!("id" in el) || el.id !== `${name}_start`)) {
|
|
260
|
+
const nextEl = el.nextSibling;
|
|
261
|
+
if (el.nodeName !== "LINK" && el.nodeName !== "STYLE") {
|
|
262
|
+
el.parentNode?.removeChild(el);
|
|
263
|
+
}
|
|
264
|
+
el = nextEl;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}, [shadowRoot, remoteComponent, name]);
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (src && src !== hostStateRef.current.prevSrc) {
|
|
270
|
+
const previousSrc = hostStateRef.current.prevSrc;
|
|
271
|
+
const previousName = hostStateRef.current.prevName;
|
|
272
|
+
hostStateRef.current.prevSrc = src;
|
|
273
|
+
if (previousSrc !== null) {
|
|
274
|
+
htmlRef.current = null;
|
|
275
|
+
}
|
|
276
|
+
hostStateRef.current.abortController?.abort();
|
|
277
|
+
hostStateRef.current.abortController = new AbortController();
|
|
278
|
+
const { signal } = hostStateRef.current.abortController;
|
|
279
|
+
emitter.beforeLoad(src);
|
|
280
|
+
hostStateRef.current.stage = "loading";
|
|
281
|
+
startTransition(async () => {
|
|
282
|
+
try {
|
|
283
|
+
let html = getRemoteComponentHtml(
|
|
284
|
+
htmlRef.current ?? (endTemplateRef.current?.previousElementSibling?.tagName === "div" ? endTemplateRef.current.previousElementSibling.innerHTML : "")
|
|
285
|
+
);
|
|
286
|
+
if (!html && src) {
|
|
287
|
+
const fetchInit = {
|
|
288
|
+
credentials
|
|
289
|
+
};
|
|
290
|
+
const resolvedUrl = new URL(
|
|
291
|
+
resolveClientUrl?.(url.href) ?? url.href,
|
|
292
|
+
location.href
|
|
293
|
+
);
|
|
294
|
+
const res = await fetchWithHooks(resolvedUrl, fetchInit, {
|
|
295
|
+
onRequest,
|
|
296
|
+
onResponse,
|
|
297
|
+
abortController: hostStateRef.current.abortController
|
|
298
|
+
});
|
|
299
|
+
if (!res || !res.ok) {
|
|
300
|
+
throw await errorFromFailedFetch(url.href, resolvedUrl, res);
|
|
301
|
+
}
|
|
302
|
+
const remoteHtml = await res.text();
|
|
303
|
+
if (signal.aborted)
|
|
304
|
+
return;
|
|
305
|
+
htmlRef.current = remoteHtml;
|
|
306
|
+
html = getRemoteComponentHtml(remoteHtml);
|
|
307
|
+
}
|
|
308
|
+
if (signal.aborted)
|
|
309
|
+
return;
|
|
310
|
+
const userShared = await shared;
|
|
311
|
+
if (signal.aborted)
|
|
312
|
+
return;
|
|
313
|
+
const prepared = preparePipeline({
|
|
314
|
+
html,
|
|
315
|
+
name,
|
|
316
|
+
url,
|
|
317
|
+
shared: userShared,
|
|
318
|
+
resolveClientUrl
|
|
319
|
+
});
|
|
320
|
+
const { doc, parsed } = prepared;
|
|
321
|
+
const {
|
|
322
|
+
component,
|
|
323
|
+
name: remoteName,
|
|
324
|
+
isRemoteComponent,
|
|
325
|
+
metadata,
|
|
326
|
+
rsc,
|
|
327
|
+
remoteShared,
|
|
328
|
+
links: linkElements
|
|
329
|
+
} = parsed;
|
|
330
|
+
if (hostStateRef.current.prevIsRemoteComponent) {
|
|
331
|
+
if (shadowRoot) {
|
|
332
|
+
shadowRoot.innerHTML = "";
|
|
333
|
+
}
|
|
334
|
+
const prevUrl = hostStateRef.current.prevUrl;
|
|
335
|
+
if (prevUrl && getNamespace().unmountFns[prevUrl.href]) {
|
|
336
|
+
const unmountPromises = Promise.all(
|
|
337
|
+
Array.from(unmountRef.current ?? []).map(
|
|
338
|
+
async (unmount) => unmount(
|
|
339
|
+
shadowRoot ?? prevRemoteComponentContainerRef.current
|
|
340
|
+
)
|
|
341
|
+
)
|
|
342
|
+
);
|
|
343
|
+
unmountRef.current = null;
|
|
344
|
+
await unmountPromises;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
hostStateRef.current.prevIsRemoteComponent = isRemoteComponent;
|
|
348
|
+
hostStateRef.current.prevUrl = url;
|
|
349
|
+
hostStateRef.current.prevName = remoteName;
|
|
350
|
+
const links = linkElements.map((link) => ({
|
|
351
|
+
href: new URL(link.getAttribute("href") ?? link.href, url).href,
|
|
352
|
+
...link.getAttributeNames().reduce((acc, key) => {
|
|
353
|
+
if (key !== "href") {
|
|
354
|
+
acc[attrToProp[key] ?? key] = link.getAttribute(key) ?? "";
|
|
355
|
+
}
|
|
356
|
+
return acc;
|
|
357
|
+
}, {})
|
|
358
|
+
}));
|
|
359
|
+
const inlineScripts = (isRemoteComponent ? component : doc).querySelectorAll(
|
|
360
|
+
"script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
|
|
361
|
+
);
|
|
362
|
+
if (!isRemoteComponent) {
|
|
363
|
+
const self = globalThis;
|
|
364
|
+
const prevNextScripts = self.__next_s;
|
|
365
|
+
const nextScripts = [];
|
|
366
|
+
self.__next_s = nextScripts;
|
|
367
|
+
await Promise.all(
|
|
368
|
+
Array.from(inlineScripts).filter(
|
|
369
|
+
(script) => !(script.id.endsWith("_shared") && script.getAttribute("type") === "application/json" && typeof script.getAttribute(
|
|
370
|
+
"data-remote-components-shared"
|
|
371
|
+
) === "string")
|
|
372
|
+
).map((script) => {
|
|
373
|
+
return new Promise((resolve) => {
|
|
374
|
+
if (script.textContent && !script.textContent.includes("self.__next_f=") && !script.textContent.includes("self.__next_f.push")) {
|
|
375
|
+
if (!script.getAttribute("type") || script.getAttribute("type") === "text/javascript" || script.getAttribute("type") === "application/javascript") {
|
|
376
|
+
const newScript = document.createElement("script");
|
|
377
|
+
const blob = new Blob([script.textContent], {
|
|
378
|
+
type: "application/javascript"
|
|
379
|
+
});
|
|
380
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
381
|
+
newScript.onload = () => {
|
|
382
|
+
resolve(void 0);
|
|
383
|
+
URL.revokeObjectURL(blobUrl);
|
|
384
|
+
newScript.remove();
|
|
385
|
+
};
|
|
386
|
+
newScript.onerror = () => {
|
|
387
|
+
URL.revokeObjectURL(blobUrl);
|
|
388
|
+
newScript.remove();
|
|
389
|
+
resolve(void 0);
|
|
390
|
+
};
|
|
391
|
+
newScript.src = blobUrl;
|
|
392
|
+
document.body.appendChild(newScript);
|
|
393
|
+
} else {
|
|
394
|
+
resolve(void 0);
|
|
395
|
+
document.body.appendChild(script);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
resolve(void 0);
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
})
|
|
402
|
+
);
|
|
403
|
+
nextScripts.forEach(([scriptSrc, props]) => {
|
|
404
|
+
const script = document.createElement("script");
|
|
405
|
+
if (scriptSrc) {
|
|
406
|
+
script.src = scriptSrc;
|
|
407
|
+
}
|
|
408
|
+
if (typeof props.children === "string") {
|
|
409
|
+
script.textContent = props.children;
|
|
410
|
+
}
|
|
411
|
+
setAttributesFromProps(script, props);
|
|
412
|
+
document.head.appendChild(script);
|
|
413
|
+
});
|
|
414
|
+
self.__next_s = prevNextScripts;
|
|
415
|
+
}
|
|
416
|
+
const rscName = rsc ? `__remote_component_rsc_${escapeString(id)}_${escapeString(
|
|
417
|
+
remoteName
|
|
418
|
+
)}` : void 0;
|
|
419
|
+
if (rsc) {
|
|
420
|
+
rsc.textContent = rsc.textContent?.replace(
|
|
421
|
+
new RegExp(`self\\["${remoteName}"\\]`, "g"),
|
|
422
|
+
`self["${rscName}"]`
|
|
423
|
+
) ?? "";
|
|
424
|
+
document.body.appendChild(rsc);
|
|
425
|
+
}
|
|
426
|
+
const newData = {
|
|
427
|
+
...metadata,
|
|
428
|
+
links,
|
|
429
|
+
remoteShared,
|
|
430
|
+
src: typeof src === "string" ? src : src.href,
|
|
431
|
+
serverUrl: url.href,
|
|
432
|
+
data: rsc ? (rsc.textContent || "").split("\n").filter(Boolean) : []
|
|
433
|
+
};
|
|
434
|
+
componentHydrationHtml.current = `${Array.from(
|
|
435
|
+
doc.querySelectorAll("link,style")
|
|
436
|
+
).map((link) => link.outerHTML).join("")}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
|
|
437
|
+
if (isRemoteComponent) {
|
|
438
|
+
if (previousSrc !== void 0) {
|
|
439
|
+
emitter.change({
|
|
440
|
+
previousSrc: previousSrc ?? null,
|
|
441
|
+
nextSrc: src,
|
|
442
|
+
previousName,
|
|
443
|
+
nextName: remoteName
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
setData(newData);
|
|
447
|
+
if (shadowRoot) {
|
|
448
|
+
const shadowRootHtml = reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>${component.innerHTML}` : component.innerHTML;
|
|
449
|
+
shadowRoot.innerHTML = shadowRootHtml;
|
|
450
|
+
htmlRef.current = null;
|
|
451
|
+
setRemoteComponent(null);
|
|
452
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
453
|
+
Array.from(shadowRoot.querySelectorAll("script")),
|
|
454
|
+
url,
|
|
455
|
+
resolveClientUrl
|
|
456
|
+
);
|
|
457
|
+
unmountRef.current = unmount;
|
|
458
|
+
await Promise.all(
|
|
459
|
+
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
460
|
+
);
|
|
461
|
+
emitter.load(src);
|
|
462
|
+
} else if (isolate === false) {
|
|
463
|
+
setRemoteComponent(
|
|
464
|
+
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
465
|
+
/* @__PURE__ */ jsx(
|
|
466
|
+
"div",
|
|
467
|
+
{
|
|
468
|
+
dangerouslySetInnerHTML: { __html: component.innerHTML },
|
|
469
|
+
ref: prevRemoteComponentContainerRef
|
|
470
|
+
}
|
|
471
|
+
)
|
|
472
|
+
);
|
|
473
|
+
htmlRef.current = null;
|
|
474
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
475
|
+
Array.from(component.querySelectorAll("script")),
|
|
476
|
+
url,
|
|
477
|
+
resolveClientUrl
|
|
478
|
+
);
|
|
479
|
+
unmountRef.current = unmount;
|
|
480
|
+
await Promise.all(
|
|
481
|
+
Array.from(mount).map(
|
|
482
|
+
(mountFn) => mountFn(prevRemoteComponentContainerRef.current)
|
|
483
|
+
)
|
|
484
|
+
);
|
|
485
|
+
emitter.load(src);
|
|
486
|
+
}
|
|
487
|
+
hostStateRef.current.stage = "loaded";
|
|
488
|
+
} else {
|
|
489
|
+
const result = await loadPrepared({
|
|
490
|
+
prepared,
|
|
491
|
+
url,
|
|
492
|
+
signal,
|
|
493
|
+
shared: userShared,
|
|
494
|
+
resolveClientUrl,
|
|
495
|
+
container: shadowRoot,
|
|
496
|
+
rscName
|
|
497
|
+
});
|
|
498
|
+
if (rsc) {
|
|
499
|
+
rsc.remove();
|
|
500
|
+
}
|
|
501
|
+
setData(newData);
|
|
502
|
+
if (previousSrc !== void 0) {
|
|
503
|
+
emitter.change({
|
|
504
|
+
previousSrc: previousSrc ?? null,
|
|
505
|
+
nextSrc: src,
|
|
506
|
+
previousName,
|
|
507
|
+
nextName: remoteName
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
if (result.status === "aborted") {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (result.status === "error") {
|
|
514
|
+
hostStateRef.current.stage = "error";
|
|
515
|
+
setRemoteComponent(result.error);
|
|
516
|
+
emitter.error(result.error);
|
|
517
|
+
} else if (result.status === "loaded") {
|
|
518
|
+
hostStateRef.current.stage = "loaded";
|
|
519
|
+
setRemoteComponent(result.component);
|
|
520
|
+
emitter.load(src);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
} catch (error) {
|
|
524
|
+
if (isAbortError(error)) {
|
|
525
|
+
hostStateRef.current.stage = "idle";
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
hostStateRef.current.stage = "error";
|
|
529
|
+
setRemoteComponent(error);
|
|
530
|
+
emitter.error(error);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
}, [
|
|
535
|
+
url,
|
|
536
|
+
src,
|
|
537
|
+
isolate,
|
|
538
|
+
credentials,
|
|
539
|
+
name,
|
|
540
|
+
shared,
|
|
541
|
+
shadowRoot,
|
|
542
|
+
reset,
|
|
543
|
+
id,
|
|
544
|
+
emitter.beforeLoad,
|
|
545
|
+
emitter.load,
|
|
546
|
+
emitter.error,
|
|
547
|
+
emitter.change,
|
|
548
|
+
onRequest,
|
|
549
|
+
onResponse,
|
|
550
|
+
resolveClientUrl
|
|
551
|
+
]);
|
|
552
|
+
if (remoteComponent instanceof Error) {
|
|
553
|
+
throw remoteComponent;
|
|
554
|
+
}
|
|
555
|
+
const metadataJson = /* @__PURE__ */ jsx("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
|
|
556
|
+
name: data?.name || name,
|
|
557
|
+
bundle: data?.bundle || "default",
|
|
558
|
+
route: data?.route || DEFAULT_ROUTE,
|
|
559
|
+
runtime: hostStateRef.current.prevIsRemoteComponent ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
560
|
+
}) });
|
|
561
|
+
const resetStyle = reset ? /* @__PURE__ */ jsx("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
|
|
562
|
+
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ createElement(
|
|
563
|
+
"link",
|
|
564
|
+
{
|
|
565
|
+
...link,
|
|
566
|
+
href: new URL(link.href, url).href,
|
|
567
|
+
key: JSON.stringify(link)
|
|
568
|
+
}
|
|
569
|
+
)) || null;
|
|
570
|
+
const componentToRender = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
571
|
+
resetStyle,
|
|
572
|
+
linksToRender,
|
|
573
|
+
remoteComponent ?? children
|
|
574
|
+
] });
|
|
575
|
+
if (componentHydrationHtml.current && shadowRoot && !shadowRoot.innerHTML) {
|
|
576
|
+
shadowRoot.innerHTML = componentHydrationHtml.current;
|
|
577
|
+
componentHydrationHtml.current = null;
|
|
578
|
+
if (hostStateRef.current.prevIsRemoteComponent) {
|
|
579
|
+
loadStaticRemoteComponent(
|
|
580
|
+
Array.from(shadowRoot.querySelectorAll("script")),
|
|
581
|
+
url,
|
|
582
|
+
resolveClientUrl
|
|
583
|
+
).then(({ mount }) => {
|
|
584
|
+
return Promise.all(
|
|
585
|
+
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
586
|
+
);
|
|
587
|
+
}).then(() => {
|
|
588
|
+
if (src) {
|
|
589
|
+
emitter.load(src);
|
|
590
|
+
}
|
|
591
|
+
}).catch((e) => {
|
|
592
|
+
const error = new RemoteComponentsError(
|
|
593
|
+
`Error mounting remote component from "${url.href}"`,
|
|
594
|
+
{
|
|
595
|
+
cause: e
|
|
596
|
+
}
|
|
597
|
+
);
|
|
598
|
+
setRemoteComponent(error);
|
|
599
|
+
emitter.error(error);
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (isolate !== false) {
|
|
604
|
+
const shadowRemoteComponentHtml = shadowRoot?.querySelector(`#__REMOTE_COMPONENT${name}`) ?? shadowRoot?.querySelector("div[data-bundle][data-route]");
|
|
605
|
+
if (shadowRemoteComponentHtml) {
|
|
606
|
+
shadowRemoteComponentHtml.remove();
|
|
607
|
+
}
|
|
608
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
609
|
+
metadataJson,
|
|
610
|
+
/* @__PURE__ */ jsxs(
|
|
611
|
+
"div",
|
|
612
|
+
{
|
|
613
|
+
"data-remote-component-id": `shadowroot_${keySuffix}`,
|
|
614
|
+
id: `shadowroot_${data?.name ?? name}`,
|
|
615
|
+
ref: shadowRootContainerRef,
|
|
616
|
+
children: [
|
|
617
|
+
typeof document === "undefined" ? (
|
|
618
|
+
// eslint-disable-next-line react/no-unknown-property
|
|
619
|
+
/* @__PURE__ */ jsxs("template", { shadowrootmode: mode, children: [
|
|
620
|
+
typeof document === "undefined" ? /* @__PURE__ */ jsx(
|
|
621
|
+
"div",
|
|
622
|
+
{
|
|
623
|
+
dangerouslySetInnerHTML: {
|
|
624
|
+
__html: `<img
|
|
625
|
+
alt="" decoding="async" style="display:none"
|
|
626
|
+
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
|
|
627
|
+
onload="(function(el){
|
|
628
|
+
// Capture the shadow root during SSR hydration so the client-side
|
|
629
|
+
// useShadowRoot hook can find it.
|
|
630
|
+
const root = el.getRootNode();
|
|
631
|
+
globalThis.__remote_components_shadowroot_${keySuffix}=root;
|
|
632
|
+
el.parentElement.remove();
|
|
633
|
+
})(this)"
|
|
634
|
+
/>`
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
) : null,
|
|
638
|
+
resetStyle,
|
|
639
|
+
linksToRender,
|
|
640
|
+
children
|
|
641
|
+
] })
|
|
642
|
+
) : null,
|
|
643
|
+
shadowRoot && remoteComponent ? createPortal(
|
|
644
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
645
|
+
/* @__PURE__ */ jsx("template", { id: `${name}_start` }),
|
|
646
|
+
resetStyle,
|
|
647
|
+
linksToRender,
|
|
648
|
+
remoteComponent,
|
|
649
|
+
/* @__PURE__ */ jsx("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
650
|
+
] }),
|
|
651
|
+
shadowRoot
|
|
652
|
+
) : null
|
|
653
|
+
]
|
|
654
|
+
}
|
|
655
|
+
)
|
|
656
|
+
] });
|
|
657
|
+
}
|
|
658
|
+
htmlRef.current = null;
|
|
659
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
660
|
+
/* @__PURE__ */ jsx("template", { id: `${name}_start` }),
|
|
661
|
+
metadataJson,
|
|
662
|
+
componentToRender,
|
|
663
|
+
/* @__PURE__ */ jsx("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
664
|
+
] });
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export {
|
|
668
|
+
ConsumeRemoteComponent
|
|
669
|
+
};
|
|
670
|
+
//# sourceMappingURL=chunk-GBFUPMMI.js.map
|