remote-components 0.3.3 → 0.3.5

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 (176) hide show
  1. package/dist/config/nextjs.cjs +86 -37
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.js +86 -37
  4. package/dist/config/nextjs.js.map +1 -1
  5. package/dist/config/webpack.cjs +5 -1
  6. package/dist/config/webpack.cjs.map +1 -1
  7. package/dist/config/webpack.js +5 -1
  8. package/dist/config/webpack.js.map +1 -1
  9. package/dist/host/html.cjs +861 -617
  10. package/dist/host/html.cjs.map +1 -1
  11. package/dist/host/html.js +861 -617
  12. package/dist/host/html.js.map +1 -1
  13. package/dist/host/nextjs/app/client-only.cjs +700 -383
  14. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  15. package/dist/host/nextjs/app/client-only.js +674 -357
  16. package/dist/host/nextjs/app/client-only.js.map +1 -1
  17. package/dist/host/nextjs/app.cjs +34 -2
  18. package/dist/host/nextjs/app.cjs.map +1 -1
  19. package/dist/host/nextjs/app.js +35 -3
  20. package/dist/host/nextjs/app.js.map +1 -1
  21. package/dist/host/react.cjs +641 -352
  22. package/dist/host/react.cjs.map +1 -1
  23. package/dist/host/react.js +641 -352
  24. package/dist/host/react.js.map +1 -1
  25. package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
  26. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
  27. package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
  28. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
  29. package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
  30. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  31. package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
  32. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  33. package/dist/internal/host/nextjs/app-client.cjs +42 -27
  34. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  35. package/dist/internal/host/nextjs/app-client.js +42 -27
  36. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  37. package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
  38. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  39. package/dist/internal/host/nextjs/dom-flight.js +31 -39
  40. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  41. package/dist/internal/host/nextjs/image-shared.cjs +39 -3
  42. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  43. package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
  44. package/dist/internal/host/nextjs/image-shared.js +29 -3
  45. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  46. package/dist/internal/host/nextjs/remote-component-links.cjs +24 -13
  47. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -1
  48. package/dist/internal/host/nextjs/remote-component-links.d.ts +3 -0
  49. package/dist/internal/host/nextjs/remote-component-links.js +24 -13
  50. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -1
  51. package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
  52. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  53. package/dist/internal/host/server/fetch-remote-component.js +2 -1
  54. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  55. package/dist/internal/host/shared/lifecycle.cjs +69 -0
  56. package/dist/internal/host/shared/lifecycle.cjs.map +1 -0
  57. package/dist/internal/host/shared/lifecycle.d.ts +34 -0
  58. package/dist/internal/host/shared/lifecycle.js +44 -0
  59. package/dist/internal/host/shared/lifecycle.js.map +1 -0
  60. package/dist/internal/host/shared/pipeline.cjs +222 -0
  61. package/dist/internal/host/shared/pipeline.cjs.map +1 -0
  62. package/dist/internal/host/shared/pipeline.d.ts +153 -0
  63. package/dist/internal/host/shared/pipeline.js +200 -0
  64. package/dist/internal/host/shared/pipeline.js.map +1 -0
  65. package/dist/internal/host/shared/polyfill.cjs +8 -7
  66. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  67. package/dist/internal/host/shared/polyfill.js +8 -7
  68. package/dist/internal/host/shared/polyfill.js.map +1 -1
  69. package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
  70. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
  71. package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
  72. package/dist/internal/host/shared/shared-module-resolver.js +78 -0
  73. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
  74. package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
  75. package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
  76. package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
  77. package/dist/internal/remote/nextjs/next-internals.js +26 -0
  78. package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
  79. package/dist/internal/runtime/html/apply-origin.cjs +11 -32
  80. package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
  81. package/dist/internal/runtime/html/apply-origin.js +11 -32
  82. package/dist/internal/runtime/html/apply-origin.js.map +1 -1
  83. package/dist/internal/runtime/html/html-spec.cjs +78 -0
  84. package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
  85. package/dist/internal/runtime/html/html-spec.d.ts +23 -0
  86. package/dist/internal/runtime/html/html-spec.js +41 -0
  87. package/dist/internal/runtime/html/html-spec.js.map +1 -0
  88. package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
  89. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  90. package/dist/internal/runtime/html/parse-remote-html.js +29 -12
  91. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  92. package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
  93. package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
  94. package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
  95. package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
  96. package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
  97. package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
  98. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  99. package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
  100. package/dist/internal/runtime/loaders/component-loader.js +28 -44
  101. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  102. package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
  103. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
  104. package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
  105. package/dist/internal/runtime/loaders/static-loader.js +15 -21
  106. package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
  107. package/dist/internal/runtime/namespace.cjs +82 -0
  108. package/dist/internal/runtime/namespace.cjs.map +1 -0
  109. package/dist/internal/runtime/namespace.d.ts +5 -0
  110. package/dist/internal/runtime/namespace.js +58 -0
  111. package/dist/internal/runtime/namespace.js.map +1 -0
  112. package/dist/internal/runtime/rsc-imports.cjs +86 -0
  113. package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
  114. package/dist/internal/runtime/rsc-imports.d.ts +39 -0
  115. package/dist/internal/runtime/rsc-imports.js +50 -0
  116. package/dist/internal/runtime/rsc-imports.js.map +1 -0
  117. package/dist/internal/runtime/rsc-runtime.cjs +17 -0
  118. package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
  119. package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
  120. package/dist/internal/runtime/rsc-runtime.js +1 -0
  121. package/dist/internal/runtime/rsc-runtime.js.map +1 -0
  122. package/dist/internal/runtime/rsc.cjs +23 -12
  123. package/dist/internal/runtime/rsc.cjs.map +1 -1
  124. package/dist/internal/runtime/rsc.d.ts +19 -2
  125. package/dist/internal/runtime/rsc.js +20 -11
  126. package/dist/internal/runtime/rsc.js.map +1 -1
  127. package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
  128. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  129. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
  130. package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
  131. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  132. package/dist/internal/runtime/turbopack/module.cjs +17 -4
  133. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  134. package/dist/internal/runtime/turbopack/module.d.ts +23 -1
  135. package/dist/internal/runtime/turbopack/module.js +16 -4
  136. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  137. package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
  138. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  139. package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
  140. package/dist/internal/runtime/turbopack/patterns.js +23 -7
  141. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  142. package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
  143. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
  144. package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
  145. package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
  146. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
  147. package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
  148. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  149. package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
  150. package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
  151. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  152. package/dist/internal/runtime/turbopack/shared-modules.cjs +21 -15
  153. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  154. package/dist/internal/runtime/turbopack/shared-modules.d.ts +9 -2
  155. package/dist/internal/runtime/turbopack/shared-modules.js +24 -18
  156. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  157. package/dist/internal/runtime/types.cjs.map +1 -1
  158. package/dist/internal/runtime/types.d.ts +5 -41
  159. package/dist/internal/utils/logger.cjs +1 -1
  160. package/dist/internal/utils/logger.cjs.map +1 -1
  161. package/dist/internal/utils/logger.d.ts +2 -2
  162. package/dist/internal/utils/logger.js +1 -1
  163. package/dist/internal/utils/logger.js.map +1 -1
  164. package/dist/remote/html.cjs +78 -22
  165. package/dist/remote/html.cjs.map +1 -1
  166. package/dist/remote/html.js +78 -22
  167. package/dist/remote/html.js.map +1 -1
  168. package/dist/remote/nextjs/app.cjs +14 -55
  169. package/dist/remote/nextjs/app.cjs.map +1 -1
  170. package/dist/remote/nextjs/app.js +24 -45
  171. package/dist/remote/nextjs/app.js.map +1 -1
  172. package/dist/types-59251814.d.ts +94 -0
  173. package/package.json +2 -2
  174. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
  175. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
  176. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
