remote-components 0.0.34 → 0.0.36

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 (66) hide show
  1. package/dist/html/host.cjs +127 -117
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +127 -117
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs +4 -3
  6. package/dist/html/remote.cjs.map +1 -1
  7. package/dist/html/remote.js +4 -3
  8. package/dist/html/remote.js.map +1 -1
  9. package/dist/internal/next/host/app-router-client.cjs +4 -15
  10. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  11. package/dist/internal/next/host/app-router-client.js +10 -21
  12. package/dist/internal/next/host/app-router-client.js.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  14. package/dist/internal/next/host/app-router-compat.d.ts +1 -1
  15. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  16. package/dist/internal/next/remote/render-server.cjs +1 -1
  17. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  18. package/dist/internal/next/remote/render-server.js +1 -1
  19. package/dist/internal/next/remote/render-server.js.map +1 -1
  20. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  21. package/dist/internal/shared/client/polyfill.js.map +1 -1
  22. package/dist/internal/shared/client/remote-component.cjs +179 -174
  23. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  24. package/dist/internal/shared/client/remote-component.d.ts +23 -23
  25. package/dist/internal/shared/client/remote-component.js +179 -174
  26. package/dist/internal/shared/client/remote-component.js.map +1 -1
  27. package/dist/internal/shared/error.cjs +1 -1
  28. package/dist/internal/shared/error.cjs.map +1 -1
  29. package/dist/internal/shared/error.js +1 -1
  30. package/dist/internal/shared/error.js.map +1 -1
  31. package/dist/internal/shared/ssr/dom-flight.cjs +7 -3
  32. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  33. package/dist/internal/shared/ssr/dom-flight.js +7 -3
  34. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  35. package/dist/internal/shared/ssr/fetch-remote-component.cjs +4 -4
  36. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  37. package/dist/internal/shared/ssr/fetch-remote-component.js +5 -5
  38. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  39. package/dist/next/config.cjs +100 -86
  40. package/dist/next/config.cjs.map +1 -1
  41. package/dist/next/config.js +100 -86
  42. package/dist/next/config.js.map +1 -1
  43. package/dist/next/host/app-router-server.cjs.map +1 -1
  44. package/dist/next/host/app-router-server.js +1 -1
  45. package/dist/next/host/app-router-server.js.map +1 -1
  46. package/dist/next/host/client/index.cjs +723 -718
  47. package/dist/next/host/client/index.cjs.map +1 -1
  48. package/dist/next/host/client/index.js +727 -722
  49. package/dist/next/host/client/index.js.map +1 -1
  50. package/dist/next/host/pages-router-server.cjs +4 -4
  51. package/dist/next/host/pages-router-server.cjs.map +1 -1
  52. package/dist/next/host/pages-router-server.js +4 -4
  53. package/dist/next/host/pages-router-server.js.map +1 -1
  54. package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
  55. package/dist/next/proxy.cjs.map +1 -0
  56. package/dist/next/proxy.d.ts +29 -0
  57. package/dist/next/{middleware.js → proxy.js} +21 -11
  58. package/dist/next/proxy.js.map +1 -0
  59. package/dist/react/index.cjs +4 -4
  60. package/dist/react/index.cjs.map +1 -1
  61. package/dist/react/index.js +11 -11
  62. package/dist/react/index.js.map +1 -1
  63. package/package.json +15 -9
  64. package/dist/next/middleware.cjs.map +0 -1
  65. package/dist/next/middleware.d.ts +0 -29
  66. package/dist/next/middleware.js.map +0 -1
@@ -1,46 +1,19 @@
1
- // src/shared/client/component-loader.ts
2
- import * as React from "react";
3
- import * as ReactDOM from "react-dom";
4
- import * as ReactDOMClient from "react-dom/client";
5
- import * as JSXDevRuntime from "react/jsx-dev-runtime";
6
- import * as JSXRuntime from "react/jsx-runtime";
7
-
8
- // src/shared/webpack/shared-modules.ts
9
- function applySharedModules(bundle, resolve) {
10
- const self = globalThis;
11
- if (self.__remote_webpack_require__?.[bundle]) {
12
- const modulePaths = Object.keys(
13
- self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
14
- );
15
- for (const [key, value] of Object.entries(resolve)) {
16
- let ids = modulePaths.filter((p) => p === key);
17
- if (ids.length === 0) {
18
- ids = modulePaths.filter((p) => p.includes(key));
19
- }
20
- for (let id of ids) {
21
- const webpackBundle = self.__remote_webpack_require__[bundle];
22
- if (webpackBundle.m) {
23
- if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
24
- id = `${self.__remote_webpack_module_map__[bundle][id]}`;
25
- }
26
- webpackBundle.m[id] = (module) => {
27
- module.exports = value;
28
- };
29
- }
30
- }
31
- }
32
- }
33
- }
34
-
35
1
  // src/shared/error.ts
