remote-components 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/html/host.cjs +132 -42
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +131 -42
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/next/config.cjs +53 -12
  6. package/dist/next/config.cjs.map +1 -1
  7. package/dist/next/config.js +53 -12
  8. package/dist/next/config.js.map +1 -1
  9. package/dist/next/host/app-router-client.cjs +1 -1
  10. package/dist/next/host/app-router-client.cjs.map +1 -1
  11. package/dist/next/host/app-router-client.js +1 -1
  12. package/dist/next/host/app-router-client.js.map +1 -1
  13. package/dist/next/host/client/index.cjs +1 -1
  14. package/dist/next/host/client/index.cjs.map +1 -1
  15. package/dist/next/host/client/index.js +1 -1
  16. package/dist/next/host/client/index.js.map +1 -1
  17. package/dist/next/host/pages-router-client.cjs +2 -2
  18. package/dist/next/host/pages-router-client.cjs.map +1 -1
  19. package/dist/next/host/pages-router-client.js +1 -1
  20. package/dist/next/host/pages-router-client.js.map +1 -1
  21. package/dist/next/host/pages-router-server.cjs +97 -18
  22. package/dist/next/host/pages-router-server.cjs.map +1 -1
  23. package/dist/next/host/pages-router-server.js +88 -19
  24. package/dist/next/host/pages-router-server.js.map +1 -1
  25. package/dist/react/index.cjs +72 -1
  26. package/dist/react/index.cjs.map +1 -1
  27. package/dist/react/index.js +73 -1
  28. package/dist/react/index.js.map +1 -1
  29. package/dist/shared/client/remote-component.cjs +81 -24
  30. package/dist/shared/client/remote-component.cjs.map +1 -1
  31. package/dist/shared/client/remote-component.d.ts +4 -2
  32. package/dist/shared/client/remote-component.js +80 -24
  33. package/dist/shared/client/remote-component.js.map +1 -1
  34. package/package.json +1 -1
@@ -152,27 +152,102 @@ var init_next_client_pages_loader = __esm({
152
152
  }
153
153
  });
154
154
 
155
+ // src/shared/client/polyfill.tsx
156
+ function sharedPolyfills(shared) {
157
+ const self = globalThis;
158
+ const polyfill = {
159
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
160
+ useRouter() {
161
+ return {
162
+ push: (routerUrl) => {
163
+ history.pushState({}, "", routerUrl);
164
+ },
165
+ replace: (routerUrl) => {
166
+ history.replaceState({}, "", routerUrl);
167
+ },
168
+ back: () => {
169
+ history.back();
170
+ }
171
+ };
172
+ },
173
+ useSearchParams() {
174
+ return new URLSearchParams(location.search);
175
+ },
176
+ __esModule: true
177
+ })),
178
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
179
+ default: ({
180
+ children,
181
+ ...props
182
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props, href: props.href, suppressHydrationWarning: true, children: children ?? null }),
183
+ __esModule: true
184
+ })),
185
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
186
+ default: () => {
187
+ throw new Error("Next.js <Form> component not implemented");
188
+ },
189
+ __esModule: true
190
+ })),
191
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? (() => Promise.resolve({
192
+ Image: (props) => (
193
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
194
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
195
+ "img",
196
+ {
197
+ ...props,
198
+ src: props.src,
199
+ suppressHydrationWarning: true
200
+ }
201
+ )
202
+ ),
203
+ __esModule: true
204
+ })),
205
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
206
+ // TODO: implement <Script> component for non-Next.js host applications
207
+ // do not throw an error for now
208
+ default: () => null,
209
+ __esModule: true
210
+ }))
211
+ };
212
+ polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
213
+ polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
214
+ polyfill["next/image"] = polyfill["next/dist/client/image-component"];
215
+ polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
216
+ polyfill["next/script"] = polyfill["next/dist/client/script"];
217
+ return polyfill;
218
+ }
219
+ var import_jsx_runtime;
220
+ var init_polyfill = __esm({
221
+ "src/shared/client/polyfill.tsx"() {
222
+ "use strict";
223
+ import_jsx_runtime = require("react/jsx-runtime");
224
+ }
225
+ });
226
+
155
227
  // src/html/host/runtime/webpack.ts
156
228
  var webpack_exports = {};
157
229
  __export(webpack_exports, {
158
230
  webpackRuntime: () => webpackRuntime
159
231
  });