@@ -0,0 +1,58 @@
1
+ const SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
2
+ const LEGACY_ALIASES = [
3
+ { global: "__remote_component_scopes__", prop: "scopes" },
4
+ {
5
+ global: "__remote_components_turbopack_chunk_loader_promise__",
6
+ prop: "chunkCache"
7
+ },
8
+ { global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
9
+ { global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
10
+ { global: "__remote_bundle_url__", prop: "bundleUrls" },
11
+ { global: "__rc_module_registry__", prop: "moduleRegistry" },
12
+ {
13
+ global: "__remote_component_host_shared_modules__",
14
+ prop: "hostSharedModules"
15
+ },
16
+ { global: "__remote_next_css__", prop: "cssCache" }
17
+ ];
18
+ function getNamespace() {
19
+ const g = globalThis;
20
+ const existing = g.__remote_components__;
21
+ if (existing) {
22
+ return existing;
23
+ }
24
+ const ns = {
25
+ scopes: /* @__PURE__ */ new Map(),
26
+ chunkCache: {},
27
+ mountFns: {},
28
+ unmountFns: {},
29
+ bundleUrls: {},
30
+ moduleRegistry: {},
31
+ dispatcherRuntime: void 0,
32
+ hostSharedModules: {},
33
+ cssCache: {},
34
+ shadowRoots: {}
35
+ };
36
+ const nsRecord = ns;
37
+ for (const { global, prop } of LEGACY_ALIASES) {
38
+ const legacyValue = g[global];
39
+ if (legacyValue != null) {
40
+ nsRecord[prop] = legacyValue;
41
+ }
42
+ g[global] = ns[prop];
43
+ }
44
+ const gRecord = g;
45
+ for (const key of Object.keys(gRecord)) {
46
+ if (key.startsWith(SHADOW_ROOT_PREFIX)) {
47
+ const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
48
+ ns.shadowRoots[suffix] = gRecord[key];
49
+ delete gRecord[key];
50
+ }
51
+ }
52
+ g.__remote_components__ = ns;
53
+ return ns;
54
+ }
55
+ export {
56
+ getNamespace
57
+ };
58
+ //# sourceMappingURL=namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/namespace.ts"],"sourcesContent":["import type { RemoteScope } from '#internal/runtime/turbopack/remote-scope';\nimport type {\n GlobalScope,\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\n\n/**\n * Typed namespace for all remote-components runtime state.\n *\n * Consolidates scattered `globalThis` globals into a single object at\n * `globalThis.__remote_components__`. Each property corresponds to a\n * previously independent global — see inline `@see` tags for the original\n * global name. Code that previously read from those globals still works\n * because each migration writes through to both the namespace and the\n * legacy global (pointing at the same underlying object).\n */\nexport interface RemoteComponentsNamespace {\n /** @see `__remote_component_scopes__` */\n scopes: Map<string, RemoteScope>;\n /** @see `__remote_components_turbopack_chunk_loader_promise__` */\n chunkCache: Record<string, Promise<unknown>>;\n /** @see `__remote_script_entrypoint_mount__` */\n mountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_script_entrypoint_unmount__` */\n unmountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_bundle_url__` */\n bundleUrls: Record<string, string | URL>;\n /** @see `__rc_module_registry__` */\n moduleRegistry: Record<string, unknown>;\n /** @see `__webpack_require_type__` */\n dispatcherRuntime: string | undefined;\n /** @see `__remote_component_host_shared_modules__` */\n hostSharedModules: Record<string, () => Promise<unknown>>;\n /** @see `__remote_next_css__` */\n cssCache: Record<string, ChildNode[]>;\n /** @see `__remote_components_shadowroot_*` */\n shadowRoots: Record<string, ShadowRoot | null>;\n}\n\n/** Prefix for legacy per-key shadow root globals (`__remote_components_shadowroot_*`). */\nconst SHADOW_ROOT_PREFIX = '__remote_components_shadowroot_';\n\n/**\n * Backward-compat aliases for globals used in <=0.3.3.\n *\n * Only includes object/Map values that can be aliased by reference.\n * Primitives (`dispatcherRuntime`) must use write-through at their call sites.\n * Dynamic-key shadow root globals are adopted separately in `getNamespace()`.\n */\nconst LEGACY_ALIASES: ReadonlyArray<{\n global: string;\n prop: keyof RemoteComponentsNamespace;\n}> = [\n { global: '__remote_component_scopes__', prop: 'scopes' },\n {\n global: '__remote_components_turbopack_chunk_loader_promise__',\n prop: 'chunkCache',\n },\n { global: '__remote_script_entrypoint_mount__', prop: 'mountFns' },\n { global: '__remote_script_entrypoint_unmount__', prop: 'unmountFns' },\n { global: '__remote_bundle_url__', prop: 'bundleUrls' },\n { global: '__rc_module_registry__', prop: 'moduleRegistry' },\n {\n global: '__remote_component_host_shared_modules__',\n prop: 'hostSharedModules',\n },\n { global: '__remote_next_css__', prop: 'cssCache' },\n];\n\n/**\n * Returns the single shared `RemoteComponentsNamespace` instance, creating\n * it on first access. The namespace lives at `globalThis.__remote_components__`\n * so every module in the page shares the same state regardless of how many\n * copies of the library are loaded.\n *\n * On first initialization this function also handles backward compatibility\n * with legacy globals:\n * 1. **Adopt**: if a legacy global already exists (written by older code before\n * the namespace was created), its value becomes the initial namespace value.\n * 2. **Alias**: legacy globals are assigned to point at the namespace's objects,\n * so older code that reads the legacy global sees the same reference.\n */\nexport function getNamespace(): RemoteComponentsNamespace {\n const g = globalThis as GlobalScope & MountUnmountFunctions;\n const existing = g.__remote_components__;\n if (existing) {\n return existing;\n }\n\n const ns: RemoteComponentsNamespace = {\n scopes: new Map(),\n chunkCache: {},\n mountFns: {},\n unmountFns: {},\n bundleUrls: {},\n moduleRegistry: {},\n dispatcherRuntime: undefined,\n hostSharedModules: {},\n cssCache: {},\n shadowRoots: {},\n };\n\n // Adopt any pre-existing legacy globals, then alias them to the namespace.\n const nsRecord = ns as unknown as Record<string, unknown>;\n for (const { global, prop } of LEGACY_ALIASES) {\n const legacyValue = (g as Record<string, unknown>)[global];\n if (legacyValue != null) {\n nsRecord[prop] = legacyValue;\n }\n (g as Record<string, unknown>)[global] = ns[prop];\n }\n\n // Adopt per-key shadow root globals used in <=0.3.3\n // (e.g. `globalThis.__remote_components_shadowroot_<key> = root`).\n const gRecord = g as Record<string, unknown>;\n for (const key of Object.keys(gRecord)) {\n if (key.startsWith(SHADOW_ROOT_PREFIX)) {\n const suffix = key.slice(SHADOW_ROOT_PREFIX.length);\n ns.shadowRoots[suffix] = gRecord[key] as ShadowRoot | null;\n delete gRecord[key];\n }\n }\n\n g.__remote_components__ = ns;\n return ns;\n}\n"],"mappings":"AAyCA,MAAM,qBAAqB;AAS3B,MAAM,iBAGD;AAAA,EACH,EAAE,QAAQ,+BAA+B,MAAM,SAAS;AAAA,EACxD;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,sCAAsC,MAAM,WAAW;AAAA,EACjE,EAAE,QAAQ,wCAAwC,MAAM,aAAa;AAAA,EACrE,EAAE,QAAQ,yBAAyB,MAAM,aAAa;AAAA,EACtD,EAAE,QAAQ,0BAA0B,MAAM,iBAAiB;AAAA,EAC3D;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,uBAAuB,MAAM,WAAW;AACpD;AAeO,SAAS,eAA0C;AACxD,QAAM,IAAI;AACV,QAAM,WAAW,EAAE;AACnB,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,KAAgC;AAAA,IACpC,QAAQ,oBAAI,IAAI;AAAA,IAChB,YAAY,CAAC;AAAA,IACb,UAAU,CAAC;AAAA,IACX,YAAY,CAAC;AAAA,IACb,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,mBAAmB;AAAA,IACnB,mBAAmB,CAAC;AAAA,IACpB,UAAU,CAAC;AAAA,IACX,aAAa,CAAC;AAAA,EAChB;AAGA,QAAM,WAAW;AACjB,aAAW,EAAE,QAAQ,KAAK,KAAK,gBAAgB;AAC7C,UAAM,cAAe,EAA8B,MAAM;AACzD,QAAI,eAAe,MAAM;AACvB,eAAS,IAAI,IAAI;AAAA,IACnB;AACA,IAAC,EAA8B,MAAM,IAAI,GAAG,IAAI;AAAA,EAClD;AAIA,QAAM,UAAU;AAChB,aAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,QAAI,IAAI,WAAW,kBAAkB,GAAG;AACtC,YAAM,SAAS,IAAI,MAAM,mBAAmB,MAAM;AAClD,SAAG,YAAY,MAAM,IAAI,QAAQ,GAAG;AACpC,aAAO,QAAQ,GAAG;AAAA,IACpB;AAAA,EACF;AAEA,IAAE,wBAAwB;AAC1B,SAAO;AACT;","names":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var rsc_imports_exports = {};
30
+ __export(rsc_imports_exports, {
31
+ importRSCClientBrowser: () => importRSCClientBrowser,
32
+ importRSCClientEdge: () => importRSCClientEdge,
33
+ importRSCServer: () => importRSCServer
34
+ });
35
+ module.exports = __toCommonJS(rsc_imports_exports);
36
+ async function importRSCClientEdge() {
37
+ try {
38
+ return await import("next/dist/compiled/react-server-dom-webpack/client.edge");
39
+ } catch {
40
+ return await import("react-server-dom-webpack/client.edge");
41
+ }
42
+ }
43
+ async function importRSCClientBrowser() {
44
+ try {
45
+ return await import("next/dist/compiled/react-server-dom-webpack/client.browser");
46
+ } catch {
47
+ const mod = await import("react-server-dom-webpack/client.browser");
48
+ return mod.default ?? mod;
49
+ }
50
+ }
51
+ async function importRSCServer() {
52
+ const [primary, fallback] = await Promise.all(
53
+ process.env.TURBOPACK ? [
54
+ tryImport(
55
+ () => import("react-server-dom-turbopack/server")
56
+ ),
57
+ tryImport(
58
+ () => import("react-server-dom-turbopack/server.edge")
59
+ )
60
+ ] : [
61
+ tryImport(
62
+ () => import("react-server-dom-webpack/server")
63
+ ),
64
+ tryImport(
65
+ () => import("react-server-dom-webpack/server.edge")
66
+ )
67
+ ]
68
+ );
69
+ return {
70
+ renderToReadableStream: primary.renderToReadableStream ?? fallback.renderToReadableStream
71
+ };
72
+ }
73
+ async function tryImport(importer) {
74
+ try {
75
+ return await importer();
76
+ } catch {
77
+ return {};
78
+ }
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ importRSCClientBrowser,
83
+ importRSCClientEdge,
84
+ importRSCServer
85
+ });
86
+ //# sourceMappingURL=rsc-imports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc-imports.ts"],"sourcesContent":["/**\n * Single import hub for all React Server Components runtime modules.\n *\n * Each function encapsulates the try/catch fallback chain that probes\n * Next.js internal paths first, then falls back to the public\n * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.\n * This keeps version-specific import paths out of business logic.\n */\n\nimport type {\n RSCClientBrowserRuntime,\n RSCClientEdgeRuntime,\n RSCServerRuntime,\n} from './rsc-runtime';\n\n/**\n * Imports the RSC client for the **edge** runtime (server-side).\n * Used by `fetch-remote-component.ts` to deserialise RSC flight data.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.edge` module.\n */\nexport async function importRSCClientEdge(): Promise<RSCClientEdgeRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n } catch {\n return await import('react-server-dom-webpack/client.edge');\n }\n}\n\n/**\n * Imports the RSC client for the **browser** runtime (client-side hydration).\n * Used by `component-loader.ts` to hydrate RSC streams in the browser.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.browser` module (which may use a\n * default export depending on the package version).\n */\nexport async function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.browser'\n );\n } catch {\n const mod = await import('react-server-dom-webpack/client.browser');\n // Some versions export `createFromReadableStream` as a default export\n return (mod.default ?? mod) as RSCClientBrowserRuntime;\n }\n}\n\n/**\n * Imports the RSC **server** renderer for `ExposeRemoteComponent`.\n *\n * When `TURBOPACK` is set in the environment, imports from\n * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.\n * Each variant tries the primary path first (`/server`), falling back to\n * the `.edge` entry point.\n */\nexport async function importRSCServer(): Promise<RSCServerRuntime> {\n const [primary, fallback] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n\n return {\n renderToReadableStream:\n primary.renderToReadableStream ?? fallback.renderToReadableStream,\n };\n}\n\nasync function tryImport<T>(importer: () => Promise<T>): Promise<T> {\n try {\n return await importer();\n } catch {\n return {} as T;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,eAAsB,sBAAqD;AACzE,MAAI;AACF,WAAO,MAAM,OACX,yDACF;AAAA,EACF,QAAE;AACA,WAAO,MAAM,OAAO,sCAAsC;AAAA,EAC5D;AACF;AAUA,eAAsB,yBAA2D;AAC/E,MAAI;AACF,WAAO,MAAM,OACX,4DACF;AAAA,EACF,QAAE;AACA,UAAM,MAAM,MAAM,OAAO,yCAAyC;AAElE,WAAQ,IAAI,WAAW;AAAA,EACzB;AACF;AAUA,eAAsB,kBAA6C;AACjE,QAAM,CAAC,SAAS,QAAQ,IAAI,MAAM,QAAQ;AAAA,IACxC,QAAQ,IAAI,YACR;AAAA,MACE;AAAA,QACE,MAAM,OAAO,mCAAmC;AAAA,MAClD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,wCAAwC;AAAA,MACvD;AAAA,IACF,IACA;AAAA,MACE;AAAA,QACE,MAAM,OAAO,iCAAiC;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,sCAAsC;AAAA,MACrD;AAAA,IACF;AAAA,EACN;AAEA,SAAO;AAAA,IACL,wBACE,QAAQ,0BAA0B,SAAS;AAAA,EAC/C;AACF;AAEA,eAAe,UAAa,UAAwC;AAClE,MAAI;AACF,WAAO,MAAM,SAAS;AAAA,EACxB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -0,0 +1,39 @@
1
+ import { RSCClientEdgeRuntime, RSCClientBrowserRuntime, RSCServerRuntime } from './rsc-runtime.js';
2
+
3
+ /**
4
+ * Single import hub for all React Server Components runtime modules.
5
+ *
6
+ * Each function encapsulates the try/catch fallback chain that probes
7
+ * Next.js internal paths first, then falls back to the public
8
+ * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.
9
+ * This keeps version-specific import paths out of business logic.
10
+ */
11
+
12
+ /**
13
+ * Imports the RSC client for the **edge** runtime (server-side).
14
+ * Used by `fetch-remote-component.ts` to deserialise RSC flight data.
15
+ *
16
+ * Tries the Next.js compiled path first, falls back to the bare
17
+ * `react-server-dom-webpack/client.edge` module.
18
+ */
19
+ declare function importRSCClientEdge(): Promise<RSCClientEdgeRuntime>;
20
+ /**
21
+ * Imports the RSC client for the **browser** runtime (client-side hydration).
22
+ * Used by `component-loader.ts` to hydrate RSC streams in the browser.
23
+ *
24
+ * Tries the Next.js compiled path first, falls back to the bare
25
+ * `react-server-dom-webpack/client.browser` module (which may use a
26
+ * default export depending on the package version).
27
+ */
28
+ declare function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime>;
29
+ /**
30
+ * Imports the RSC **server** renderer for `ExposeRemoteComponent`.
31
+ *
32
+ * When `TURBOPACK` is set in the environment, imports from
33
+ * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.
34
+ * Each variant tries the primary path first (`/server`), falling back to
35
+ * the `.edge` entry point.
36
+ */
37
+ declare function importRSCServer(): Promise<RSCServerRuntime>;
38
+
39
+ export { importRSCClientBrowser, importRSCClientEdge, importRSCServer };
@@ -0,0 +1,50 @@
1
+ async function importRSCClientEdge() {
2
+ try {
3
+ return await import("next/dist/compiled/react-server-dom-webpack/client.edge");
4
+ } catch {
5
+ return await import("react-server-dom-webpack/client.edge");
6
+ }
7
+ }
8
+ async function importRSCClientBrowser() {
9
+ try {
10
+ return await import("next/dist/compiled/react-server-dom-webpack/client.browser");
11
+ } catch {
12
+ const mod = await import("react-server-dom-webpack/client.browser");
13
+ return mod.default ?? mod;
14
+ }
15
+ }
16
+ async function importRSCServer() {
17
+ const [primary, fallback] = await Promise.all(
18
+ process.env.TURBOPACK ? [
19
+ tryImport(
20
+ () => import("react-server-dom-turbopack/server")
21
+ ),
22
+ tryImport(
23
+ () => import("react-server-dom-turbopack/server.edge")
24
+ )
25
+ ] : [
26
+ tryImport(
27
+ () => import("react-server-dom-webpack/server")
28
+ ),
29
+ tryImport(
30
+ () => import("react-server-dom-webpack/server.edge")
31
+ )
32
+ ]
33
+ );
34
+ return {
35
+ renderToReadableStream: primary.renderToReadableStream ?? fallback.renderToReadableStream
36
+ };
37
+ }
38
+ async function tryImport(importer) {
39
+ try {
40
+ return await importer();
41
+ } catch {
42
+ return {};
43
+ }
44
+ }
45
+ export {
46
+ importRSCClientBrowser,
47
+ importRSCClientEdge,
48
+ importRSCServer
49
+ };
50
+ //# sourceMappingURL=rsc-imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc-imports.ts"],"sourcesContent":["/**\n * Single import hub for all React Server Components runtime modules.\n *\n * Each function encapsulates the try/catch fallback chain that probes\n * Next.js internal paths first, then falls back to the public\n * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.\n * This keeps version-specific import paths out of business logic.\n */\n\nimport type {\n RSCClientBrowserRuntime,\n RSCClientEdgeRuntime,\n RSCServerRuntime,\n} from './rsc-runtime';\n\n/**\n * Imports the RSC client for the **edge** runtime (server-side).\n * Used by `fetch-remote-component.ts` to deserialise RSC flight data.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.edge` module.\n */\nexport async function importRSCClientEdge(): Promise<RSCClientEdgeRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n } catch {\n return await import('react-server-dom-webpack/client.edge');\n }\n}\n\n/**\n * Imports the RSC client for the **browser** runtime (client-side hydration).\n * Used by `component-loader.ts` to hydrate RSC streams in the browser.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.browser` module (which may use a\n * default export depending on the package version).\n */\nexport async function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.browser'\n );\n } catch {\n const mod = await import('react-server-dom-webpack/client.browser');\n // Some versions export `createFromReadableStream` as a default export\n return (mod.default ?? mod) as RSCClientBrowserRuntime;\n }\n}\n\n/**\n * Imports the RSC **server** renderer for `ExposeRemoteComponent`.\n *\n * When `TURBOPACK` is set in the environment, imports from\n * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.\n * Each variant tries the primary path first (`/server`), falling back to\n * the `.edge` entry point.\n */\nexport async function importRSCServer(): Promise<RSCServerRuntime> {\n const [primary, fallback] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n\n return {\n renderToReadableStream:\n primary.renderToReadableStream ?? fallback.renderToReadableStream,\n };\n}\n\nasync function tryImport<T>(importer: () => Promise<T>): Promise<T> {\n try {\n return await importer();\n } catch {\n return {} as T;\n }\n}\n"],"mappings":"AAsBA,eAAsB,sBAAqD;AACzE,MAAI;AACF,WAAO,MAAM,OACX,yDACF;AAAA,EACF,QAAE;AACA,WAAO,MAAM,OAAO,sCAAsC;AAAA,EAC5D;AACF;AAUA,eAAsB,yBAA2D;AAC/E,MAAI;AACF,WAAO,MAAM,OACX,4DACF;AAAA,EACF,QAAE;AACA,UAAM,MAAM,MAAM,OAAO,yCAAyC;AAElE,WAAQ,IAAI,WAAW;AAAA,EACzB;AACF;AAUA,eAAsB,kBAA6C;AACjE,QAAM,CAAC,SAAS,QAAQ,IAAI,MAAM,QAAQ;AAAA,IACxC,QAAQ,IAAI,YACR;AAAA,MACE;AAAA,QACE,MAAM,OAAO,mCAAmC;AAAA,MAClD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,wCAAwC;AAAA,MACvD;AAAA,IACF,IACA;AAAA,MACE;AAAA,QACE,MAAM,OAAO,iCAAiC;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,sCAAsC;AAAA,MACrD;AAAA,IACF;AAAA,EACN;AAEA,SAAO;AAAA,IACL,wBACE,QAAQ,0BAA0B,SAAS;AAAA,EAC/C;AACF;AAEA,eAAe,UAAa,UAAwC;AAClE,MAAI;AACF,WAAO,MAAM,SAAS;AAAA,EACxB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var rsc_runtime_exports = {};
16
+ module.exports = __toCommonJS(rsc_runtime_exports);
17
+ //# sourceMappingURL=rsc-runtime.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc-runtime.ts"],"sourcesContent":["/**\n * Adapter interfaces for React Server Components runtimes.\n *\n * These decouple the rest of the codebase from the concrete module paths\n * (`next/dist/compiled/...`, `react-server-dom-webpack/...`, etc.) so that\n * version-specific import logic lives in a single place (`rsc-imports.ts`).\n */\n\ninterface ClientModuleEntry {\n id: string;\n name: string;\n chunks: string[];\n async: boolean;\n}\n\n/** Edge-runtime RSC client — used by `fetch-remote-component.ts` on the server. */\nexport interface RSCClientEdgeRuntime {\n createFromReadableStream(\n stream: ReadableStream<Uint8Array>,\n options: {\n serverConsumerManifest: {\n moduleLoading: {\n prefix?: string;\n crossOrigin?: boolean | null;\n };\n moduleMap: Record<string, unknown>;\n };\n },\n ): React.ReactNode;\n}\n\n/** Browser-runtime RSC client — used by `component-loader.ts` for hydration. */\nexport interface RSCClientBrowserRuntime {\n createFromReadableStream(stream: ReadableStream<Uint8Array>): React.ReactNode;\n}\n\n/** Server-side RSC renderer — used by the remote `ExposeRemoteComponent`. */\nexport interface RSCServerRuntime {\n renderToReadableStream?: (\n element: React.ReactNode,\n clientModules: Record<string, ClientModuleEntry>,\n options?: {\n onError?: (e: Error) => void;\n },\n ) => ReadableStream<Uint8Array>;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Adapter interfaces for React Server Components runtimes.
3
+ *
4
+ * These decouple the rest of the codebase from the concrete module paths
5
+ * (`next/dist/compiled/...`, `react-server-dom-webpack/...`, etc.) so that
6
+ * version-specific import logic lives in a single place (`rsc-imports.ts`).
7
+ */
8
+ interface ClientModuleEntry {
9
+ id: string;
10
+ name: string;
11
+ chunks: string[];
12
+ async: boolean;
13
+ }
14
+ /** Edge-runtime RSC client — used by `fetch-remote-component.ts` on the server. */
15
+ interface RSCClientEdgeRuntime {
16
+ createFromReadableStream(stream: ReadableStream<Uint8Array>, options: {
17
+ serverConsumerManifest: {
18
+ moduleLoading: {
19
+ prefix?: string;
20
+ crossOrigin?: boolean | null;
21
+ };
22
+ moduleMap: Record<string, unknown>;
23
+ };
24
+ }): React.ReactNode;
25
+ }
26
+ /** Browser-runtime RSC client — used by `component-loader.ts` for hydration. */
27
+ interface RSCClientBrowserRuntime {
28
+ createFromReadableStream(stream: ReadableStream<Uint8Array>): React.ReactNode;
29
+ }
30
+ /** Server-side RSC renderer — used by the remote `ExposeRemoteComponent`. */
31
+ interface RSCServerRuntime {
32
+ renderToReadableStream?: (element: React.ReactNode, clientModules: Record<string, ClientModuleEntry>, options?: {
33
+ onError?: (e: Error) => void;
34
+ }) => ReadableStream<Uint8Array>;
35
+ }
36
+
37
+ export { RSCClientBrowserRuntime, RSCClientEdgeRuntime, RSCServerRuntime };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=rsc-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -18,7 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var rsc_exports = {};
20
20
  __export(rsc_exports, {
21
- createRSCStream: () => createRSCStream
21
+ buildRSCChunks: () => buildRSCChunks,
22
+ createRSCStream: () => createRSCStream,
23
+ fixPayload: () => fixPayload
22
24
  });
23
25
  module.exports = __toCommonJS(rsc_exports);
24
26
  var import_web_streams_polyfill = require("web-streams-polyfill");
@@ -40,6 +42,18 @@ function fixPayload(payload) {
40
42
  }
41
43
  }