36
2
  var RemoteComponentsError = class extends Error {
3
+ code = "REMOTE_COMPONENTS_ERROR";
37
4
  constructor(message, options) {
38
5
  super(message, options);
39
- this.code = "REMOTE_COMPONENTS_ERROR";
40
6
  this.name = "RemoteComponentsError";
41
7
  }
42
8
  };
43
9
 
10
+ // src/shared/client/component-loader.ts
11
+ import * as React from "react";
12
+ import * as JSXDevRuntime from "react/jsx-dev-runtime";
13
+ import * as JSXRuntime from "react/jsx-runtime";
14
+ import * as ReactDOM from "react-dom";
15
+ import * as ReactDOMClient from "react-dom/client";
16
+
44
17
  // src/shared/webpack/next-client-pages-loader.ts
45
18
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
46
19
  const self = globalThis;
@@ -153,6 +126,128 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
153
126
  return { Component: null, App: null };
154
127
  }
155
128
 
129
+ // src/shared/webpack/shared-modules.ts
130
+ function applySharedModules(bundle, resolve) {
131
+ const self = globalThis;
132
+ if (self.__remote_webpack_require__?.[bundle]) {
133
+ const modulePaths = Object.keys(
134
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
135
+ );
136
+ for (const [key, value] of Object.entries(resolve)) {
137
+ let ids = modulePaths.filter((p) => p === key);
138
+ if (ids.length === 0) {
139
+ ids = modulePaths.filter((p) => p.includes(key));
140
+ }
141
+ for (let id of ids) {
142
+ const webpackBundle = self.__remote_webpack_require__[bundle];
143
+ if (webpackBundle.m) {
144
+ if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
145
+ id = `${self.__remote_webpack_module_map__[bundle][id]}`;
146
+ }
147
+ webpackBundle.m[id] = (module) => {
148
+ module.exports = value;
149
+ };
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ // src/shared/client/rsc.ts
157
+ import { ReadableStream } from "web-streams-polyfill";
158
+ function fixPayload(payload) {
159
+ if (Array.isArray(payload)) {
160
+ if (payload[0] === "$") {
161
+ fixPayload(payload[3]);
162
+ if (payload.length === 4) {
163
+ payload.push(null, null, 1);
164
+ }
165
+ } else {
166
+ for (const item of payload) {
167
+ fixPayload(item);
168
+ }
169
+ }
170
+ } else if (typeof payload === "object" && payload !== null) {
171
+ for (const key in payload) {
172
+ fixPayload(payload[key]);
173
+ }
174
+ }
175
+ }
176
+ function createRSCStream(rscName, data) {
177
+ return new ReadableStream({
178
+ type: "bytes",
179
+ start(controller) {
180
+ const encoder = new TextEncoder();
181
+ const self = globalThis;
182
+ if (data.length > 0) {
183
+ data.forEach((chunk) => {
184
+ const lines = chunk.split("\n");
185
+ for (const line of lines) {
186
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
187
+ if (match?.groups?.rsc) {
188
+ self[rscName] = self[rscName] ?? [];
189
+ self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
190
+ }
191
+ }
192
+ });
193
+ }
194
+ const allChunks = (self[rscName] ?? [`0:[null]
195
+ `]).join("");
196
+ self[rscName] = null;
197
+ allChunks.split("\n").forEach((chunk) => {
198
+ if (chunk.length > 0) {
199
+ const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
200
+ chunk
201
+ )?.groups ?? {};
202
+ if (payload) {
203
+ const jsonPayload = JSON.parse(payload);
204
+ fixPayload(jsonPayload);
205
+ const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
206
+ controller.enqueue(encoder.encode(`${reconstruct}
207
+ `));
208
+ } else {
209
+ controller.enqueue(encoder.encode(`${chunk}
210
+ `));
211
+ }
212
+ } else {
213
+ controller.enqueue(encoder.encode(`${chunk}
214
+ `));
215
+ }
216
+ });
217
+ controller.close();
218
+ }
219
+ });
220
+ }
221
+
222
+ // src/shared/client/script-loader.ts
223
+ async function loadScripts(scripts) {
224
+ await Promise.all(
225
+ scripts.map((script) => {
226
+ return new Promise((resolve, reject) => {
227
+ const newSrc = new URL(
228
+ // remove the remote component bundle name identifier from the script src
229
+ script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
230
+ location.origin
231
+ ).href;
232
+ const newScript = document.createElement("script");
233
+ newScript.onload = () => {
234
+ resolve();
235
+ };
236
+ newScript.onerror = () => {
237
+ reject(
238
+ new RemoteComponentsError(
239
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
240
+ )
241
+ );
242
+ };
243
+ newScript.src = newSrc;
244
+ newScript.async = true;
245
+ document.head.appendChild(newScript);
246
+ });
247
+ })
248
+ );
249
+ }
250
+
156
251
  // src/shared/utils/index.ts
157
252
  function escapeString(str) {
158
253
  return str.replace(/[^a-z0-9]/g, "_");
@@ -331,7 +426,10 @@ async function handleTurbopackChunk(code, bundle, url) {
331
426
  function createModuleRequire(runtime) {
332
427
  return (id) => {
333
428
  const self = globalThis;
334
- const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? { bundle: "default", id };
429
+ const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
430
+ bundle: "default",
431
+ id
432
+ };
335
433
  const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
336
434
  try {
337
435
  if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
@@ -667,101 +765,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
667
765
  return moduleExports.exports;
668
766
  }
669
767
 
670
- // src/shared/client/script-loader.ts
671
- async function loadScripts(scripts) {
672
- await Promise.all(
673
- scripts.map((script) => {
674
- return new Promise((resolve, reject) => {
675
- const newSrc = new URL(
676
- // remove the remote component bundle name identifier from the script src
677
- script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
678
- location.origin
679
- ).href;
680
- const newScript = document.createElement("script");
681
- newScript.onload = () => {
682
- resolve();
683
- };
684
- newScript.onerror = () => {
685
- reject(
686
- new RemoteComponentsError(
687
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
688
- )
689
- );
690
- };
691
- newScript.src = newSrc;
692
- newScript.async = true;
693
- document.head.appendChild(newScript);
694
- });
695
- })
696
- );
697
- }
698
-
699
- // src/shared/client/rsc.ts
700
- import { ReadableStream } from "web-streams-polyfill";
701
- function fixPayload(payload) {
702
- if (Array.isArray(payload)) {
703
- if (payload[0] === "$") {
704
- fixPayload(payload[3]);
705
- if (payload.length === 4) {
706
- payload.push(null, null, 1);
707
- }
708
- } else {
709
- for (const item of payload) {
710
- fixPayload(item);
711
- }
712
- }
713
- } else if (typeof payload === "object" && payload !== null) {
714
- for (const key in payload) {
715
- fixPayload(payload[key]);
716
- }
717
- }
718
- }
719
- function createRSCStream(rscName, data) {
720
- return new ReadableStream({
721
- type: "bytes",
722
- start(controller) {
723
- const encoder = new TextEncoder();
724
- const self = globalThis;
725
- if (data.length > 0) {
726
- data.forEach((chunk) => {
727
- const lines = chunk.split("\n");
728
- for (const line of lines) {
729
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
730
- if (match?.groups?.rsc) {
731
- self[rscName] = self[rscName] ?? [];
732
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
733
- }
734
- }
735
- });
736
- }
737
- const allChunks = (self[rscName] ?? [`0:[null]
738
- `]).join("");
739
- self[rscName] = null;
740
- allChunks.split("\n").forEach((chunk) => {
741
- if (chunk.length > 0) {
742
- const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
743
- chunk
744
- )?.groups ?? {};
745
- if (payload) {
746
- const jsonPayload = JSON.parse(payload);
747
- fixPayload(jsonPayload);
748
- const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
749
- controller.enqueue(encoder.encode(`${reconstruct}
750
- `));
751
- } else {
752
- controller.enqueue(encoder.encode(`${chunk}
753
- `));
754
- }
755
- } else {
756
- controller.enqueue(encoder.encode(`${chunk}
757
- `));
758
- }
759
- });
760
- controller.close();
761
- }
762
- });
763
- }
764
-
765
768
  // src/shared/client/component-loader.ts
766
769
  async function loadRemoteComponent({
767
770
  url,
@@ -834,7 +837,9 @@ async function loadRemoteComponent({
834
837
  component: null,
835
838
  error: new RemoteComponentsError(
836
839
  `Failed to load remote component "${name}".`,
837
- { cause: error instanceof Error ? error : new Error(String(error)) }
840
+ {
841
+ cause: error instanceof Error ? error : new Error(String(error))
842
+ }
838
843
  )
839
844
  };
840
845
  }
@@ -870,6 +875,48 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
870
875
  return { component };
871
876
  }
872
877
 
878
+ // src/shared/client/set-attributes-from-props.ts
879
+ var DOMAttributeNames = {
880
+ acceptCharset: "accept-charset",
881
+ className: "class",
882
+ htmlFor: "for",
883
+ httpEquiv: "http-equiv",
884
+ noModule: "noModule"
885
+ };
886
+ var ignoreProps = [
887
+ "onLoad",
888
+ "onReady",
889
+ "dangerouslySetInnerHTML",
890
+ "children",
891
+ "onError",
892
+ "strategy",
893
+ "stylesheets"
894
+ ];
895
+ function isBooleanScriptAttribute(attr) {
896
+ return ["async", "defer", "noModule"].includes(attr);
897
+ }
898
+ function setAttributesFromProps(el, props) {
899
+ for (const [p, value] of Object.entries(props)) {
900
+ if (!Object.hasOwn(props, p))
901
+ continue;
902
+ if (ignoreProps.includes(p))
903
+ continue;
904
+ if (value === void 0) {
905
+ continue;
906
+ }
907
+ const attr = DOMAttributeNames[p] || p.toLowerCase();
908
+ if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
909
+ el[attr] = Boolean(value);
910
+ } else {
911
+ el.setAttribute(attr, String(value));
912
+ }
913
+ if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
914
+ el.setAttribute(attr, "");
915
+ el.removeAttribute(attr);
916
+ }
917
+ }
918
+ }
919
+
873
920
  // src/shared/client/static-loader.ts
874
921
  async function loadStaticRemoteComponent(scripts, url) {
875
922
  const self = globalThis;
@@ -963,48 +1010,6 @@ async function loadStaticRemoteComponent(scripts, url) {
963
1010
  }
964
1011
  );
965
1012
  }
966
-
967
- // src/shared/client/set-attributes-from-props.ts
968
- var DOMAttributeNames = {
969
- acceptCharset: "accept-charset",
970
- className: "class",
971
- htmlFor: "for",
972
- httpEquiv: "http-equiv",
973
- noModule: "noModule"
974
- };
975
- var ignoreProps = [
976
- "onLoad",
977
- "onReady",
978
- "dangerouslySetInnerHTML",
979
- "children",
980
- "onError",
981
- "strategy",
982
- "stylesheets"
983
- ];
984
- function isBooleanScriptAttribute(attr) {
985
- return ["async", "defer", "noModule"].includes(attr);
986
- }
987
- function setAttributesFromProps(el, props) {
988
- for (const [p, value] of Object.entries(props)) {
989
- if (!Object.prototype.hasOwnProperty.call(props, p))
990
- continue;
991
- if (ignoreProps.includes(p))
992
- continue;
993
- if (value === void 0) {
994
- continue;
995
- }
996
- const attr = DOMAttributeNames[p] || p.toLowerCase();
997
- if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
998
- el[attr] = Boolean(value);
999
- } else {
1000
- el.setAttribute(attr, String(value));
1001
- }
1002
- if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
1003
- el.setAttribute(attr, "");
1004
- el.removeAttribute(attr);
1005
- }
1006
- }
1007
- }
1008
1013
  export {
1009
1014
  DEFAULT_ROUTE,
1010
1015
  REMOTE_COMPONENT_REGEX,