remote-components 0.0.46 → 0.0.47

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 (74) hide show
  1. package/dist/html/host.cjs +50 -7
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +50 -7
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs.map +1 -1
  6. package/dist/html/remote.js.map +1 -1
  7. package/dist/internal/next/host/app-router-client.cjs +6 -6
  8. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  9. package/dist/internal/next/host/app-router-client.js +1 -1
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/host/app-router-compat.cjs +5 -5
  12. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.js +1 -1
  14. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  15. package/dist/internal/shared/client/polyfill.cjs +2 -2
  16. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  17. package/dist/internal/shared/client/polyfill.js +1 -1
  18. package/dist/internal/shared/client/polyfill.js.map +1 -1
  19. package/dist/internal/shared/client/remote-component.cjs +32 -1
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.js +32 -1
  22. package/dist/internal/shared/client/remote-component.js.map +1 -1
  23. package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -6
  24. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  25. package/dist/internal/shared/ssr/fetch-remote-component.js +1 -6
  26. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  27. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +9 -2
  28. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  29. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +6 -1
  30. package/dist/internal/shared/ssr/fetch-with-hooks.js +9 -2
  31. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  32. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +57 -0
  33. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -0
  34. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +11 -0
  35. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +32 -0
  36. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -0
  37. package/dist/internal/shared/{logger.cjs → utils/logger.cjs} +5 -0
  38. package/dist/internal/shared/utils/logger.cjs.map +1 -0
  39. package/dist/internal/shared/{logger.d.ts → utils/logger.d.ts} +3 -2
  40. package/dist/internal/shared/{logger.js → utils/logger.js} +4 -0
  41. package/dist/internal/shared/utils/logger.js.map +1 -0
  42. package/dist/internal/shared/utils.cjs +2 -9
  43. package/dist/internal/shared/utils.cjs.map +1 -1
  44. package/dist/internal/shared/utils.d.ts +0 -2
  45. package/dist/internal/shared/utils.js +1 -5
  46. package/dist/internal/shared/utils.js.map +1 -1
  47. package/dist/next/config.cjs.map +1 -1
  48. package/dist/next/config.js.map +1 -1
  49. package/dist/next/host/client/index.cjs +51 -17
  50. package/dist/next/host/client/index.cjs.map +1 -1
  51. package/dist/next/host/client/index.js +51 -17
  52. package/dist/next/host/client/index.js.map +1 -1
  53. package/dist/next/proxy.cjs +128 -19
  54. package/dist/next/proxy.cjs.map +1 -1
  55. package/dist/next/proxy.d.ts +34 -6
  56. package/dist/next/proxy.js +125 -18
  57. package/dist/next/proxy.js.map +1 -1
  58. package/dist/react/index.cjs +51 -17
  59. package/dist/react/index.cjs.map +1 -1
  60. package/dist/react/index.js +51 -17
  61. package/dist/react/index.js.map +1 -1
  62. package/dist/shared/host/proxy.cjs +79 -0
  63. package/dist/shared/host/proxy.cjs.map +1 -0
  64. package/dist/shared/host/proxy.d.ts +29 -0
  65. package/dist/shared/host/proxy.js +54 -0
  66. package/dist/shared/host/proxy.js.map +1 -0
  67. package/dist/shared/remote/proxy.cjs +71 -0
  68. package/dist/shared/remote/proxy.cjs.map +1 -0
  69. package/dist/shared/remote/proxy.d.ts +38 -0
  70. package/dist/shared/remote/proxy.js +45 -0
  71. package/dist/shared/remote/proxy.js.map +1 -0
  72. package/package.json +10 -1
  73. package/dist/internal/shared/logger.cjs.map +0 -1
  74. package/dist/internal/shared/logger.js.map +0 -1
@@ -62,6 +62,9 @@ function logDebug(location2, message) {
62
62
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
63
63
  }
64
64
  }
65
+ function logInfo(location2, message) {
66
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
67
+ }
65
68
  function logWarn(location2, message) {
66
69
  console.warn(`[${PREFIX}:${location2}]: ${message}`);
67
70
  }
@@ -267,6 +270,41 @@ var init_shared_modules = __esm({
267
270
  }
268
271
  });