42
44
  }
45
+ function buildRSCChunks(rscName, data) {
46
+ const chunks = [];
47
+ for (const chunk of data) {
48
+ for (const line of chunk.split("\n")) {
49
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
50
+ if (match?.groups?.rsc) {
51
+ chunks.push(JSON.parse(`"${match.groups.rsc}"`));
52
+ }
53
+ }
54
+ }
55
+ return chunks;
56
+ }
43
57
  function createRSCStream(rscName, data) {
44
58
  return new import_web_streams_polyfill.ReadableStream({
45
59
  type: "bytes",
@@ -47,16 +61,11 @@ function createRSCStream(rscName, data) {
47
61
  const encoder = new TextEncoder();
48
62
  const self = globalThis;
49
63
  if (data.length > 0) {
50
- data.forEach((chunk) => {
51
- const lines = chunk.split("\n");
52
- for (const line of lines) {
53
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
54
- if (match?.groups?.rsc) {
55
- self[rscName] = self[rscName] ?? [];
56
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
57
- }
58
- }
59
- });
64
+ const parsed = buildRSCChunks(rscName, data);
65
+ if (parsed.length > 0) {
66
+ self[rscName] = self[rscName] ?? [];
67
+ self[rscName].push(...parsed);
68
+ }
60
69
  }
61
70
  const allChunks = (self[rscName] ?? [`0:[null]
62
71
  `]).join("");
@@ -87,6 +96,8 @@ function createRSCStream(rscName, data) {
87
96
  }
88
97
  // Annotate the CommonJS export names for ESM import in node:
89
98
  0 && (module.exports = {
90
- createRSCStream
99
+ buildRSCChunks,
100
+ createRSCStream,
101
+ fixPayload
91
102
  });
92
103
  //# sourceMappingURL=rsc.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload to make it compatible with React JSX development runtime\n */\nfunction fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n // if the current node is a React element, we need to fix the payload\n if (payload[0] === '$') {\n // fix the props (children or other React elements)\n fixPayload(payload[3]);\n if (payload.length === 4) {\n // add placeholder for the missing debug info\n payload.push(null, null, 1);\n }\n } else {\n // we are in an array, continue with visiting each item\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n // we are in an object, continue with visiting each property\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // when the remote component RSC scripts are not found or loaded\n // we need to load the RSC flight data parsing the chunks\n if (data.length > 0) {\n data.forEach((chunk) => {\n const lines = chunk.split('\\n');\n for (const line of lines) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n });\n }\n\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n\n // clear the RSC flight data from the global scope\n self[rscName] = null;\n\n // process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n // parse the chunk to get the id, prefix and payload\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n // parse the payload to a JSON object\n const jsonPayload = JSON.parse(payload) as unknown[];\n // fix the payload to make it compatible with React JSX development runtime\n fixPayload(jsonPayload);\n // reconstruct the chunk to a string\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;AAK/B,SAAS,WAAW,SAAwB;AAC1C,MAAI,MAA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cAAc,KAAK,MAAM,OAAO;AAEtC,uBAAW,WAAW;AAEtB,kBAAM,cAAc,GAAG,UAAU,KAAK,MAAM,UAAU,KAAK,KAAK,UAAU,WAAW;AAErF,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAe,CAAC;AAAA,UACvD,OAAO;AAEL,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,UACjD;AAAA,QACF,OAAO;AAEL,qBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AAED,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload arrays to be compatible with React JSX development runtime.\n * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);\n * the dev runtime expects 7 elements with debug info in positions 4-6.\n */\nexport function fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n if (payload[0] === '$') {\n // React element — fix props recursively, then pad to 7 elements\n fixPayload(payload[3]);\n if (payload.length === 4) {\n payload.push(null, null, 1);\n }\n } else {\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Parses raw RSC script chunks (the `self[\"name\"].push(\"...\")` format produced\n * by `<RemoteComponentData>`) into a flat array of flight-data strings.\n *\n * This is a pure function — it reads from `data` only, never from `globalThis`.\n */\nexport function buildRSCChunks(rscName: string, data: string[]): string[] {\n const chunks: string[] = [];\n\n for (const chunk of data) {\n for (const line of chunk.split('\\n')) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n chunks.push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n }\n\n return chunks;\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream.\n *\n * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),\n * merging them onto `globalThis[rscName]`. Then consumes the global array\n * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // Parse inline script chunks and merge onto the global array\n if (data.length > 0) {\n const parsed = buildRSCChunks(rscName, data);\n if (parsed.length > 0) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(...parsed);\n }\n }\n\n // Consume the global RSC flight data, falling back to an empty payload\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n self[rscName] = null;\n\n // Process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n const jsonPayload = JSON.parse(payload) as unknown[];\n fixPayload(jsonPayload);\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n controller.close();\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;AAOxB,SAAS,WAAW,SAAwB;AACjD,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW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cAAI,SAAS;AACX,kBAAM,cAAc,KAAK,MAAM,OAAO;AACtC,uBAAW,WAAW;AACtB,kBAAM,cAAc,GAAG,UAAU,KAAK,MAAM,UAAU,KAAK,KAAK,UAAU,WAAW;AACrF,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAe,CAAC;AAAA,UACvD,OAAO;AACL,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,UACjD;AAAA,QACF,OAAO;AACL,qBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AACD,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,8 +1,25 @@
1
1
  import { ReadableStream } from 'web-streams-polyfill';
2
2
 
3
3
  /**
4
- * Processes RSC flight data and creates a ReadableStream
4
+ * Fixes RSC payload arrays to be compatible with React JSX development runtime.
5
+ * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);
6
+ * the dev runtime expects 7 elements with debug info in positions 4-6.
7
+ */
8
+ declare function fixPayload(payload: unknown): void;
9
+ /**
10
+ * Parses raw RSC script chunks (the `self["name"].push("...")` format produced
11
+ * by `<RemoteComponentData>`) into a flat array of flight-data strings.
12
+ *
13
+ * This is a pure function — it reads from `data` only, never from `globalThis`.
14
+ */
15
+ declare function buildRSCChunks(rscName: string, data: string[]): string[];
16
+ /**
17
+ * Processes RSC flight data and creates a ReadableStream.
18
+ *
19
+ * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),
20
+ * merging them onto `globalThis[rscName]`. Then consumes the global array
21
+ * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.
5
22
  */
6
23
  declare function createRSCStream(rscName: string, data: string[]): ReadableStream<Uint8Array>;
7
24
 
8
- export { createRSCStream };
25
+ export { buildRSCChunks, createRSCStream, fixPayload };
@@ -17,6 +17,18 @@ function fixPayload(payload) {
17
17
  }
18
18
  }
19
19
  }
20
+ function buildRSCChunks(rscName, data) {
21
+ const chunks = [];
22
+ for (const chunk of data) {
23
+ for (const line of chunk.split("\n")) {
24
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
25
+ if (match?.groups?.rsc) {
26
+ chunks.push(JSON.parse(`"${match.groups.rsc}"`));
27
+ }
28
+ }
29
+ }
30
+ return chunks;
31
+ }
20
32
  function createRSCStream(rscName, data) {
21
33
  return new ReadableStream({
22
34
  type: "bytes",
@@ -24,16 +36,11 @@ function createRSCStream(rscName, data) {
24
36
  const encoder = new TextEncoder();
25
37
  const self = globalThis;
26
38
  if (data.length > 0) {
27
- data.forEach((chunk) => {
28
- const lines = chunk.split("\n");
29
- for (const line of lines) {
30
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
31
- if (match?.groups?.rsc) {
32
- self[rscName] = self[rscName] ?? [];
33
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
34
- }
35
- }
36
- });
39
+ const parsed = buildRSCChunks(rscName, data);
40
+ if (parsed.length > 0) {
41
+ self[rscName] = self[rscName] ?? [];
42
+ self[rscName].push(...parsed);
43
+ }
37
44
  }
38
45
  const allChunks = (self[rscName] ?? [`0:[null]
39
46
  `]).join("");
@@ -63,6 +70,8 @@ function createRSCStream(rscName, data) {
63
70
  });
64
71
  }
65
72
  export {
66
- createRSCStream
73
+ buildRSCChunks,
74
+ createRSCStream,
75
+ fixPayload
67
76
  };
68
77
  //# sourceMappingURL=rsc.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload to make it compatible with React JSX development runtime\n */\nfunction fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n // if the current node is a React element, we need to fix the payload\n if (payload[0] === '$') {\n // fix the props (children or other React elements)\n fixPayload(payload[3]);\n if (payload.length === 4) {\n // add placeholder for the missing debug info\n payload.push(null, null, 1);\n }\n } else {\n // we are in an array, continue with visiting each item\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n // we are in an object, continue with visiting each property\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // when the remote component RSC scripts are not found or loaded\n // we need to load the RSC flight data parsing the chunks\n if (data.length > 0) {\n data.forEach((chunk) => {\n const lines = chunk.split('\\n');\n for (const line of lines) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n });\n }\n\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n\n // clear the RSC flight data from the global scope\n self[rscName] = null;\n\n // process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n // parse the chunk to get the id, prefix and payload\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n // parse the payload to a JSON object\n const jsonPayload = JSON.parse(payload) as unknown[];\n // fix the payload to make it compatible with React JSX development runtime\n fixPayload(jsonPayload);\n // reconstruct the chunk to a string\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n });\n}\n"],"mappings":"AAAA,SAAS,sBAAsB;AAK/B,SAAS,WAAW,SAAwB;AAC1C,MAAI,MAAM,QAAQ,OAAO,GAAG;AAE1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW,GAAG;AAExB,gBAAQ,KAAK,MAAM,MAAM,CAAC;AAAA,MAC5B;AAAA,IACF,OAAO;AAEL,iBAAW,QAAQ,SAAS;AAC1B,mBAAW,IAAI;AAAA,MACjB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,YAAY,YAAY,YAAY,MAAM;AAE1D,eAAW,OAAO,SAAS;AACzB,iBAAY,QAAoC,GAAG,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAKO,SAAS,gBACd,SACA,MAC4B;AAC5B,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM;AAAA,IACN,MAAM,YAAY;AAChB,YAAM,UAAU,IAAI,YAAY;AAChC,YAAM,OAAO;AAKb,UAAI,KAAK,SAAS,GAAG;AACnB,aAAK,QAAQ,CAAC,UAAU;AACtB,gBAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,qBAAW,QAAQ,OAAO;AACxB,kBAAM,QAAQ,2BAA2B,KAAK,IAAI;AAClD,gBAAI,OAAO,QAAQ,KAAK;AACtB,mBAAK,OAAO,IAAI,KAAK,OAAO,KAAK,CAAC;AAClC,mBAAK,OAAO,EAAE,KAAK,KAAK,MAAM,IAAI,MAAM,OAAO,MAAM,CAAW;AAAA,YAClE;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAKA,YAAM,aAAa,KAAK,OAAO,KAAK,CAAC;AAAA,CAAY,GAAG,KAAK,EAAE;AAG3D,WAAK,OAAO,IAAI;AAGhB,gBAAU,MAAM,IAAI,EAAE,QAAQ,CAAC,UAAU;AACvC,YAAI,MAAM,SAAS,GAAG;AAEpB,gBAAM,EAAE,QAAQ,IAAI,QAAQ,QAAQ,IAClC,6EAA6E;AAAA,YAC3E;AAAA,UACF,GAAG,UAAU,CAAC;AAEhB,cAAI,SAAS;AAEX,kBAAM,cAAc,KAAK,MAAM,OAAO;AAEtC,uBAAW,WAAW;AAEtB,kBAAM,cAAc,GAAG,UAAU,KAAK,MAAM,UAAU,KAAK,KAAK,UAAU,WAAW;AAErF,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAe,CAAC;AAAA,UACvD,OAAO;AAEL,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,UACjD;AAAA,QACF,OAAO;AAEL,qBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AAED,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload arrays to be compatible with React JSX development runtime.\n * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);\n * the dev runtime expects 7 elements with debug info in positions 4-6.\n */\nexport function fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n if (payload[0] === '$') {\n // React element — fix props recursively, then pad to 7 elements\n fixPayload(payload[3]);\n if (payload.length === 4) {\n payload.push(null, null, 1);\n }\n } else {\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Parses raw RSC script chunks (the `self[\"name\"].push(\"...\")` format produced\n * by `<RemoteComponentData>`) into a flat array of flight-data strings.\n *\n * This is a pure function — it reads from `data` only, never from `globalThis`.\n */\nexport function buildRSCChunks(rscName: string, data: string[]): string[] {\n const chunks: string[] = [];\n\n for (const chunk of data) {\n for (const line of chunk.split('\\n')) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n chunks.push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n }\n\n return chunks;\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream.\n *\n * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),\n * merging them onto `globalThis[rscName]`. Then consumes the global array\n * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // Parse inline script chunks and merge onto the global array\n if (data.length > 0) {\n const parsed = buildRSCChunks(rscName, data);\n if (parsed.length > 0) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(...parsed);\n }\n }\n\n // Consume the global RSC flight data, falling back to an empty payload\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n self[rscName] = null;\n\n // Process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n const jsonPayload = JSON.parse(payload) as unknown[];\n fixPayload(jsonPayload);\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n controller.close();\n },\n });\n}\n"],"mappings":"AAAA,SAAS,sBAAsB;AAOxB,SAAS,WAAW,SAAwB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