remote-components 0.0.31 → 0.0.33

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 (100) hide show
  1. package/dist/{component-loader-e5513139.d.ts → component-loader-28ad0083.d.ts} +1 -0
  2. package/dist/html/host.cjs +152 -56
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +152 -56
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/internal/next/host/app-router-client.cjs +6 -2
  7. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  8. package/dist/internal/next/host/app-router-client.d.ts +2 -2
  9. package/dist/internal/next/host/app-router-client.js +6 -2
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/remote/render-client.cjs +13 -3
  12. package/dist/internal/next/remote/render-client.cjs.map +1 -1
  13. package/dist/internal/next/remote/render-client.js +13 -3
  14. package/dist/internal/next/remote/render-client.js.map +1 -1
  15. package/dist/internal/next/remote/render-server.cjs +22 -3
  16. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  17. package/dist/internal/next/remote/render-server.js +23 -4
  18. package/dist/internal/next/remote/render-server.js.map +1 -1
  19. package/dist/internal/shared/client/remote-component.cjs +82 -45
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.d.ts +9 -2
  22. package/dist/internal/shared/client/remote-component.js +81 -45
  23. package/dist/internal/shared/client/remote-component.js.map +1 -1
  24. package/dist/internal/shared/error.cjs +50 -0
  25. package/dist/internal/shared/error.cjs.map +1 -0
  26. package/dist/internal/shared/error.d.ts +10 -0
  27. package/dist/internal/shared/error.js +24 -0
  28. package/dist/internal/shared/error.js.map +1 -0
  29. package/dist/internal/shared/ssr/dom-flight.cjs +8 -1
  30. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  31. package/dist/internal/shared/ssr/dom-flight.d.ts +2 -1
  32. package/dist/internal/shared/ssr/dom-flight.js +8 -1
  33. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  34. package/dist/internal/shared/ssr/fetch-remote-component.cjs +48 -5
  35. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  36. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  37. package/dist/internal/shared/ssr/fetch-remote-component.js +52 -5
  38. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  39. package/dist/internal/webpack/next-client-pages-loader.cjs +3 -2
  40. package/dist/internal/webpack/next-client-pages-loader.cjs.map +1 -1
  41. package/dist/internal/webpack/next-client-pages-loader.js +3 -2
  42. package/dist/internal/webpack/next-client-pages-loader.js.map +1 -1
  43. package/dist/next/config.cjs +26 -9
  44. package/dist/next/config.cjs.map +1 -1
  45. package/dist/next/config.js +26 -9
  46. package/dist/next/config.js.map +1 -1
  47. package/dist/next/host/client/index.cjs +133 -57
  48. package/dist/next/host/client/index.cjs.map +1 -1
  49. package/dist/next/host/client/index.d.ts +1 -1
  50. package/dist/next/host/client/index.js +133 -57
  51. package/dist/next/host/client/index.js.map +1 -1
  52. package/dist/next/host/pages-router-client.cjs +1 -1
  53. package/dist/next/host/pages-router-client.cjs.map +1 -1
  54. package/dist/next/host/pages-router-client.js +1 -1
  55. package/dist/next/host/pages-router-client.js.map +1 -1
  56. package/dist/next/host/pages-router-server.cjs +4 -3
  57. package/dist/next/host/pages-router-server.cjs.map +1 -1
  58. package/dist/next/host/pages-router-server.js +4 -3
  59. package/dist/next/host/pages-router-server.js.map +1 -1
  60. package/dist/next/index.cjs +4 -2
  61. package/dist/next/index.cjs.map +1 -1
  62. package/dist/next/index.js +4 -2
  63. package/dist/next/index.js.map +1 -1
  64. package/dist/next/remote/pages-router.cjs +1 -1
  65. package/dist/next/remote/pages-router.cjs.map +1 -1
  66. package/dist/next/remote/pages-router.js +1 -1
  67. package/dist/next/remote/pages-router.js.map +1 -1
  68. package/dist/react/index.cjs +42 -11
  69. package/dist/react/index.cjs.map +1 -1
  70. package/dist/react/index.d.ts +2 -2
  71. package/dist/react/index.js +46 -11
  72. package/dist/react/index.js.map +1 -1
  73. package/dist/shared/host/app.cjs +36 -0
  74. package/dist/shared/host/app.cjs.map +1 -0
  75. package/dist/shared/host/app.d.ts +3 -0
  76. package/dist/shared/host/app.js +12 -0
  77. package/dist/shared/host/app.js.map +1 -0
  78. package/dist/shared/host/pages.cjs +36 -0
  79. package/dist/shared/host/pages.cjs.map +1 -0
  80. package/dist/shared/host/pages.d.ts +3 -0
  81. package/dist/shared/host/pages.js +12 -0
  82. package/dist/shared/host/pages.js.map +1 -0
  83. package/dist/shared/remote/app.cjs +32 -0
  84. package/dist/shared/remote/app.cjs.map +1 -0
  85. package/dist/shared/remote/app.d.ts +3 -0
  86. package/dist/shared/remote/app.js +8 -0
  87. package/dist/shared/remote/app.js.map +1 -0
  88. package/dist/shared/remote/pages.cjs +32 -0
  89. package/dist/shared/remote/pages.cjs.map +1 -0
  90. package/dist/shared/remote/pages.d.ts +3 -0
  91. package/dist/shared/remote/pages.js +8 -0
  92. package/dist/shared/remote/pages.js.map +1 -0
  93. package/dist/shared/remote/wrapper.cjs +48 -0
  94. package/dist/shared/remote/wrapper.cjs.map +1 -0
  95. package/dist/shared/remote/wrapper.d.ts +2 -0
  96. package/dist/shared/remote/wrapper.js +25 -0
  97. package/dist/shared/remote/wrapper.js.map +1 -0
  98. package/dist/{types-b8210fd3.d.ts → types-7c207455.d.ts} +1 -1
  99. package/dist/{types-280a3640.d.ts → types-e4a3fa37.d.ts} +1 -0
  100. package/package.json +37 -1