269
272
 
273
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
274
+ async function fetchWithProtectedRcFallback(url, init) {
275
+ try {
276
+ const res = await fetch(url, init);
277
+ return res;
278
+ } catch (error) {
279
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
280
+ logInfo(
281
+ "FetchRemoteComponent",
282
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
283
+ );
284
+ const proxiedRes = await fetch(
285
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
286
+ );
287
+ if (proxiedRes.status === 200) {
288
+ return proxiedRes;
289
+ } else {
290
+ logError(
291
+ "FetchRemoteComponent",
292
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
293
+ );
294
+ }
295
+ }
296
+ throw error;
297
+ }
298
+ }
299
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
300
+ var init_fetch_with_protected_rc_fallback = __esm({
301
+ "src/shared/ssr/fetch-with-protected-rc-fallback.ts"() {
302
+ "use strict";
303
+ init_logger();
304
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
305
+ }
306
+ });
307
+
270
308
  // src/shared/utils/index.ts
271
309
  function escapeString(str) {
272
310
  return str.replace(/[^a-z0-9]/g, "_");
@@ -274,7 +312,6 @@ function escapeString(str) {
274
312
  var init_utils = __esm({
275
313
  "src/shared/utils/index.ts"() {
276
314
  "use strict";
277
- init_logger();
278
315
  }
279
316
  });
280
317
 
@@ -336,7 +373,7 @@ function createChunkLoader(runtime) {
336
373
  }
337
374
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
338
375
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
339
- fetch(url).then((res) => res.text()).then((code) => {
376
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
340
377
  const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
341
378
  if (hasTurbopack) {
342
379
  return handleTurbopackChunk(code, bundle ?? "", url);
@@ -489,6 +526,7 @@ var init_chunk_loader = __esm({
489
526
  "src/shared/client/chunk-loader.ts"() {
490
527
  "use strict";
491
528
  init_error();
529
+ init_fetch_with_protected_rc_fallback();
492
530
  init_logger();
493
531
  init_const();
494
532
  }
@@ -1258,7 +1296,7 @@ var import_jsx_runtime, imageImpl;
1258
1296
  var init_polyfill = __esm({
1259
1297
  "src/shared/client/polyfill.tsx"() {
1260
1298
  "use strict";
1261
- init_utils();
1299
+ init_logger();
1262
1300
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
1263
1301
  import_jsx_runtime = require("react/jsx-runtime");
1264
1302
  imageImpl = (bundle) => function RemoteImage({
@@ -1663,11 +1701,17 @@ function remoteFetchHeaders() {
1663
1701
  }
1664
1702
 
1665
1703
  // src/shared/ssr/fetch-with-hooks.ts
1666
- async function fetchWithHooks(url, init, options = {}) {
1704
+ init_fetch_with_protected_rc_fallback();
1705
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1667
1706
  const { onRequest, onResponse } = options;
1707
+ const init = {
1708
+ method: "GET",
1709
+ headers: remoteFetchHeaders(),
1710
+ ...additionalInit
1711
+ };
1668
1712
  let res = await onRequest?.(url, init);
1669
1713
  if (!res) {
1670
- res = await fetch(url, init);
1714
+ res = await fetchWithProtectedRcFallback(url, init);
1671
1715
  }
1672
1716
  const transformedRes = await onResponse?.(url, res);
1673
1717
  if (transformedRes) {
@@ -1678,6 +1722,7 @@ async function fetchWithHooks(url, init, options = {}) {
1678
1722
 
1679
1723
  // src/html/host/index.tsx
1680
1724
  init_utils();
1725
+ init_logger();
1681
1726
 
1682
1727
  // src/html/host/runtime/index.ts
1683
1728
  init_error();
@@ -1819,8 +1864,6 @@ if (typeof HTMLElement !== "undefined") {
1819
1864
  }
1820
1865
  if (!remoteComponentChild && url) {
1821
1866
  const fetchInit = {
1822
- method: "GET",
1823
- headers: remoteFetchHeaders(),
1824
1867
  credentials: this.getAttribute("credentials") || "same-origin"
1825
1868
  };
1826
1869
  const res = await fetchWithHooks(url, fetchInit, {