remote-components 0.3.1 → 0.3.2
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.map +1 -1
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +390 -353
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +390 -353
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +453 -435
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +461 -443
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/react.cjs +381 -362
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +381 -362
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +2 -2
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.js +2 -2
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +20 -1
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +20 -1
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +2 -5
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.js +2 -5
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +76 -126
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +22 -7
- package/dist/internal/runtime/turbopack/chunk-loader.js +85 -131
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +56 -57
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +14 -11
- package/dist/internal/runtime/turbopack/module.js +54 -56
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.cjs +101 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +55 -0
- package/dist/internal/runtime/turbopack/remote-scope.js +73 -0
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -0
- package/dist/internal/runtime/turbopack/shared-modules.cjs +62 -56
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +7 -3
- package/dist/internal/runtime/turbopack/shared-modules.js +63 -57
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs +39 -29
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +5 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.js +42 -32
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +4 -3
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/internal/utils.cjs +5 -0
- package/dist/internal/utils.cjs.map +1 -1
- package/dist/internal/utils.d.ts +15 -1
- package/dist/internal/utils.js +4 -0
- package/dist/internal/utils.js.map +1 -1
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js.map +1 -1
- package/package.json +1 -1
|
@@ -37,33 +37,43 @@ var import_error = require("#internal/utils/error");
|
|
|
37
37
|
var import_logger = require("#internal/utils/logger");
|
|
38
38
|
var import_chunk_loader = require("./chunk-loader");
|
|
39
39
|
var import_module = require("./module");
|
|
40
|
+
var import_remote_scope = require("./remote-scope");
|
|
40
41
|
var import_shared_modules = require("./shared-modules");
|
|
41
42
|
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
|
|
42
43
|
const self = globalThis;
|
|
44
|
+
const bundleName = bundle ?? "default";
|
|
45
|
+
const scope = (0, import_remote_scope.createScope)(bundleName, url, runtime, resolveClientUrl);
|
|
46
|
+
(0, import_remote_scope.registerScope)(scope);
|
|
43
47
|
if (!self.__remote_bundle_url__) {
|
|
44
48
|
self.__remote_bundle_url__ = {};
|
|
45
49
|
}
|
|
46
|
-
self.__remote_bundle_url__[
|
|
50
|
+
self.__remote_bundle_url__[bundleName] = url;
|
|
51
|
+
if (scope.scopedName !== bundleName) {
|
|
52
|
+
self.__remote_bundle_url__[scope.scopedName] = url;
|
|
53
|
+
}
|
|
47
54
|
self.__webpack_get_script_filename__ = () => null;
|
|
48
|
-
|
|
55
|
+
const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack";
|
|
56
|
+
if (willCreateDispatchers) {
|
|
49
57
|
if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
|
|
50
58
|
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
51
59
|
self.__original_webpack_require__ = self.__webpack_require__;
|
|
52
60
|
}
|
|
53
|
-
self.__webpack_chunk_load__ = (0, import_chunk_loader.
|
|
54
|
-
self.__webpack_require__ =
|
|
61
|
+
self.__webpack_chunk_load__ = (0, import_chunk_loader.createChunkDispatcher)();
|
|
62
|
+
self.__webpack_require__ = createModuleDispatcher(runtime);
|
|
55
63
|
self.__webpack_require_type__ = runtime;
|
|
56
64
|
if (self.__remote_webpack_require__ && runtime === import_constants.RUNTIME_TURBOPACK) {
|
|
57
|
-
|
|
58
|
-
self.__remote_webpack_require__[
|
|
59
|
-
self.__remote_webpack_require__[remoteBundle].type = "turbopack";
|
|
65
|
+
self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
|
|
66
|
+
self.__remote_webpack_require__[bundleName].type = "turbopack";
|
|
60
67
|
}
|
|
61
68
|
}
|
|
69
|
+
if (self.__remote_webpack_require__?.[bundleName] && scope.scopedName !== bundleName) {
|
|
70
|
+
self.__remote_webpack_require__[scope.scopedName] = self.__remote_webpack_require__[bundleName];
|
|
71
|
+
}
|
|
62
72
|
if (runtime === import_constants.RUNTIME_TURBOPACK) {
|
|
63
73
|
const results = await Promise.allSettled(
|
|
64
74
|
scripts.map((script) => {
|
|
65
75
|
if (script.src) {
|
|
66
|
-
return
|
|
76
|
+
return (0, import_chunk_loader.loadChunkWithScope)(scope, script.src);
|
|
67
77
|
}
|
|
68
78
|
return Promise.resolve(void 0);
|
|
69
79
|
})
|
|
@@ -85,54 +95,54 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
85
95
|
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
86
96
|
...shared
|
|
87
97
|
};
|
|
88
|
-
await (0, import_shared_modules.initializeSharedModules)(
|
|
89
|
-
bundle ?? "default",
|
|
90
|
-
// include all core modules as shared
|
|
91
|
-
coreShared,
|
|
92
|
-
remoteShared
|
|
93
|
-
);
|
|
98
|
+
await (0, import_shared_modules.initializeSharedModules)(scope, coreShared, remoteShared);
|
|
94
99
|
}
|
|
95
|
-
function
|
|
100
|
+
function createModuleDispatcher(runtime) {
|
|
96
101
|
return (id) => {
|
|
97
102
|
const self = globalThis;
|
|
98
103
|
const { bundle, id: moduleId } = id.match(import_patterns.REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
99
104
|
bundle: "default",
|
|
100
105
|
id
|
|
101
106
|
};
|
|
102
|
-
const
|
|
103
|
-
|
|
107
|
+
const bundleName = bundle ?? "default";
|
|
108
|
+
const remoteRuntime = self.__remote_webpack_require__?.[bundleName] ? self.__remote_webpack_require__[bundleName]?.type || "webpack" : runtime;
|
|
109
|
+
(0, import_logger.logDebug)(
|
|
110
|
+
"ModuleDispatcher",
|
|
111
|
+
`Resolving "${id}" (bundle: "${bundleName}", runtime: "${remoteRuntime}")`
|
|
112
|
+
);
|
|
104
113
|
try {
|
|
105
114
|
if (remoteRuntime === import_constants.RUNTIME_WEBPACK && bundle && moduleId) {
|
|
106
115
|
return self.__remote_webpack_require__?.[bundle]?.(moduleId);
|
|
107
116
|
}
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return sharedModule;
|
|
117
|
+
const scope = (0, import_remote_scope.getScope)(bundleName);
|
|
118
|
+
if (scope) {
|
|
119
|
+
return (0, import_module.requireModule)(scope, moduleId ?? id, id);
|
|
112
120
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
throw new Error(`Module "${id}" not found.`);
|
|
121
|
+
throw new Error(
|
|
122
|
+
`Module "${id}" not found \u2014 no scope for bundle "${bundleName}".`
|
|
123
|
+
);
|
|
117
124
|
} catch (requireError) {
|
|
118
125
|
(0, import_logger.logWarn)(
|
|
119
|
-
"
|
|
126
|
+
"ModuleDispatcher",
|
|
120
127
|
`Module require failed: ${String(requireError)}`
|
|
121
128
|
);
|
|
122
129
|
if (typeof self.__original_webpack_require__ !== "function") {
|
|
123
130
|
throw new import_error.RemoteComponentsError(
|
|
124
|
-
`Module "${id}" not found in remote component bundle "${
|
|
131
|
+
`Module "${id}" not found in remote component bundle "${bundleName}".`,
|
|
125
132
|
{
|
|
126
133
|
cause: requireError instanceof Error ? requireError : void 0
|
|
127
134
|
}
|
|
128
135
|
);
|
|
129
136
|
}
|
|
130
137
|
try {
|
|
131
|
-
(0, import_logger.logDebug)(
|
|
138
|
+
(0, import_logger.logDebug)(
|
|
139
|
+
"ModuleDispatcher",
|
|
140
|
+
"Falling back to original webpack require"
|
|
141
|
+
);
|
|
132
142
|
return self.__original_webpack_require__(id);
|
|
133
143
|
} catch (originalError) {
|
|
134
144
|
throw new import_error.RemoteComponentsError(
|
|
135
|
-
`Module "${id}" not found in remote component bundle "${
|
|
145
|
+
`Module "${id}" not found in remote component bundle "${bundleName}".`,
|
|
136
146
|
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
137
147
|
);
|
|
138
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/webpack-runtime.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkLoader } from './chunk-loader';\nimport { handleTurbopackModule } from './module';\nimport { getSharedModule, initializeSharedModules } from './shared-modules';\n\n/**\n * Sets up webpack runtime environment for remote components.\n * This function initializes the global webpack require and chunk loading functions\n * to support loading and executing remote component bundles.\n *\n * @param runtime - The bundler runtime type ('webpack' or 'turbopack')\n * @param scripts - Initial script chunks to load for Turbopack runtime\n * @param url - Base URL for the remote component bundle\n * @param bundle - Bundle identifier (defaults to 'default')\n * @param shared - Host-provided shared modules (e.g., React)\n * @param remoteShared - Mapping of remote module IDs to shared module names\n */\nexport async function setupWebpackRuntime(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n shared: Record<string, () => Promise<unknown>> = {},\n remoteShared: Record<string, string> = {},\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n\n if (!self.__remote_bundle_url__) {\n self.__remote_bundle_url__ = {};\n }\n self.__remote_bundle_url__[bundle ?? 'default'] = url;\n self.__webpack_get_script_filename__ = () => null;\n\n if (\n typeof self.__webpack_require__ !== 'function' ||\n self.__webpack_require_type__ !== 'turbopack'\n ) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);\n self.__webpack_require__ = createModuleRequire(runtime);\n self.__webpack_require_type__ = runtime;\n\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n const remoteBundle = bundle ?? 'default';\n self.__remote_webpack_require__[remoteBundle] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[remoteBundle].type = 'turbopack';\n }\n }\n\n // load all initial chunks when using Turbopack runtime\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return self.__webpack_chunk_load__?.(script.src, bundle);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n // initialize shared modules with core React dependencies\n const coreShared = {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...shared,\n };\n await initializeSharedModules(\n bundle ?? 'default',\n // include all core modules as shared\n coreShared,\n remoteShared,\n );\n}\n\n/**\n * Creates module require function for webpack runtime.\n * This function resolves module IDs to their exports, handling:\n * - Webpack remotes (pre-loaded bundles)\n * - Shared modules (React, etc.)\n * - Turbopack modules (dynamically loaded)\n */\nfunction createModuleRequire(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : runtime;\n\n logDebug('WebpackRuntime', `remoteRuntime: \"${remoteRuntime}\"`);\n\n try {\n // for webpack remotes, use the pre-loaded require function\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n const sharedModuleId = moduleId ?? id;\n const sharedModule = getSharedModule(bundle ?? 'default', sharedModuleId);\n if (sharedModule) {\n return sharedModule;\n }\n if (bundle && moduleId) {\n return handleTurbopackModule(bundle, moduleId, id);\n }\n throw new Error(`Module \"${id}\" not found.`);\n } catch (requireError) {\n logWarn(\n 'WebpackRuntime',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundle}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug('WebpackRuntime', 'Falling back to original webpack require');\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundle}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAIO;AACP,sBAAuC;AAEvC,mBAAsC;AACtC,oBAAkC;AAClC,0BAAkC;AAClC,oBAAsC;AACtC,4BAAyD;AAczD,eAAsB,oBACpB,SACA,UAAoC,CAAC,GACrC,MAAW,IAAI,IAAI,SAAS,IAAI,GAChC,QACA,SAAiD,CAAC,GAClD,eAAuC,CAAC,GACxC,kBACe;AACf,QAAM,OAAO;AAEb,MAAI,CAAC,KAAK,uBAAuB;AAC/B,SAAK,wBAAwB,CAAC;AAAA,EAChC;AACA,OAAK,sBAAsB,UAAU,SAAS,IAAI;AAClD,OAAK,kCAAkC,MAAM;AAE7C,MACE,OAAO,KAAK,wBAAwB,cACpC,KAAK,6BAA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AAM,EAAE,QAAQ,IAAI,SAAS,IAAI,GAAG,MAAM,sCAAsB,GAC5D,UAAU;AAAA,MACZ,QAAQ;AAAA,MACR;AAAA,IACF;AACA,UAAM,gBAAgB,KAAK,6BAA6B,UAAU,SAAS,IACvE,KAAK,2BAA2B,UAAU,SAAS,GAAG,QAAQ,YAC9D;AAEJ,gCAAS,kBAAkB,mBAAmB,gBAAgB;AAE9D,QAAI;AAEF,UAAI,kBAAkB,oCAAmB,UAAU,UAAU;AAC3D,eAAO,KAAK,6BAA6B,MAAM,IAAI,QAAQ;AAAA,MAC7D;AACA,YAAM,iBAAiB,YAAY;AACnC,YAAM,mBAAe,uCAAgB,UAAU,WAAW,cAAc;AACxE,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AACA,UAAI,UAAU,UAAU;AACtB,mBAAO,qCAAsB,QAAQ,UAAU,EAAE;AAAA,MACnD;AACA,YAAM,IAAI,MAAM,WAAW,gBAAgB;AAAA,IAC7C,SAAS,cAAP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF,oCAAS,kBAAkB,0CAA0C;AACrE,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/webpack-runtime.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport { createScope, getScope, registerScope } from './remote-scope';\nimport { initializeSharedModules } from './shared-modules';\n\n/**\n * Sets up webpack runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * @param runtime - The bundler runtime type ('webpack' or 'turbopack')\n * @param scripts - Initial script chunks to load for Turbopack runtime\n * @param url - Base URL for the remote component bundle\n * @param bundle - Bundle identifier (defaults to 'default')\n * @param shared - Host-provided shared modules (e.g., React)\n * @param remoteShared - Mapping of remote module IDs to shared module names\n */\nexport async function setupWebpackRuntime(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n shared: Record<string, () => Promise<unknown>> = {},\n remoteShared: Record<string, string> = {},\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const bundleName = bundle ?? 'default';\n\n // Create and register a scope for this remote\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // Still needed by patch-require.ts (webpack plugin that generates runtime\n // code as a string template — can't call getScope at build time) and the\n // HTML host (html/index.tsx writes this before setupWebpackRuntime runs).\n if (!self.__remote_bundle_url__) {\n self.__remote_bundle_url__ = {};\n }\n self.__remote_bundle_url__[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n self.__remote_bundle_url__[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n self.__webpack_require_type__ !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n self.__webpack_require_type__ = runtime;\n\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // Alias __remote_webpack_require__ under the scoped name so the module\n // dispatcher can find it when RSC data uses the rewritten bundle identifier.\n // For turbopack remotes the entry was just created above; for webpack remotes\n // it was populated by the remote's own scripts under the plain name.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n // initialize shared modules with core React dependencies\n const coreShared = {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...shared,\n };\n await initializeSharedModules(scope, coreShared, remoteShared);\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, use the pre-loaded require function\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;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Y,IAAI,EAAE;AAAA,MAChD;AAEA,YAAM,IAAI;AAAA,QACR,WAAW,6CAAwC;AAAA,MACrD;AAAA,IACF,SAAS,cAAP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -3,8 +3,11 @@ import { Runtime } from '../constants.js';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Sets up webpack runtime environment for remote components.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
*
|
|
7
|
+
* Creates a RemoteScope that encapsulates all per-remote state (base URL,
|
|
8
|
+
* proxy callback, module cache, shared modules) and registers it in the
|
|
9
|
+
* global scope registry. Global dispatchers (__webpack_require__,
|
|
10
|
+
* __webpack_chunk_load__) are set once and route to the correct scope.
|
|
8
11
|
*
|
|
9
12
|
* @param runtime - The bundler runtime type ('webpack' or 'turbopack')
|
|
10
13
|
* @param scripts - Initial script chunks to load for Turbopack runtime
|
|
@@ -5,35 +5,45 @@ import {
|
|
|
5
5
|
import { REMOTE_COMPONENT_REGEX } from "#internal/runtime/patterns";
|
|
6
6
|
import { RemoteComponentsError } from "#internal/utils/error";
|
|
7
7
|
import { logDebug, logWarn } from "#internal/utils/logger";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { createChunkDispatcher, loadChunkWithScope } from "./chunk-loader";
|
|
9
|
+
import { requireModule } from "./module";
|
|
10
|
+
import { createScope, getScope, registerScope } from "./remote-scope";
|
|
11
|
+
import { initializeSharedModules } from "./shared-modules";
|
|
11
12
|
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
|
|
12
13
|
const self = globalThis;
|
|
14
|
+
const bundleName = bundle ?? "default";
|
|
15
|
+
const scope = createScope(bundleName, url, runtime, resolveClientUrl);
|
|
16
|
+
registerScope(scope);
|
|
13
17
|
if (!self.__remote_bundle_url__) {
|
|
14
18
|
self.__remote_bundle_url__ = {};
|
|
15
19
|
}
|
|
16
|
-
self.__remote_bundle_url__[
|
|
20
|
+
self.__remote_bundle_url__[bundleName] = url;
|
|
21
|
+
if (scope.scopedName !== bundleName) {
|
|
22
|
+
self.__remote_bundle_url__[scope.scopedName] = url;
|
|
23
|
+
}
|
|
17
24
|
self.__webpack_get_script_filename__ = () => null;
|
|
18
|
-
|
|
25
|
+
const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack";
|
|
26
|
+
if (willCreateDispatchers) {
|
|
19
27
|
if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
|
|
20
28
|
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
21
29
|
self.__original_webpack_require__ = self.__webpack_require__;
|
|
22
30
|
}
|
|
23
|
-
self.__webpack_chunk_load__ =
|
|
24
|
-
self.__webpack_require__ =
|
|
31
|
+
self.__webpack_chunk_load__ = createChunkDispatcher();
|
|
32
|
+
self.__webpack_require__ = createModuleDispatcher(runtime);
|
|
25
33
|
self.__webpack_require_type__ = runtime;
|
|
26
34
|
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
27
|
-
|
|
28
|
-
self.__remote_webpack_require__[
|
|
29
|
-
self.__remote_webpack_require__[remoteBundle].type = "turbopack";
|
|
35
|
+
self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
|
|
36
|
+
self.__remote_webpack_require__[bundleName].type = "turbopack";
|
|
30
37
|
}
|
|
31
38
|
}
|
|
39
|
+
if (self.__remote_webpack_require__?.[bundleName] && scope.scopedName !== bundleName) {
|
|
40
|
+
self.__remote_webpack_require__[scope.scopedName] = self.__remote_webpack_require__[bundleName];
|
|
41
|
+
}
|
|
32
42
|
if (runtime === RUNTIME_TURBOPACK) {
|
|
33
43
|
const results = await Promise.allSettled(
|
|
34
44
|
scripts.map((script) => {
|
|
35
45
|
if (script.src) {
|
|
36
|
-
return
|
|
46
|
+
return loadChunkWithScope(scope, script.src);
|
|
37
47
|
}
|
|
38
48
|
return Promise.resolve(void 0);
|
|
39
49
|
})
|
|
@@ -55,54 +65,54 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
55
65
|
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
56
66
|
...shared
|
|
57
67
|
};
|
|
58
|
-
await initializeSharedModules(
|
|
59
|
-
bundle ?? "default",
|
|
60
|
-
// include all core modules as shared
|
|
61
|
-
coreShared,
|
|
62
|
-
remoteShared
|
|
63
|
-
);
|
|
68
|
+
await initializeSharedModules(scope, coreShared, remoteShared);
|
|
64
69
|
}
|
|
65
|
-
function
|
|
70
|
+
function createModuleDispatcher(runtime) {
|
|
66
71
|
return (id) => {
|
|
67
72
|
const self = globalThis;
|
|
68
73
|
const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
69
74
|
bundle: "default",
|
|
70
75
|
id
|
|
71
76
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
77
|
+
const bundleName = bundle ?? "default";
|
|
78
|
+
const remoteRuntime = self.__remote_webpack_require__?.[bundleName] ? self.__remote_webpack_require__[bundleName]?.type || "webpack" : runtime;
|
|
79
|
+
logDebug(
|
|
80
|
+
"ModuleDispatcher",
|
|
81
|
+
`Resolving "${id}" (bundle: "${bundleName}", runtime: "${remoteRuntime}")`
|
|
82
|
+
);
|
|
74
83
|
try {
|
|
75
84
|
if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
|
|
76
85
|
return self.__remote_webpack_require__?.[bundle]?.(moduleId);
|
|
77
86
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return sharedModule;
|
|
87
|
+
const scope = getScope(bundleName);
|
|
88
|
+
if (scope) {
|
|
89
|
+
return requireModule(scope, moduleId ?? id, id);
|
|
82
90
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
throw new Error(`Module "${id}" not found.`);
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Module "${id}" not found \u2014 no scope for bundle "${bundleName}".`
|
|
93
|
+
);
|
|
87
94
|
} catch (requireError) {
|
|
88
95
|
logWarn(
|
|
89
|
-
"
|
|
96
|
+
"ModuleDispatcher",
|
|
90
97
|
`Module require failed: ${String(requireError)}`
|
|
91
98
|
);
|
|
92
99
|
if (typeof self.__original_webpack_require__ !== "function") {
|
|
93
100
|
throw new RemoteComponentsError(
|
|
94
|
-
`Module "${id}" not found in remote component bundle "${
|
|
101
|
+
`Module "${id}" not found in remote component bundle "${bundleName}".`,
|
|
95
102
|
{
|
|
96
103
|
cause: requireError instanceof Error ? requireError : void 0
|
|
97
104
|
}
|
|
98
105
|
);
|
|
99
106
|
}
|
|
100
107
|
try {
|
|
101
|
-
logDebug(
|
|
108
|
+
logDebug(
|
|
109
|
+
"ModuleDispatcher",
|
|
110
|
+
"Falling back to original webpack require"
|
|
111
|
+
);
|
|
102
112
|
return self.__original_webpack_require__(id);
|
|
103
113
|
} catch (originalError) {
|
|
104
114
|
throw new RemoteComponentsError(
|
|
105
|
-
`Module "${id}" not found in remote component bundle "${
|
|
115
|
+
`Module "${id}" not found in remote component bundle "${bundleName}".`,
|
|
106
116
|
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
107
117
|
);
|
|
108
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/webpack-runtime.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkLoader } from './chunk-loader';\nimport { handleTurbopackModule } from './module';\nimport { getSharedModule, initializeSharedModules } from './shared-modules';\n\n/**\n * Sets up webpack runtime environment for remote components.\n * This function initializes the global webpack require and chunk loading functions\n * to support loading and executing remote component bundles.\n *\n * @param runtime - The bundler runtime type ('webpack' or 'turbopack')\n * @param scripts - Initial script chunks to load for Turbopack runtime\n * @param url - Base URL for the remote component bundle\n * @param bundle - Bundle identifier (defaults to 'default')\n * @param shared - Host-provided shared modules (e.g., React)\n * @param remoteShared - Mapping of remote module IDs to shared module names\n */\nexport async function setupWebpackRuntime(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n shared: Record<string, () => Promise<unknown>> = {},\n remoteShared: Record<string, string> = {},\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n\n if (!self.__remote_bundle_url__) {\n self.__remote_bundle_url__ = {};\n }\n self.__remote_bundle_url__[bundle ?? 'default'] = url;\n self.__webpack_get_script_filename__ = () => null;\n\n if (\n typeof self.__webpack_require__ !== 'function' ||\n self.__webpack_require_type__ !== 'turbopack'\n ) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);\n self.__webpack_require__ = createModuleRequire(runtime);\n self.__webpack_require_type__ = runtime;\n\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n const remoteBundle = bundle ?? 'default';\n self.__remote_webpack_require__[remoteBundle] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[remoteBundle].type = 'turbopack';\n }\n }\n\n // load all initial chunks when using Turbopack runtime\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return self.__webpack_chunk_load__?.(script.src, bundle);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n // initialize shared modules with core React dependencies\n const coreShared = {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...shared,\n };\n await initializeSharedModules(\n bundle ?? 'default',\n // include all core modules as shared\n coreShared,\n remoteShared,\n );\n}\n\n/**\n * Creates module require function for webpack runtime.\n * This function resolves module IDs to their exports, handling:\n * - Webpack remotes (pre-loaded bundles)\n * - Shared modules (React, etc.)\n * - Turbopack modules (dynamically loaded)\n */\nfunction createModuleRequire(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : runtime;\n\n logDebug('WebpackRuntime', `remoteRuntime: \"${remoteRuntime}\"`);\n\n try {\n // for webpack remotes, use the pre-loaded require function\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n const sharedModuleId = moduleId ?? id;\n const sharedModule = getSharedModule(bundle ?? 'default', sharedModuleId);\n if (sharedModule) {\n return sharedModule;\n }\n if (bundle && moduleId) {\n return handleTurbopackModule(bundle, moduleId, id);\n }\n throw new Error(`Module \"${id}\" not found.`);\n } catch (requireError) {\n logWarn(\n 'WebpackRuntime',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundle}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug('WebpackRuntime', 'Falling back to original webpack require');\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundle}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,8BAA8B;AAEvC,SAAS,6BAA6B;AACtC,SAAS,UAAU,eAAe;AAClC,SAAS,yBAAyB;AAClC,SAAS,6BAA6B;AACtC,SAAS,iBAAiB,+BAA+B;AAczD,eAAsB,oBACpB,SACA,UAAoC,CAAC,GACrC,MAAW,IAAI,IAAI,SAAS,IAAI,GAChC,QACA,SAAiD,CAAC,GAClD,eAAuC,CAAC,GACxC,kBACe;AACf,QAAM,OAAO;AAEb,MAAI,CAAC,KAAK,uBAAuB;AAC/B,SAAK,wBAAwB,CAAC;AAAA,EAChC;AACA,OAAK,sBAAsB,UAAU,SAAS,IAAI;AAClD,OAAK,kCAAkC,MAAM;AAE7C,MACE,OAAO,KAAK,wBAAwB,cACpC,KAAK,6BAA6B,aAClC;AAEA,QACE,CAAC,KAAK,gCACN,CA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,MAAM,sBAAsB,GAC5D,UAAU;AAAA,MACZ,QAAQ;AAAA,MACR;AAAA,IACF;AACA,UAAM,gBAAgB,KAAK,6BAA6B,UAAU,SAAS,IACvE,KAAK,2BAA2B,UAAU,SAAS,GAAG,QAAQ,YAC9D;AAEJ,aAAS,kBAAkB,mBAAmB,gBAAgB;AAE9D,QAAI;AAEF,UAAI,kBAAkB,mBAAmB,UAAU,UAAU;AAC3D,eAAO,KAAK,6BAA6B,MAAM,IAAI,QAAQ;AAAA,MAC7D;AACA,YAAM,iBAAiB,YAAY;AACnC,YAAM,eAAe,gBAAgB,UAAU,WAAW,cAAc;AACxE,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AACA,UAAI,UAAU,UAAU;AACtB,eAAO,sBAAsB,QAAQ,UAAU,EAAE;AAAA,MACnD;AACA,YAAM,IAAI,MAAM,WAAW,gBAAgB;AAAA,IAC7C,SAAS,cAAP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF,iBAAS,kBAAkB,0CAA0C;AACrE,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/webpack-runtime.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport { createScope, getScope, registerScope } from './remote-scope';\nimport { initializeSharedModules } from './shared-modules';\n\n/**\n * Sets up webpack runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * @param runtime - The bundler runtime type ('webpack' or 'turbopack')\n * @param scripts - Initial script chunks to load for Turbopack runtime\n * @param url - Base URL for the remote component bundle\n * @param bundle - Bundle identifier (defaults to 'default')\n * @param shared - Host-provided shared modules (e.g., React)\n * @param remoteShared - Mapping of remote module IDs to shared module names\n */\nexport async function setupWebpackRuntime(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n shared: Record<string, () => Promise<unknown>> = {},\n remoteShared: Record<string, string> = {},\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const bundleName = bundle ?? 'default';\n\n // Create and register a scope for this remote\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // Still needed by patch-require.ts (webpack plugin that generates runtime\n // code as a string template — can't call getScope at build time) and the\n // HTML host (html/index.tsx writes this before setupWebpackRuntime runs).\n if (!self.__remote_bundle_url__) {\n self.__remote_bundle_url__ = {};\n }\n self.__remote_bundle_url__[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n self.__remote_bundle_url__[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n self.__webpack_require_type__ !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n self.__webpack_require_type__ = runtime;\n\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // Alias __remote_webpack_require__ under the scoped name so the module\n // dispatcher can find it when RSC data uses the rewritten bundle identifier.\n // For turbopack remotes the entry was just created above; for webpack remotes\n // it was populated by the remote's own scripts under the plain name.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n // initialize shared modules with core React dependencies\n const coreShared = {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...shared,\n };\n await initializeSharedModules(scope, coreShared, remoteShared);\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, use the pre-loaded require function\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,8BAA8B;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,MAChD;AAEA,YAAM,IAAI;AAAA,QACR,WAAW,6CAAwC;AAAA,MACrD;AAAA,IACF,SAAS,cAAP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/types.ts"],"sourcesContent":["import type { RemoteComponentMetadata } from '#internal/runtime/metadata';\n\nexport interface GlobalScope {\n __DISABLE_WEBPACK_EXEC__?: Record<string, boolean>;\n __webpack_chunk_load__?: (\n chunkId: string,\n scriptBundle?: string,\n ) => Promise<unknown> | undefined;\n __original_webpack_chunk_load__?: (\n chunkId: string,\n scriptBundle?: string,\n ) => Promise<unknown> | undefined;\n __webpack_require__?: (id: string) => unknown;\n __webpack_get_script_filename__?: (id: string) => string | null | undefined;\n __original_webpack_require__?: (id: string) => unknown;\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string | number) => unknown) & {\n c?: Record<\n string | number,\n { id: string; parents: string[]; children: string[] }\n >;\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: 'turbopack' | 'webpack' | 'script';\n }\n >;\n __webpack_require_type__?: RemoteComponentMetadata['runtime'];\n
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/types.ts"],"sourcesContent":["import type { RemoteComponentMetadata } from '#internal/runtime/metadata';\n\nexport interface GlobalScope {\n __DISABLE_WEBPACK_EXEC__?: Record<string, boolean>;\n __webpack_chunk_load__?: (\n chunkId: string,\n scriptBundle?: string,\n ) => Promise<unknown> | undefined;\n __original_webpack_chunk_load__?: (\n chunkId: string,\n scriptBundle?: string,\n ) => Promise<unknown> | undefined;\n __webpack_require__?: (id: string) => unknown;\n __webpack_get_script_filename__?: (id: string) => string | null | undefined;\n __original_webpack_require__?: (id: string) => unknown;\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string | number) => unknown) & {\n c?: Record<\n string | number,\n { id: string; parents: string[]; children: string[] }\n >;\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: 'turbopack' | 'webpack' | 'script';\n }\n >;\n __webpack_require_type__?: RemoteComponentMetadata['runtime'];\n /** Base URL per bundle — used by image loaders, HTML host, and webpack plugins. */\n __remote_bundle_url__?: Record<string, string | URL>;\n /** Global chunk dedup cache keyed by absolute URL. */\n __remote_components_turbopack_chunk_loader_promise__?: Record<\n string,\n Promise<unknown>\n >;\n /** RemoteScope registry keyed by scoped name — managed by turbopack/remote-scope.ts. */\n __remote_component_scopes__?: Map<string, unknown>;\n [key: string]: unknown;\n}\n\nexport interface LoaderResult {\n component: React.ReactNode;\n error?: Error;\n}\n\nexport type RSCKey = `__remote_component_rsc_${string}__`;\n\nexport type MountOrUnmountFunction = (\n el?: ShadowRoot | DocumentFragment | HTMLElement | HTMLCollection | null,\n) => Promise<void> | void;\n\nexport interface MountUnmountFunctions {\n __remote_script_entrypoint_mount__?: Record<\n string,\n Set<MountOrUnmountFunction>\n >;\n __remote_script_entrypoint_unmount__?: Record<\n string,\n Set<MountOrUnmountFunction>\n >;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -19,11 +19,12 @@ interface GlobalScope {
|
|
|
19
19
|
type?: 'turbopack' | 'webpack' | 'script';
|
|
20
20
|
}>;
|
|
21
21
|
__webpack_require_type__?: RemoteComponentMetadata['runtime'];
|
|
22
|
-
|
|
22
|
+
/** Base URL per bundle — used by image loaders, HTML host, and webpack plugins. */
|
|
23
23
|
__remote_bundle_url__?: Record<string, string | URL>;
|
|
24
|
+
/** Global chunk dedup cache keyed by absolute URL. */
|
|
24
25
|
__remote_components_turbopack_chunk_loader_promise__?: Record<string, Promise<unknown>>;
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/** RemoteScope registry keyed by scoped name — managed by turbopack/remote-scope.ts. */
|
|
27
|
+
__remote_component_scopes__?: Map<string, unknown>;
|
|
27
28
|
[key: string]: unknown;
|
|
28
29
|
}
|
|
29
30
|
interface LoaderResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/logger.ts"],"sourcesContent":["import { CORS_DOCS_URL } from '#internal/utils/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackRuntime'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the proxy middleware and resolveClientUrl on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'To load assets from a protected deployment, two steps are required: ' +\n '(1) configure withRemoteComponentsHostProxy middleware in your host with the remote URL in allowedProxyUrls, ' +\n 'and (2) provide a resolveClientUrl prop that rewrites cross-origin asset URLs to go through the proxy. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA8B;AAC9B,mBAAsC;
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/logger.ts"],"sourcesContent":["import { CORS_DOCS_URL } from '#internal/utils/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ChunkDispatcher'\n | 'ComponentLoader'\n | 'ModuleDispatcher'\n | 'RemoteScope'\n | 'SharedModules'\n | 'WebpackRuntime'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the proxy middleware and resolveClientUrl on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'To load assets from a protected deployment, two steps are required: ' +\n '(1) configure withRemoteComponentsHostProxy middleware in your host with the remote URL in allowedProxyUrls, ' +\n 'and (2) provide a resolveClientUrl prop that rewrites cross-origin asset URLs to go through the proxy. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA8B;AAC9B,mBAAsC;AAqBtC,MAAM,SAAS;AACf,MAAM,QACJ,OAAO,WAAW,eAAe,aAAa,QAAQ,UAAU,MAAM;AAEjE,SAAS,SAASA,WAAuB,SAAiB;AAC/D,MAAI,OAAO;AAET,YAAQ,MAAM,IAAI,UAAUA,eAAc,SAAS;AAAA,EACrD;AACF;AAEO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;AAEO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;AAEO,SAAS,SACdA,WACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,mCAAsB,IAAI,UAAUA,eAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAMO,SAAS,0BACd,aACA,KACM;AACN,MAAI;AACF,UAAM,SAAS,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;AACxD,QAAI,OAAO,aAAa,eAAe,OAAO,WAAW,SAAS,QAAQ;AACxE;AAAA,IACF;AACA;AAAA,MACE;AAAA,MACA,0CAA0C,OAAO,uSAIvC;AAAA,IACZ;AAAA,EACF,QAAE;AAAA,EAEF;AACF;","names":["location"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type LogLocation = 'ChunkLoader' | 'ComponentLoader' | 'SharedModules' | 'WebpackRuntime' | 'TurbopackModule' | 'StaticLoader' | 'ScriptLoader' | 'Polyfill' | 'HtmlRemote' | 'HtmlHost' | 'Config' | 'NextAppRouter' | 'NextAppRouterCompat' | 'FetchRemoteComponent';
|
|
1
|
+
type LogLocation = 'ChunkLoader' | 'ChunkDispatcher' | 'ComponentLoader' | 'ModuleDispatcher' | 'RemoteScope' | 'SharedModules' | 'WebpackRuntime' | 'TurbopackModule' | 'StaticLoader' | 'ScriptLoader' | 'Polyfill' | 'HtmlRemote' | 'HtmlHost' | 'Config' | 'NextAppRouter' | 'NextAppRouterCompat' | 'FetchRemoteComponent';
|
|
2
2
|
declare function logDebug(location: LogLocation, message: string): void;
|
|
3
3
|
declare function logInfo(location: LogLocation, message: string): void;
|
|
4
4
|
declare function logWarn(location: LogLocation, message: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/logger.ts"],"sourcesContent":["import { CORS_DOCS_URL } from '#internal/utils/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackRuntime'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the proxy middleware and resolveClientUrl on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'To load assets from a protected deployment, two steps are required: ' +\n '(1) configure withRemoteComponentsHostProxy middleware in your host with the remote URL in allowedProxyUrls, ' +\n 'and (2) provide a resolveClientUrl prop that rewrites cross-origin asset URLs to go through the proxy. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/logger.ts"],"sourcesContent":["import { CORS_DOCS_URL } from '#internal/utils/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ChunkDispatcher'\n | 'ComponentLoader'\n | 'ModuleDispatcher'\n | 'RemoteScope'\n | 'SharedModules'\n | 'WebpackRuntime'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the proxy middleware and resolveClientUrl on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'To load assets from a protected deployment, two steps are required: ' +\n '(1) configure withRemoteComponentsHostProxy middleware in your host with the remote URL in allowedProxyUrls, ' +\n 'and (2) provide a resolveClientUrl prop that rewrites cross-origin asset URLs to go through the proxy. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAqBtC,MAAM,SAAS;AACf,MAAM,QACJ,OAAO,WAAW,eAAe,aAAa,QAAQ,UAAU,MAAM;AAEjE,SAAS,SAASA,WAAuB,SAAiB;AAC/D,MAAI,OAAO;AAET,YAAQ,MAAM,IAAI,UAAUA,eAAc,SAAS;AAAA,EACrD;AACF;AAEO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;AAEO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;AAEO,SAAS,SACdA,WACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,sBAAsB,IAAI,UAAUA,eAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAMO,SAAS,0BACd,aACA,KACM;AACN,MAAI;AACF,UAAM,SAAS,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;AACxD,QAAI,OAAO,aAAa,eAAe,OAAO,WAAW,SAAS,QAAQ;AACxE;AAAA,IACF;AACA;AAAA,MACE;AAAA,MACA,0CAA0C,OAAO,uSAIvC;AAAA,IACZ;AAAA,EACF,QAAE;AAAA,EAEF;AACF;","names":["location"]}
|
package/dist/internal/utils.cjs
CHANGED
|
@@ -19,12 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
attrToProp: () => attrToProp,
|
|
22
|
+
computeScopedName: () => computeScopedName,
|
|
22
23
|
escapeString: () => escapeString
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(utils_exports);
|
|
25
26
|
function escapeString(str) {
|
|
26
27
|
return str.replace(/[^a-z0-9]/g, "_");
|
|
27
28
|
}
|
|
29
|
+
function computeScopedName(name, options) {
|
|
30
|
+
return options.isCrossOrigin ? `${name}_${escapeString(options.remoteHost.toLowerCase())}` : name;
|
|
31
|
+
}
|
|
28
32
|
const attrToProp = {
|
|
29
33
|
fetchpriority: "fetchPriority",
|
|
30
34
|
crossorigin: "crossOrigin",
|
|
@@ -35,6 +39,7 @@ const attrToProp = {
|
|
|
35
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
40
|
0 && (module.exports = {
|
|
37
41
|
attrToProp,
|
|
42
|
+
computeScopedName,
|
|
38
43
|
escapeString
|
|
39
44
|
});
|
|
40
45
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\n/**\n * Computes the origin-qualified scoped name for a bundle. Same-origin\n * remotes keep the plain name; cross-origin remotes append the escaped\n * host (hostname + port) to avoid collisions between bundles that share\n * a name but are served from different origins.\n *\n * Used on both the server (to rewrite RSC flight data) and the client\n * (to create and look up RemoteScopes). Both sides must produce the\n * same value for a given remote.\n */\nexport function computeScopedName(\n name: string,\n options: { remoteHost: string; isCrossOrigin: boolean },\n): string {\n return options.isCrossOrigin\n ? `${name}_${escapeString(options.remoteHost.toLowerCase())}`\n : name;\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAYO,SAAS,kBACd,MACA,SACQ;AACR,SAAO,QAAQ,gBACX,GAAG,QAAQ,aAAa,QAAQ,WAAW,YAAY,CAAC,MACxD;AACN;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
|
package/dist/internal/utils.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
declare function escapeString(str: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Computes the origin-qualified scoped name for a bundle. Same-origin
|
|
4
|
+
* remotes keep the plain name; cross-origin remotes append the escaped
|
|
5
|
+
* host (hostname + port) to avoid collisions between bundles that share
|
|
6
|
+
* a name but are served from different origins.
|
|
7
|
+
*
|
|
8
|
+
* Used on both the server (to rewrite RSC flight data) and the client
|
|
9
|
+
* (to create and look up RemoteScopes). Both sides must produce the
|
|
10
|
+
* same value for a given remote.
|
|
11
|
+
*/
|
|
12
|
+
declare function computeScopedName(name: string, options: {
|
|
13
|
+
remoteHost: string;
|
|
14
|
+
isCrossOrigin: boolean;
|
|
15
|
+
}): string;
|
|
2
16
|
declare const attrToProp: Record<string, string>;
|
|
3
17
|
|
|
4
|
-
export { attrToProp, escapeString };
|
|
18
|
+
export { attrToProp, computeScopedName, escapeString };
|
package/dist/internal/utils.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
function escapeString(str) {
|
|
2
2
|
return str.replace(/[^a-z0-9]/g, "_");
|
|
3
3
|
}
|
|
4
|
+
function computeScopedName(name, options) {
|
|
5
|
+
return options.isCrossOrigin ? `${name}_${escapeString(options.remoteHost.toLowerCase())}` : name;
|
|
6
|
+
}
|
|
4
7
|
const attrToProp = {
|
|
5
8
|
fetchpriority: "fetchPriority",
|
|
6
9
|
crossorigin: "crossOrigin",
|
|
@@ -10,6 +13,7 @@ const attrToProp = {
|
|
|
10
13
|
};
|
|
11
14
|
export {
|
|
12
15
|
attrToProp,
|
|
16
|
+
computeScopedName,
|
|
13
17
|
escapeString
|
|
14
18
|
};
|
|
15
19
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":"AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\n/**\n * Computes the origin-qualified scoped name for a bundle. Same-origin\n * remotes keep the plain name; cross-origin remotes append the escaped\n * host (hostname + port) to avoid collisions between bundles that share\n * a name but are served from different origins.\n *\n * Used on both the server (to rewrite RSC flight data) and the client\n * (to create and look up RemoteScopes). Both sides must produce the\n * same value for a given remote.\n */\nexport function computeScopedName(\n name: string,\n options: { remoteHost: string; isCrossOrigin: boolean },\n): string {\n return options.isCrossOrigin\n ? `${name}_${escapeString(options.remoteHost.toLowerCase())}`\n : name;\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":"AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAYO,SAAS,kBACd,MACA,SACQ;AACR,SAAO,QAAQ,gBACX,GAAG,QAAQ,aAAa,QAAQ,WAAW,YAAY,CAAC,MACxD;AACN;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
|