@@ -5,6 +5,7 @@ interface RemoteComponentMetadata {
5
5
  route: string;
6
6
  runtime: 'webpack' | 'turbopack';
7
7
  id: string;
8
+ type: 'nextjs' | 'unknown';
8
9
  }
9
10
 
10
11
  interface RemoteComponentProps {
@@ -62,6 +62,32 @@ var init_shared_modules = __esm({
62
62
  }
63
63
  });
64
64
 
65
+ // src/shared/error.ts
66
+ function multipleRemoteComponentsError(url) {
67
+ return new Error(
68
+ `Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
69
+ );
70
+ }
71
+ function failedToFetchRemoteComponentError(url, error) {
72
+ return new RemoteComponentsError(
73
+ `Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
74
+ { cause: error instanceof Error ? error : new Error(String(error)) }
75
+ );
76
+ }
77
+ var RemoteComponentsError;
78
+ var init_error = __esm({
79
+ "src/shared/error.ts"() {
80
+ "use strict";
81
+ RemoteComponentsError = class extends Error {
82
+ constructor(message, options) {
83
+ super(message, options);
84
+ this.code = "REMOTE_COMPONENTS_ERROR";
85
+ this.name = "RemoteComponentsError";
86
+ }
87
+ };
88
+ }
89
+ });
90
+
65
91
  // src/shared/webpack/next-client-pages-loader.ts
66
92
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
67
93
  const self = globalThis;
@@ -100,8 +126,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
100
126
  (key) => key.includes("/next/dist/client/page-loader.js")
101
127
  ) ?? ""] ?? -1;
