remote-components 0.3.2 → 0.3.4
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.
- package/dist/config/nextjs.cjs +122 -62
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +116 -56
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +5 -1
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +5 -1
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/defaults/app.cjs +2 -5
- package/dist/host/defaults/app.cjs.map +1 -1
- package/dist/host/defaults/app.d.ts +1 -3
- package/dist/host/defaults/app.js +1 -4
- package/dist/host/defaults/app.js.map +1 -1
- package/dist/host/defaults/pages.cjs +2 -5
- package/dist/host/defaults/pages.cjs.map +1 -1
- package/dist/host/defaults/pages.d.ts +1 -3
- package/dist/host/defaults/pages.js +1 -4
- package/dist/host/defaults/pages.js.map +1 -1
- package/dist/host/defaults/shared.cjs +32 -0
- package/dist/host/defaults/shared.cjs.map +1 -0
- package/dist/host/defaults/shared.d.ts +3 -0
- package/dist/host/defaults/shared.js +8 -0
- package/dist/host/defaults/shared.js.map +1 -0
- package/dist/host/html.cjs +533 -351
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +533 -351
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +494 -285
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +468 -259
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/react.cjs +412 -241
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +412 -241
- package/dist/host/react.js.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +6 -22
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +5 -11
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.js +31 -39
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +39 -3
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
- package/dist/internal/host/nextjs/image-shared.js +29 -3
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/nextjs/shared-import.cjs +46 -0
- package/dist/internal/host/nextjs/shared-import.cjs.map +1 -0
- package/dist/internal/host/nextjs/shared-import.d.ts +3 -0
- package/dist/internal/host/nextjs/shared-import.js +12 -0
- package/dist/internal/host/nextjs/shared-import.js.map +1 -0
- package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +2 -1
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/polyfill.cjs +8 -7
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.js +8 -7
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
- package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
- package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
- package/dist/internal/host/shared/shared-module-resolver.js +78 -0
- package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
- package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
- package/dist/internal/remote/nextjs/next-internals.js +26 -0
- package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
- package/dist/internal/runtime/html/apply-origin.cjs +11 -32
- package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
- package/dist/internal/runtime/html/apply-origin.js +11 -32
- package/dist/internal/runtime/html/apply-origin.js.map +1 -1
- package/dist/internal/runtime/html/html-spec.cjs +78 -0
- package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
- package/dist/internal/runtime/html/html-spec.d.ts +23 -0
- package/dist/internal/runtime/html/html-spec.js +41 -0
- package/dist/internal/runtime/html/html-spec.js.map +1 -0
- package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.js +29 -12
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
- package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
- package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
- package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
- package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
- package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/component-loader.js +28 -44
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.cjs +7 -0
- package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.js +7 -0
- package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
- package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/static-loader.js +15 -21
- package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
- package/dist/internal/runtime/namespace.cjs +82 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -0
- package/dist/internal/runtime/namespace.d.ts +5 -0
- package/dist/internal/runtime/namespace.js +58 -0
- package/dist/internal/runtime/namespace.js.map +1 -0
- package/dist/internal/runtime/rsc-imports.cjs +86 -0
- package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
- package/dist/internal/runtime/rsc-imports.d.ts +39 -0
- package/dist/internal/runtime/rsc-imports.js +50 -0
- package/dist/internal/runtime/rsc-imports.js.map +1 -0
- package/dist/internal/{host/shared/resolved-data.cjs → runtime/rsc-runtime.cjs} +3 -3
- package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
- package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
- package/dist/internal/runtime/rsc-runtime.js +1 -0
- package/dist/internal/runtime/rsc.cjs +23 -12
- package/dist/internal/runtime/rsc.cjs.map +1 -1
- package/dist/internal/runtime/rsc.d.ts +19 -2
- package/dist/internal/runtime/rsc.js +20 -11
- package/dist/internal/runtime/rsc.js.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +19 -17
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +23 -1
- package/dist/internal/runtime/turbopack/module.js +19 -18
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
- package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
- package/dist/internal/runtime/turbopack/patterns.js +23 -7
- package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
- package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
- package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
- package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
- package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.cjs +23 -15
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +13 -1
- package/dist/internal/runtime/turbopack/shared-modules.js +25 -18
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +5 -41
- package/dist/internal/utils/logger.cjs +1 -1
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +2 -2
- package/dist/internal/utils/logger.js +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/internal/utils/project-id-env.cjs +31 -0
- package/dist/internal/utils/project-id-env.cjs.map +1 -0
- package/dist/internal/utils/project-id-env.d.ts +7 -0
- package/dist/internal/utils/project-id-env.js +7 -0
- package/dist/internal/utils/project-id-env.js.map +1 -0
- package/dist/internal/utils/project-id.cjs +46 -0
- package/dist/internal/utils/project-id.cjs.map +1 -0
- package/dist/internal/utils/project-id.d.ts +8 -0
- package/dist/internal/utils/project-id.js +22 -0
- package/dist/internal/utils/project-id.js.map +1 -0
- package/dist/remote/defaults/app.cjs +2 -5
- package/dist/remote/defaults/app.cjs.map +1 -1
- package/dist/remote/defaults/app.d.ts +1 -3
- package/dist/remote/defaults/app.js +1 -4
- package/dist/remote/defaults/app.js.map +1 -1
- package/dist/remote/defaults/pages.cjs +2 -5
- package/dist/remote/defaults/pages.cjs.map +1 -1
- package/dist/remote/defaults/pages.d.ts +1 -3
- package/dist/remote/defaults/pages.js +1 -4
- package/dist/remote/defaults/pages.js.map +1 -1
- package/dist/remote/defaults/shared.cjs +32 -0
- package/dist/remote/defaults/shared.cjs.map +1 -0
- package/dist/remote/defaults/shared.d.ts +3 -0
- package/dist/remote/defaults/shared.js +8 -0
- package/dist/remote/defaults/shared.js.map +1 -0
- package/dist/remote/html.cjs +78 -22
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +78 -22
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +16 -56
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +26 -46
- package/dist/remote/nextjs/app.js.map +1 -1
- package/dist/remote/nextjs/pages.cjs +2 -1
- package/dist/remote/nextjs/pages.cjs.map +1 -1
- package/dist/remote/nextjs/pages.js +2 -1
- package/dist/remote/nextjs/pages.js.map +1 -1
- package/dist/types-59251814.d.ts +94 -0
- package/package.json +1 -1
- package/dist/internal/host/shared/resolved-data.cjs.map +0 -1
- package/dist/internal/host/shared/resolved-data.d.ts +0 -48
- package/dist/internal/host/shared/resolved-data.js +0 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
- /package/dist/internal/{host/shared/resolved-data.js.map → runtime/rsc-runtime.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/loaders/static-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type {\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & MountUnmountFunctions;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n"],"mappings":"AAKA,SAAS,UAAU,iCAAiC;AAsBpD,eAAe,kBACb,aACA,kBACY;AACZ,QAAM,cAAc,iBAAiB,WAAW,KAAK;AACrD,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,IAAI,EAAE;AACrD,QAAM,WAAW,MAAM,MAAM,QAAQ;AACrC,MAAI,CAAC,SAAS;AAAI,UAAM,IAAI,MAAM,yBAAyB,SAAS,QAAQ;AAM5E,QAAM,WAAW,MAAM,SAAS,KAAK,GAClC,QAAQ,sBAAsB,KAAK,UAAU,WAAW,CAAC,EACzD;AAAA,IACC;AAAA,IACA,CAAC,GAAG,SAAS,OAAO,iBAAiB;AACnC,YAAM,oBAAoB,IAAI,IAAI,cAAc,WAAW,EAAE;AAC7D,YAAM,oBAAoB,IAAI;AAAA,QAC5B,iBAAiB,iBAAiB,KAAK;AAAA,QACvC,SAAS;AAAA,MACX,EAAE;AACF,aAAO,GAAG,WAAW,QAAQ,oBAAoB;AAAA,IACnD;AAAA,EACF;AACF,QAAM,gBAAgB,IAAI;AAAA,IACxB,IAAI,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAAA,EACjD;AACA,QAAM,iBAAiB;AAAA,IACrB,mBAAmB,KAAK,UAAU,aAAa;AAAA,IAC/C;AAAA,IACA,qCAAqC,KAAK,UAAU,WAAW;AAAA,EACjE,EAAE,KAAK,EAAE;AACT,QAAM,iBAAiB,IAAI;AAAA,IACzB,IAAI,KAAK,CAAC,cAAc,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAAA,EACxD;AACA,QAAM,WAAW,SAAS,cAAc,QAAQ;AAChD,WAAS,OAAO;AAChB,WAAS,MAAM;AACf,MAAI;AACF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AA+C,OAAO,OAAO,IAAI;AAAA,UACjE;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/loaders/static-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = getNamespace().moduleRegistry as Record<string, T>;\n const mod = registry[absoluteSrc] ?? ({} as T);\n delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const ns = getNamespace();\n\n if (ns.mountFns[url.href]) {\n ns.mountFns[url.href] = new Set();\n }\n if (ns.unmountFns[url.href]) {\n ns.unmountFns[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!ns.mountFns[url.href]) {\n ns.mountFns[url.href] = new Set();\n }\n ns.mountFns[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!ns.unmountFns[url.href]) {\n ns.unmountFns[url.href] = new Set();\n }\n ns.unmountFns[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n"],"mappings":"AACA,SAAS,oBAAoB;AAE7B,SAAS,UAAU,iCAAiC;AAsBpD,eAAe,kBACb,aACA,kBACY;AACZ,QAAM,cAAc,iBAAiB,WAAW,KAAK;AACrD,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,IAAI,EAAE;AACrD,QAAM,WAAW,MAAM,MAAM,QAAQ;AACrC,MAAI,CAAC,SAAS;AAAI,UAAM,IAAI,MAAM,yBAAyB,SAAS,QAAQ;AAM5E,QAAM,WAAW,MAAM,SAAS,KAAK,GAClC,QAAQ,sBAAsB,KAAK,UAAU,WAAW,CAAC,EACzD;AAAA,IACC;AAAA,IACA,CAAC,GAAG,SAAS,OAAO,iBAAiB;AACnC,YAAM,oBAAoB,IAAI,IAAI,cAAc,WAAW,EAAE;AAC7D,YAAM,oBAAoB,IAAI;AAAA,QAC5B,iBAAiB,iBAAiB,KAAK;AAAA,QACvC,SAAS;AAAA,MACX,EAAE;AACF,aAAO,GAAG,WAAW,QAAQ,oBAAoB;AAAA,IACnD;AAAA,EACF;AACF,QAAM,gBAAgB,IAAI;AAAA,IACxB,IAAI,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAAA,EACjD;AACA,QAAM,iBAAiB;AAAA,IACrB,mBAAmB,KAAK,UAAU,aAAa;AAAA,IAC/C;AAAA,IACA,qCAAqC,KAAK,UAAU,WAAW;AAAA,EACjE,EAAE,KAAK,EAAE;AACT,QAAM,iBAAiB,IAAI;AAAA,IACzB,IAAI,KAAK,CAAC,cAAc,GAAG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,QACF;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var namespace_exports = {};
|
|
20
|
+
__export(namespace_exports, {
|
|
21
|
+
getNamespace: () => getNamespace
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(namespace_exports);
|
|
24
|
+
const SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
|
|
25
|
+
const LEGACY_ALIASES = [
|
|
26
|
+
{ global: "__remote_component_scopes__", prop: "scopes" },
|
|
27
|
+
{
|
|
28
|
+
global: "__remote_components_turbopack_chunk_loader_promise__",
|
|
29
|
+
prop: "chunkCache"
|
|
30
|
+
},
|
|
31
|
+
{ global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
|
|
32
|
+
{ global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
|
|
33
|
+
{ global: "__remote_bundle_url__", prop: "bundleUrls" },
|
|
34
|
+
{ global: "__rc_module_registry__", prop: "moduleRegistry" },
|
|
35
|
+
{
|
|
36
|
+
global: "__remote_component_host_shared_modules__",
|
|
37
|
+
prop: "hostSharedModules"
|
|
38
|
+
},
|
|
39
|
+
{ global: "__remote_next_css__", prop: "cssCache" }
|
|
40
|
+
];
|
|
41
|
+
function getNamespace() {
|
|
42
|
+
const g = globalThis;
|
|
43
|
+
const existing = g.__remote_components__;
|
|
44
|
+
if (existing) {
|
|
45
|
+
return existing;
|
|
46
|
+
}
|
|
47
|
+
const ns = {
|
|
48
|
+
scopes: /* @__PURE__ */ new Map(),
|
|
49
|
+
chunkCache: {},
|
|
50
|
+
mountFns: {},
|
|
51
|
+
unmountFns: {},
|
|
52
|
+
bundleUrls: {},
|
|
53
|
+
moduleRegistry: {},
|
|
54
|
+
dispatcherRuntime: void 0,
|
|
55
|
+
hostSharedModules: {},
|
|
56
|
+
cssCache: {},
|
|
57
|
+
shadowRoots: {}
|
|
58
|
+
};
|
|
59
|
+
const nsRecord = ns;
|
|
60
|
+
for (const { global, prop } of LEGACY_ALIASES) {
|
|
61
|
+
const legacyValue = g[global];
|
|
62
|
+
if (legacyValue != null) {
|
|
63
|
+
nsRecord[prop] = legacyValue;
|
|
64
|
+
}
|
|
65
|
+
g[global] = ns[prop];
|
|
66
|
+
}
|
|
67
|
+
const gRecord = g;
|
|
68
|
+
for (const key of Object.keys(gRecord)) {
|
|
69
|
+
if (key.startsWith(SHADOW_ROOT_PREFIX)) {
|
|
70
|
+
const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
|
|
71
|
+
ns.shadowRoots[suffix] = gRecord[key];
|
|
72
|
+
delete gRecord[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
g.__remote_components__ = ns;
|
|
76
|
+
return ns;
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
getNamespace
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=namespace.cjs.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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,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":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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":[]}
|
|
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
module.exports = __toCommonJS(
|
|
17
|
-
//# sourceMappingURL=
|
|
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
|
|
@@ -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
|
-
|
|
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
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
|
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,S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AAC,UAAU;AACvC,YAAI,MAAM,SAAS,GAAG;AACpB,gBAAM,EAAE,QAAQ,IAAI,QAAQ,QAAQ,IAClC,6EAA6E;AAAA,YAC3E;AAAA,UACF,GAAG,UAAU,CAAC;AAEhB,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
|
-
*
|
|
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 };
|