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
package/dist/html/host.js CHANGED
@@ -40,6 +40,9 @@ function logDebug(location2, message) {
40
40
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
41
41
  }
42
42
  }
43
+ function logInfo(location2, message) {
44
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
45
+ }
43
46
  function logWarn(location2, message) {
44
47
  console.warn(`[${PREFIX}:${location2}]: ${message}`);
45
48
  }
@@ -245,6 +248,41 @@ var init_shared_modules = __esm({
245
248
  }
246
249
  });
247
250
 
251
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
252
+ async function fetchWithProtectedRcFallback(url, init) {
253
+ try {
254
+ const res = await fetch(url, init);
255
+ return res;
256
+ } catch (error) {
257
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
258
+ logInfo(
259
+ "FetchRemoteComponent",
260
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
261
+ );
262
+ const proxiedRes = await fetch(
263
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
264
+ );
265
+ if (proxiedRes.status === 200) {
266
+ return proxiedRes;
267
+ } else {
268
+ logError(
269
+ "FetchRemoteComponent",
270
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
271
+ );
272
+ }
273
+ }
274
+ throw error;
275
+ }
276
+ }
277
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
278
+ var init_fetch_with_protected_rc_fallback = __esm({
279
+ "src/shared/ssr/fetch-with-protected-rc-fallback.ts"() {
280
+ "use strict";
281
+ init_logger();
282
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
283
+ }
284
+ });
285
+
248
286
  // src/shared/utils/index.ts
249
287
  function escapeString(str) {
250
288
  return str.replace(/[^a-z0-9]/g, "_");
@@ -252,7 +290,6 @@ function escapeString(str) {
252
290
  var init_utils = __esm({
253
291
  "src/shared/utils/index.ts"() {
254
292
  "use strict";
255
- init_logger();
256
293
  }
257
294
  });
258
295
 
@@ -314,7 +351,7 @@ function createChunkLoader(runtime) {
314
351
  }
315
352
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
316
353
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
317
- fetch(url).then((res) => res.text()).then((code) => {
354
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
318
355
  const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
319
356
  if (hasTurbopack) {
320
357
  return handleTurbopackChunk(code, bundle ?? "", url);
@@ -467,6 +504,7 @@ var init_chunk_loader = __esm({
467
504
  "src/shared/client/chunk-loader.ts"() {
468
505
  "use strict";
469
506
  init_error();
507
+ init_fetch_with_protected_rc_fallback();
470
508
  init_logger();
471
509
  init_const();
472
510
  }
@@ -1237,7 +1275,7 @@ var imageImpl;
1237
1275
  var init_polyfill = __esm({
1238
1276
  "src/shared/client/polyfill.tsx"() {
1239
1277
  "use strict";
1240
- init_utils();
1278
+ init_logger();
1241
1279
  imageImpl = (bundle) => function RemoteImage({
1242
1280
  fill: _fill,
1243
1281
  loader: _loader,
@@ -1638,11 +1676,17 @@ function remoteFetchHeaders() {
1638
1676
  }
1639
1677
 
1640
1678
  // src/shared/ssr/fetch-with-hooks.ts
1641
- async function fetchWithHooks(url, init, options = {}) {
1679
+ init_fetch_with_protected_rc_fallback();
1680
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1642
1681
  const { onRequest, onResponse } = options;
1682
+ const init = {
1683
+ method: "GET",
1684
+ headers: remoteFetchHeaders(),
1685
+ ...additionalInit
1686
+ };
1643
1687
  let res = await onRequest?.(url, init);
1644
1688
  if (!res) {
1645
- res = await fetch(url, init);
1689
+ res = await fetchWithProtectedRcFallback(url, init);
1646
1690
  }
1647
1691
  const transformedRes = await onResponse?.(url, res);
1648
1692
  if (transformedRes) {
@@ -1653,6 +1697,7 @@ async function fetchWithHooks(url, init, options = {}) {
1653
1697
 
1654
1698
  // src/html/host/index.tsx
1655
1699
  init_utils();
1700
+ init_logger();
1656
1701
 
1657
1702
  // src/html/host/runtime/index.ts
1658
1703
  init_error();
@@ -1794,8 +1839,6 @@ if (typeof HTMLElement !== "undefined") {
1794
1839
  }
1795
1840
  if (!remoteComponentChild && url) {
1796
1841
  const fetchInit = {
1797
- method: "GET",
1798
- headers: remoteFetchHeaders(),
1799
1842
  credentials: this.getAttribute("credentials") || "same-origin"
1800
1843
  };
1801
1844
  const res = await fetchWithHooks(url, fetchInit, {