102
128
  if (!(componentLoaderChunk && appLoaderChunk)) {
103
- throw new Error(
104
- `Next.js client pages loader not found in bundle "${bundle}"`
129
+ throw new RemoteComponentsError(
130
+ `Next.js client pages loader not found in bundle "${bundle}".`
105
131
  );
106
132
  }
107
133
  const __NEXT_P_ORIGINAL = self.__NEXT_P;
@@ -176,6 +202,7 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
176
202
  var init_next_client_pages_loader = __esm({
177
203
  "src/shared/webpack/next-client-pages-loader.ts"() {
178
204
  "use strict";
205
+ init_error();
179
206
  }
180
207
  });
181
208
 
@@ -334,11 +361,11 @@ async function handleTurbopackChunk(code, bundle, url) {
334
361
  scriptResolve(void 0);
335
362
  script.remove();
336
363
  };
337
- script.onerror = (error) => {
364
+ script.onerror = () => {
338
365
  URL.revokeObjectURL(scriptUrl);
339
366
  scriptReject(
340
- new Error(
341
- `Failed to load script: ${error instanceof Error ? error.message : String(error)}`
367
+ new RemoteComponentsError(
368
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
342
369
  )
343
370
  );
344
371
  script.remove();
@@ -380,11 +407,11 @@ function createModuleRequire(runtime) {
380
407
  if (bundle && moduleId) {
381
408
  return handleTurbopackModule(bundle, moduleId, id);
382
409
  }
383
- throw new Error(`Module ${id} not found`);
410
+ throw new Error(`Module "${id}" not found.`);
384
411
  } catch (requireError) {
385
412
  if (typeof self.__original_webpack_require__ !== "function") {
386
- throw new Error(
387
- `Module ${id} not found in remote component bundle ${bundle}`,
413
+ throw new RemoteComponentsError(
414
+ `Module "${id}" not found in remote component bundle "${bundle}".`,
388
415
  {
389
416
  cause: requireError instanceof Error ? requireError : void 0
390
417
  }
@@ -393,8 +420,8 @@ function createModuleRequire(runtime) {
393
420
  try {
394
421
  return self.__original_webpack_require__(id);
395
422
  } catch (originalError) {
396
- throw new Error(
397
- `Module ${id} not found in remote component bundle ${bundle}`,
423
+ throw new RemoteComponentsError(
424
+ `Module "${id}" not found in remote component bundle "${bundle}".`,
398
425
  { cause: originalError instanceof Error ? originalError : void 0 }
399
426
  );
400
427
  }
@@ -524,7 +551,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
524
551
  }
525
552
  const exports = {};
526
553
  const moduleExports = { exports };
527
- const exportNames = /* @__PURE__ */ new Set();
528
554
  if (!self.__remote_components_turbopack_modules__) {
529
555
  self.__remote_components_turbopack_modules__ = {};
530
556
  }
@@ -560,31 +586,53 @@ function handleTurbopackModule(bundle, moduleId, id) {
560
586
  };
561
587
  }
562
588
  },
563
- // define exports
564
- s(m) {
565
- let mod = m;
566
- if (Array.isArray(m)) {
567
- mod = {};
568
- const keys = [];
569
- for (const current of m) {
570
- if (typeof current === "string") {
571
- keys.push(current);
572
- } else if (typeof current === "function") {
573
- while (keys.length > 0) {
574
- const key = keys.shift();
575
- if (key) {
576
- mod[key] = current;
577
- }
589
+ // esm
590
+ s(bindings, esmId) {
591
+ let mod = exports;
592
+ if (typeof esmId === "string" || typeof esmId === "number") {
593
+ if (!self.__remote_components_turbopack_modules__) {
594
+ self.__remote_components_turbopack_modules__ = {};
595
+ }
596
+ if (!self.__remote_components_turbopack_modules__[bundle]) {
597
+ self.__remote_components_turbopack_modules__[bundle] = {};
598
+ }
599
+ if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {
600
+ self.__remote_components_turbopack_modules__[bundle][esmId] = {};
601
+ }
602
+ mod = self.__remote_components_turbopack_modules__[bundle][esmId];
603
+ }
604
+ Object.defineProperty(mod, "__esModule", { value: true });
605
+ if (Array.isArray(bindings)) {
606
+ let i = 0;
607
+ while (i < bindings.length) {
608
+ const propName = bindings[i++];
609
+ const tagOrFunc = bindings[i++];
610
+ if (typeof tagOrFunc === "number") {
611
+ Object.defineProperty(mod, propName, {
612
+ value: bindings[i++],
613
+ enumerable: true,
614
+ writable: false
615
+ });
616
+ } else {
617
+ const getterFn = tagOrFunc;
618
+ if (typeof bindings[i] === "function") {
619
+ const setterFn = bindings[i++];
620
+ Object.defineProperty(mod, propName, {
621
+ get: getterFn,
622
+ set: setterFn,
623
+ enumerable: true
624
+ });
625
+ } else {
626
+ Object.defineProperty(mod, propName, {
627
+ get: getterFn,
628
+ enumerable: true
629
+ });
578
630
  }
579
631
  }
580
632
  }
581
633
  }
582
- for (const [key, value] of Object.entries(mod)) {
583
- exports[key] = value;
584
- exportNames.add(key);
585
- }
586
634
  },
587
- // import ESM
635
+ // import
588
636
  i(importId) {
589
637
  let mod;
590
638
  if (typeof importId === "string") {
@@ -608,7 +656,10 @@ function handleTurbopackModule(bundle, moduleId, id) {
608
656
  } else {
609
657
  mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
610
658
  }
611
- if (!("default" in mod) && mod.toString() !== "[object Module]") {
659
+ if (typeof mod !== "object") {
660
+ mod = { default: mod };
661
+ } else if (!("default" in mod) && // eslint-disable-next-line @typescript-eslint/no-base-to-string
662
+ mod.toString() !== "[object Module]") {
612
663
  try {
613
664
  mod.default = mod;
614
665
  } catch {
@@ -627,7 +678,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
627
678
  return self.__webpack_require__?.(`[${bundle}] ${vid}`);
628
679
  });
629
680
  } else {
630
- exports.default = value;
681
+ moduleExports.exports = value;
631
682
  }
632
683
  },
633
684
  // async module initializer
@@ -661,7 +712,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
661
712
  return self.__webpack_chunk_load__?.(bundleUrl, bundle);
662
713
  }
663
714
  }
664
- throw new Error(`Failed to load chunk ${url} for module ${id}`);
715
+ throw new Error(
716
+ `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
717
+ );
665
718
  },
666
719
  // global
667
720
  g: self.__remote_components_turbopack_global__[bundle],
@@ -671,11 +724,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
671
724
  moduleExports,
672
725
  exports
673
726
  );
674
- for (const name of exportNames) {
675
- if (typeof exports[name] === "function") {
676
- exports[name] = exports[name]();
677
- }
678
- }
679
727
  if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
680
728
  self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
681
729
  }
@@ -684,6 +732,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
684
732
  var init_webpack_adapter = __esm({
685
733
  "src/shared/client/webpack-adapter.ts"() {
686
734
  "use strict";
735
+ init_error();
687
736
  init_const();
688
737
  }
689
738
  });
@@ -905,10 +954,14 @@ async function webpackRuntime(bundle, shared, remoteShared) {
905
954
  const remoteBundle = match?.groups?.bundle;
906
955
  const id = match?.groups?.id;
907
956
  if (!(id && remoteBundle)) {
908
- throw new Error(`Module not found: "${remoteId}"`);
957
+ throw new RemoteComponentsError(
958
+ `Remote Component module "${remoteId}" not found. Did you forget to wrap the Next.js config with \`withRemoteComponents\` on both host and remote?`
959
+ );
909
960
  }
910
961
  if (typeof self.__remote_webpack_require__?.[remoteBundle] !== "function") {
911
- throw new Error(`Remote component loading error "${remoteBundle}"`);
962
+ throw new RemoteComponentsError(
963
+ `Remote Components are not available in "${remoteBundle}". Did you forget to wrap the Next.js config with \`withRemoteComponents\` on both host and remote?`
964
+ );
912
965
  }
913
966
  return self.__remote_webpack_require__[remoteBundle](id);
914
967
  };
@@ -930,8 +983,8 @@ async function webpackRuntime(bundle, shared, remoteShared) {
930
983
  };
931
984
  newScript.onerror = () => {
932
985
  reject(
933
- new Error(
934
- `Failed to load script ${script.src} for remote component`
986
+ new RemoteComponentsError(
987
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
935
988
  )
936
989
  );
937
990
  newScript.remove();
@@ -991,6 +1044,7 @@ async function webpackRuntime(bundle, shared, remoteShared) {
991
1044
  var init_webpack = __esm({
992
1045
  "src/html/host/runtime/webpack.ts"() {
993
1046
  "use strict";
1047
+ init_error();
994
1048
  init_shared_modules();
995
1049
  init_next_client_pages_loader();
996
1050
  init_polyfill();
@@ -1068,8 +1122,12 @@ var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
1068
1122
  var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
1069
1123
  init_shared_modules();
1070
1124
  init_next_client_pages_loader();
1125
+ init_error();
1071
1126
  init_webpack_adapter();
1072
1127
 
1128
+ // src/shared/client/script-loader.ts
1129
+ init_error();
1130
+
1073
1131
  // src/shared/client/rsc.ts
1074
1132
  var import_web_streams_polyfill = require("web-streams-polyfill");
1075
1133
  function fixPayload(payload) {
@@ -1139,6 +1197,7 @@ function createRSCStream(rscName, data) {
1139
1197
  // src/shared/client/remote-component.ts
1140
1198
  init_webpack_adapter();
1141
1199
  init_const();
1200
+ init_error();
1142
1201
 
1143
1202
  // src/html/host/index.tsx
1144
1203
  init_utils();
@@ -1218,7 +1277,11 @@ function applyOriginToNodes(doc, url) {
1218
1277
  }
1219
1278
  }
1220
1279
 
1280
+ // src/html/host/index.tsx
1281
+ init_error();
1282
+
1221
1283
  // src/html/host/runtime/index.ts
1284
+ init_error();
1222
1285
  async function getRuntime(type, url, bundle, shared, remoteShared) {
1223
1286
  if (typeof globalThis.process === "undefined") {
1224
1287
  globalThis.process = {
@@ -1232,7 +1295,9 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
1232
1295
  const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
1233
1296
  return turbopackRuntime2(url, bundle, shared, remoteShared);
1234
1297
  }
1235
- throw new Error(`Runtime ${type} is not supported`);
1298
+ throw new RemoteComponentsError(
1299
+ `Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack" and "turbopack".`
1300
+ );
1236
1301
  }
1237
1302
 
1238
1303
  // src/html/host/index.tsx
@@ -1257,9 +1322,6 @@ if (typeof HTMLElement !== "undefined") {
1257
1322
  if (this.getAttribute("src")) {
1258
1323
  this.load().catch((e) => {
1259
1324
  console.error(e);
1260
- throw new Error(
1261
- `Failed to load remote component: ${this.bundle ?? this.name ?? this.getAttribute("src")}`
1262
- );
1263
1325
  });
1264
1326
  }
1265
1327
  } else if (name === "mode" && oldValue !== newValue && this.root) {
@@ -1271,7 +1333,7 @@ if (typeof HTMLElement !== "undefined") {
1271
1333
  });
1272
1334
  this.root = newRoot;
1273
1335
  this.load().catch((e) => {
1274
- throw new Error(`Failed to load remote component: ${e}`);
1336
+ console.error(e);
1275
1337
  });
1276
1338
  }
1277
1339
  }
@@ -1305,14 +1367,14 @@ if (typeof HTMLElement !== "undefined") {
1305
1367
  }
1306
1368
  if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
1307
1369
  this.load().catch((e) => {
1308
- throw new Error(`Failed to load remote component: ${e}`);
1370
+ console.error(e);
1309
1371
  });
1310
1372
  }
1311
1373
  this.isLoading = true;
1312
1374
  const src = this.getAttribute("src");
1313
1375
  const remoteComponentChild = this.querySelector("div#__REMOTE_COMPONENT__") || this.querySelector("div[data-bundle][data-route]");
1314
1376
  if (!src && !remoteComponentChild) {
1315
- throw new Error("src attribute is required");
1377
+ throw new RemoteComponentsError('"src" attribute is required');
1316
1378
  }
1317
1379
  let url = null;
1318
1380
  let html = this.innerHTML;
@@ -1330,14 +1392,41 @@ if (typeof HTMLElement !== "undefined") {
1330
1392
  };
1331
1393
  const res = await fetch(url, fetchInit);
1332
1394
  if (!res.ok) {
1333
- throw new Error(
1334
- `Failed to fetch remote component "${this.name}": ${res.status}`
1335
- );
1395
+ let error = failedToFetchRemoteComponentError(url.href, {
1396
+ cause: new Error(`${res.status} ${res.statusText}`)
1397
+ });
1398
+ try {
1399
+ const body = await res.text();
1400
+ const parser2 = new DOMParser();
1401
+ const doc2 = parser2.parseFromString(body, "text/html");
1402
+ const errorTemplate = doc2.querySelector(
1403
+ "template[data-next-error-message]"
1404
+ );
1405
+ const errorMessage = errorTemplate?.getAttribute(
1406
+ "data-next-error-message"
1407
+ );
1408
+ const errorStack = errorTemplate?.getAttribute(
1409
+ "data-next-error-stack"
1410
+ );
1411
+ if (errorMessage) {
1412
+ error = new RemoteComponentsError(errorMessage);
1413
+ if (errorStack) {
1414
+ error.stack = errorStack;
1415
+ }
1416
+ }
1417
+ } catch {
1418
+ }
1419
+ throw error;
1336
1420
  }
1337
1421
  html = await res.text();
1338
1422
  }
1339
1423
  const parser = new DOMParser();
1340
1424
  const doc = parser.parseFromString(html, "text/html");
1425
+ if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${this.name}"]`)) {
1426
+ throw multipleRemoteComponentsError(
1427
+ url?.href ?? (this.getAttribute("src") || "unknown")
1428
+ );
1429
+ }
1341
1430
  const component = doc.querySelector(`div[data-bundle][data-route][id^="${this.name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
1342
1431
  doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
1343
1432
  doc.querySelector("div#__next");
@@ -1377,8 +1466,15 @@ if (typeof HTMLElement !== "undefined") {
1377
1466
  );
1378
1467
  const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
1379
1468
  remoteSharedEl?.parentElement?.removeChild(remoteSharedEl);
1469
+ if ("__remote_components_missing_shared__" in remoteShared) {
1470
+ throw new RemoteComponentsError(
1471
+ remoteShared.__remote_components_missing_shared__
1472
+ );
1473
+ }
1380
1474
  if (!component || !(rsc || nextData)) {
1381
- throw new Error(`Failed to find component with id "${this.name}"`);
1475
+ throw new RemoteComponentsError(
1476
+ `Remote Component not found on ${src}.${this.name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${this.name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
1477
+ );
1382
1478
  }
1383
1479
  const removable = Array.from(this.childNodes);
1384
1480
  const links = doc.querySelectorAll("link[href]");
@@ -1396,8 +1492,8 @@ if (typeof HTMLElement !== "undefined") {
1396
1492
  };
1397
1493
  newLink.onerror = () => {
1398
1494
  reject(
1399
- new Error(
1400
- `Failed to load link ${link.href} for remote component`
1495
+ new RemoteComponentsError(
1496
+ `Failed to load <link href="${link.href}"> for Remote Component. Check the URL is correct.`
1401
1497
  )
1402
1498
  );
1403
1499
  };