160
- async function webpackRuntime(shared, remoteShared) {
232
+ async function webpackRuntime(bundle, shared, remoteShared) {
161
233
  const self = globalThis;
162
- self.__DISABLE_WEBPACK_EXEC__ = true;
234
+ if (!self.__DISABLE_WEBPACK_EXEC__) {
235
+ self.__DISABLE_WEBPACK_EXEC__ = {};
236
+ }
237
+ self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
163
238
  if (typeof self.__webpack_require__ !== "function" && self.__webpack_require_type__ !== "turbopack") {
164
239
  self.__webpack_require__ = (remoteId) => {
165
240
  const re = /\[(?<bundle>[^\]]+)\] (?<id>.*)/;
166
241
  const match = re.exec(remoteId);
167
- const bundle = match?.groups?.bundle;
242
+ const remoteBundle = match?.groups?.bundle;
168
243
  const id = match?.groups?.id;
169
- if (!(id && bundle)) {
244
+ if (!(id && remoteBundle)) {
170
245
  throw new Error(`Module not found: "${remoteId}"`);
171
246
  }
172
- if (typeof self.__remote_webpack_require__?.[bundle] !== "function") {
173
- throw new Error(`Remote component loading error "${bundle}"`);
247
+ if (typeof self.__remote_webpack_require__?.[remoteBundle] !== "function") {
248
+ throw new Error(`Remote component loading error "${remoteBundle}"`);
174
249
  }
175
- return self.__remote_webpack_require__[bundle](id);
250
+ return self.__remote_webpack_require__[remoteBundle](id);
176
251
  };
177
252
  self.__webpack_chunk_load__ = () => {
178
253
  return Promise.resolve([]);
@@ -181,7 +256,7 @@ async function webpackRuntime(shared, remoteShared) {
181
256
  const {
182
257
  default: { createFromReadableStream }
183
258
  } = await import("react-server-dom-webpack/client.browser");
184
- async function preloadScripts(scripts, url, bundle, _) {
259
+ async function preloadScripts(scripts, url, remoteBundle, _) {
185
260
  await Promise.all(
186
261
  scripts.map((script) => {
187
262
  return new Promise((resolve2, reject) => {
@@ -210,6 +285,7 @@ async function webpackRuntime(shared, remoteShared) {
210
285
  })
211
286
  );
212
287
  const hostShared = {
288
+ ...sharedPolyfills(shared),
213
289
  ...self.__remote_component_host_shared_modules__,
214
290
  ...shared
215
291
  };
@@ -237,7 +313,7 @@ async function webpackRuntime(shared, remoteShared) {
237
313
  return Promise.resolve(value);
238
314
  })
239
315
  );
240
- applySharedModules(bundle, resolve);
316
+ applySharedModules(remoteBundle, resolve);
241
317
  }
242
318
  return {
243
319
  self,
@@ -252,6 +328,7 @@ var init_webpack = __esm({
252
328
  "use strict";
253
329
  init_shared_modules();
254
330
  init_next_client_pages_loader();
331
+ init_polyfill();
255
332
  }
256
333
  });
257
334
 
@@ -396,6 +473,7 @@ async function handleTurbopackChunk(code, bundle, url) {
396
473
  script.onload = () => {
397
474
  URL.revokeObjectURL(scriptUrl);
398
475
  scriptResolve(void 0);
476
+ script.remove();
399
477
  };
400
478
  script.onerror = (error) => {
401
479
  URL.revokeObjectURL(scriptUrl);
@@ -404,6 +482,7 @@ async function handleTurbopackChunk(code, bundle, url) {
404
482
  `Failed to load script: ${error instanceof Error ? error.message : String(error)}`
405
483
  )
406
484
  );
485
+ script.remove();
407
486
  };
408
487
  document.head.appendChild(script);
409
488
  });
@@ -468,20 +547,11 @@ function initializeSharedModules(bundle, shared = {}, remoteShared = {}) {
468
547
  return Promise.all(
469
548
  Object.entries(remoteShared).map(async ([id, module2]) => {
470
549
  if (self.__remote_shared_modules__?.[bundle]) {
471
- self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await (shared[module2] ?? (() => Promise.resolve(
472
- new Proxy(
473
- {},
474
- {
475
- get(_, prop) {
476
- if (prop !== "then") {
477
- console.warn(
478
- `Shared dependency "${module2}" not found for "${bundle}" when trying to import "${prop}".`
479
- );
480
- }
481
- }
482
- }
483
- )
484
- )))();
550
+ if (shared[module2]) {
551
+ self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await shared[module2]();
552
+ } else {
553
+ console.error(`Shared module "${module2}" not found for "${bundle}".`);
554
+ }
485
555
  }
486
556
  })
487
557
  );
@@ -504,9 +574,17 @@ function handleTurbopackModule(bundle, moduleId, id) {
504
574
  let moduleInit;
505
575
  for (const mod of modules ?? []) {
506
576
  if (typeof mod[1] === "string") {
507
- const index = mod.indexOf(moduleId);
577
+ let index = mod.indexOf(moduleId);
578
+ if (index === -1) {
579
+ index = mod.findIndex(
580
+ (m) => typeof m === "string" && m.startsWith(moduleId)
581
+ );
582
+ }
508
583
  if (index !== -1) {
509
- moduleInit = mod[index + 1];
584
+ while (typeof mod[index] !== "function" && index < mod.length) {
585
+ index++;
586
+ }
587
+ moduleInit = mod[index];
510
588
  break;
511
589
  }
512
590
  } else {
@@ -534,6 +612,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
534
612
  `Module ${id} not found in bundle ${bundle} with id ${moduleId}`
535
613
  );
536
614
  }
615
+ self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
537
616
  moduleInit({
538
617
  // HMR not implemented for Remote Components
539
618
  k: {
@@ -550,11 +629,17 @@ function handleTurbopackModule(bundle, moduleId, id) {
550
629
  let mod = m;
551
630
  if (Array.isArray(m)) {
552
631
  mod = {};
553
- for (let i = 0; i < m.length; i += 2) {
554
- const key = m[i];
555
- const value = m[i + 1];
556
- if (typeof key === "string" && typeof value === "function") {
557
- mod[key] = value;
632
+ const keys = [];
633
+ for (const current of m) {
634
+ if (typeof current === "string") {
635
+ keys.push(current);
636
+ } else if (typeof current === "function") {
637
+ while (keys.length > 0) {
638
+ const key = keys.shift();
639
+ if (key) {
640
+ mod[key] = current;
641
+ }
642
+ }
558
643
  }
559
644
  }
560
645
  }
@@ -569,7 +654,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
569
654
  const mod = self.__webpack_require__?.(
570
655
  `[${bundle}] ${normalizedId}`
571
656
  );
572
- if (exportSource && exportName) {
657
+ if (exportSource && exportName && typeof mod[exportSource] !== "undefined" && typeof mod[exportName] === "undefined") {
573
658
  mod[exportName] = mod[exportSource];
574
659
  }
575
660
  return mod;
@@ -577,6 +662,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
577
662
  r(rid) {
578
663
  return self.__webpack_require__?.(`[${bundle}] ${rid}`);
579
664
  },
665
+ v(value) {
666
+ exports.default = value;
667
+ },
580
668
  m: moduleExports,
581
669
  e: exports
582
670
  });
@@ -585,7 +673,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
585
673
  exports[name] = exports[name]();
586
674
  }
587
675
  }
588
- self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
589
676
  return moduleExports.exports;
590
677
  }
591
678
  var init_webpack_adapter = __esm({
@@ -602,12 +689,18 @@ __export(turbopack_exports, {
602
689
  });
603
690
  async function turbopackRuntime(url, bundle, shared, remoteShared) {
604
691
  const self = globalThis;
692
+ const hostShared = {
693
+ ...sharedPolyfills(shared),
694
+ ...self.__remote_component_host_shared_modules__,
695
+ ...shared,
696
+ ...self.__remote_component_shared__
697
+ };
605
698
  await setupWebpackRuntime(
606
699
  "turbopack",
607
700
  [],
608
701
  url,
609
702
  bundle,
610
- { ...shared, ...self.__remote_component_shared__ },
703
+ hostShared,
611
704
  remoteShared
612
705
  );
613
706
  const {
@@ -621,11 +714,7 @@ async function turbopackRuntime(url, bundle, shared, remoteShared) {
621
714
  })),
622
715
  url,
623
716
  bundle,
624
- {
625
- ...self.__remote_component_host_shared_modules__,
626
- ...shared,
627
- ...self.__remote_component_shared__
628
- },
717
+ hostShared,
629
718
  remoteShared
630
719
  );
631
720
  }
@@ -643,6 +732,7 @@ var init_turbopack = __esm({
643
732
  init_shared_modules();
644
733
  init_next_client_pages_loader();
645
734
  init_webpack_adapter();
735
+ init_polyfill();
646
736
  }
647
737
  });
648
738
 
@@ -728,7 +818,7 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
728
818
  }
729
819
  if (type === "webpack") {
730
820
  const { webpackRuntime: webpackRuntime2 } = await Promise.resolve().then(() => (init_webpack(), webpack_exports));
731
- return webpackRuntime2(shared, remoteShared);
821
+ return webpackRuntime2(bundle ?? "default", shared, remoteShared);
732
822
  } else if (type === "turbopack") {
733
823
  const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
734
824
  return turbopackRuntime2(url, bundle, shared, remoteShared);
@@ -737,7 +827,7 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
737
827
  }
738
828
 
739
829
  // src/html/host/index.tsx
740
- var import_jsx_runtime = require("react/jsx-runtime");
830
+ var import_jsx_runtime2 = require("react/jsx-runtime");
741
831
  if (typeof HTMLElement !== "undefined") {
742
832
  class RemoteComponent extends HTMLElement {
743
833
  constructor() {
@@ -923,7 +1013,7 @@ if (typeof HTMLElement !== "undefined") {
923
1013
  // hydrateRoot expects a document or element, but it works for the shadow DOM too
924
1014
  // @ts-expect-error support for shadow DOM
925
1015
  this.shadowRoot,
926
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RemoteComponentFromReadableStream, { name: this.name })
1016
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromReadableStream, { name: this.name })
927
1017
  );
928
1018
  } else if (nextData) {
929
1019
  const { Component, App } = nextClientPagesLoader2(
@@ -936,7 +1026,7 @@ if (typeof HTMLElement !== "undefined") {
936
1026
  // hydrateRoot expects a document or element, but it works for the shadow DOM too
937
1027
  // @ts-expect-error support for shadow DOM
938
1028
  this.shadowRoot,
939
- App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { Component, ...nextData.props }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...nextData.props })
1029
+ App ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(App, { Component, ...nextData.props }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ...nextData.props })
940
1030
  );
941
1031
  }
942
1032
  if (this.fouc) {