remote-components 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/html/host.cjs +758 -0
  4. package/dist/html/host.cjs.map +1 -0
  5. package/dist/html/host.d.ts +2 -0
  6. package/dist/html/host.js +737 -0
  7. package/dist/html/host.js.map +1 -0
  8. package/dist/next/config.cjs +347 -0
  9. package/dist/next/config.cjs.map +1 -0
  10. package/dist/next/config.d.ts +8 -0
  11. package/dist/next/config.js +325 -0
  12. package/dist/next/config.js.map +1 -0
  13. package/dist/next/host/app-client.cjs +124 -0
  14. package/dist/next/host/app-client.cjs.map +1 -0
  15. package/dist/next/host/app-client.d.ts +33 -0
  16. package/dist/next/host/app-client.js +104 -0
  17. package/dist/next/host/app-client.js.map +1 -0
  18. package/dist/next/host/app-server.cjs +61 -0
  19. package/dist/next/host/app-server.cjs.map +1 -0
  20. package/dist/next/host/app-server.d.ts +7 -0
  21. package/dist/next/host/app-server.js +37 -0
  22. package/dist/next/host/app-server.js.map +1 -0
  23. package/dist/next/host/pages-client.cjs +52 -0
  24. package/dist/next/host/pages-client.cjs.map +1 -0
  25. package/dist/next/host/pages-client.d.ts +17 -0
  26. package/dist/next/host/pages-client.js +18 -0
  27. package/dist/next/host/pages-client.js.map +1 -0
  28. package/dist/next/host/pages-server.cjs +134 -0
  29. package/dist/next/host/pages-server.cjs.map +1 -0
  30. package/dist/next/host/pages-server.d.ts +25 -0
  31. package/dist/next/host/pages-server.js +99 -0
  32. package/dist/next/host/pages-server.js.map +1 -0
  33. package/dist/next/remote/pages.cjs +37 -0
  34. package/dist/next/remote/pages.cjs.map +1 -0
  35. package/dist/next/remote/pages.d.ts +9 -0
  36. package/dist/next/remote/pages.js +13 -0
  37. package/dist/next/remote/pages.js.map +1 -0
  38. package/dist/next/remote/render-client-turbopack.cjs +51 -0
  39. package/dist/next/remote/render-client-turbopack.cjs.map +1 -0
  40. package/dist/next/remote/render-client-turbopack.d.ts +11 -0
  41. package/dist/next/remote/render-client-turbopack.js +27 -0
  42. package/dist/next/remote/render-client-turbopack.js.map +1 -0
  43. package/dist/next/remote/render-client-webpack.cjs +51 -0
  44. package/dist/next/remote/render-client-webpack.cjs.map +1 -0
  45. package/dist/next/remote/render-client-webpack.d.ts +11 -0
  46. package/dist/next/remote/render-client-webpack.js +27 -0
  47. package/dist/next/remote/render-client-webpack.js.map +1 -0
  48. package/dist/next/remote/render-client.cjs +106 -0
  49. package/dist/next/remote/render-client.cjs.map +1 -0
  50. package/dist/next/remote/render-client.d.ts +15 -0
  51. package/dist/next/remote/render-client.js +82 -0
  52. package/dist/next/remote/render-client.js.map +1 -0
  53. package/dist/next/remote/render-server.cjs +133 -0
  54. package/dist/next/remote/render-server.cjs.map +1 -0
  55. package/dist/next/remote/render-server.d.ts +9 -0
  56. package/dist/next/remote/render-server.js +99 -0
  57. package/dist/next/remote/render-server.js.map +1 -0
  58. package/dist/next/remote/server.cjs +29 -0
  59. package/dist/next/remote/server.cjs.map +1 -0
  60. package/dist/next/remote/server.d.ts +3 -0
  61. package/dist/next/remote/server.js +5 -0
  62. package/dist/next/remote/server.js.map +1 -0
  63. package/dist/shared/client/remote-component.cjs +558 -0
  64. package/dist/shared/client/remote-component.cjs.map +1 -0
  65. package/dist/shared/client/remote-component.d.ts +93 -0
  66. package/dist/shared/client/remote-component.js +511 -0
  67. package/dist/shared/client/remote-component.js.map +1 -0
  68. package/dist/shared/ssr/dom-flight.cjs +185 -0
  69. package/dist/shared/ssr/dom-flight.cjs.map +1 -0
  70. package/dist/shared/ssr/dom-flight.d.ts +30 -0
  71. package/dist/shared/ssr/dom-flight.js +151 -0
  72. package/dist/shared/ssr/dom-flight.js.map +1 -0
  73. package/dist/shared/ssr/fetch-remote-component.cjs +162 -0
  74. package/dist/shared/ssr/fetch-remote-component.cjs.map +1 -0
  75. package/dist/shared/ssr/fetch-remote-component.d.ts +31 -0
  76. package/dist/shared/ssr/fetch-remote-component.js +137 -0
  77. package/dist/shared/ssr/fetch-remote-component.js.map +1 -0
  78. package/dist/shared/webpack/next-client-pages-loader.cjs +107 -0
  79. package/dist/shared/webpack/next-client-pages-loader.cjs.map +1 -0
  80. package/dist/shared/webpack/next-client-pages-loader.d.ts +10 -0
  81. package/dist/shared/webpack/next-client-pages-loader.js +83 -0
  82. package/dist/shared/webpack/next-client-pages-loader.js.map +1 -0
  83. package/dist/shared/webpack/shared-modules.cjs +50 -0
  84. package/dist/shared/webpack/shared-modules.cjs.map +1 -0
  85. package/dist/shared/webpack/shared-modules.d.ts +3 -0
  86. package/dist/shared/webpack/shared-modules.js +26 -0
  87. package/dist/shared/webpack/shared-modules.js.map +1 -0
  88. package/dist/types-280a3640.d.ts +8 -0
  89. package/dist/types-a1bd5b56.d.ts +6 -0
  90. package/package.json +151 -0
@@ -0,0 +1,325 @@
1
+ // src/next/config/index.ts
2
+ import { dirname, join as join2, relative } from "node:path";
3
+ import { mkdirSync, writeFileSync } from "node:fs";
4
+ import {
5
+ MicrofrontendsServer,
6
+ getApplicationContext
7
+ } from "@vercel/microfrontends/microfrontends/server";
8
+
9
+ // src/next/config/webpack/index.ts
10
+ import { join } from "node:path";
11
+
12
+ // src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts
13
+ import { RuntimeModule } from "webpack";
14
+ var RemoteWebpackRequireRuntimeModule = class extends RuntimeModule {
15
+ constructor(appName) {
16
+ super("remote-webpack-require");
17
+ this.appName = appName;
18
+ }
19
+ generate() {
20
+ return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
21
+ }
22
+ };
23
+
24
+ // src/next/config/webpack/plugins/remote-webpack-require.ts
25
+ var RemoteWebpackRequirePlugin = class {
26
+ constructor(appName) {
27
+ this.appName = appName;
28
+ }
29
+ apply(compiler) {
30
+ compiler.hooks.thisCompilation.tap(
31
+ "RemoteWebpackRequirePlugin",
32
+ (compilation) => {
33
+ compilation.hooks.runtimeRequirementInTree.for("__webpack_require__").tap("RemoteWebpackRequirePlugin", (chunk) => {
34
+ compilation.addRuntimeModule(
35
+ chunk,
36
+ new RemoteWebpackRequireRuntimeModule(this.appName)
37
+ );
38
+ });
39
+ }
40
+ );
41
+ }
42
+ };
43
+
44
+ // src/next/config/webpack/plugins/module-id-embed-runtime-module.ts
45
+ import { RuntimeModule as RuntimeModule2 } from "webpack";
46
+ var ModuleIdEmbedRuntimeModule = class extends RuntimeModule2 {
47
+ constructor(appName, moduleMap) {
48
+ super("remote-webpack-module-id-embed");
49
+ this.appName = appName;
50
+ this.moduleMap = moduleMap;
51
+ }
52
+ generate() {
53
+ return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
54
+ }
55
+ };
56
+
57
+ // src/next/config/webpack/plugins/module-id-embed.ts
58
+ var ModuleIdEmbedPlugin = class {
59
+ constructor(appName) {
60
+ this.appName = appName;
61
+ }
62
+ apply(compiler) {
63
+ compiler.hooks.thisCompilation.tap("ModuleIdEmbedPlugin", (compilation) => {
64
+ const moduleMap = {};
65
+ compilation.hooks.runtimeRequirementInTree.for(compiler.webpack.RuntimeGlobals.require).tap("ModuleIdEmbedPlugin", (chunk, set) => {
66
+ for (const [key, entry] of compilation.entrypoints) {
67
+ for (const entryChunk of entry.chunks) {
68
+ if (key.includes("nextjs-pages-remote")) {
69
+ for (const mod of compilation.chunkGraph.getChunkModulesIterable(
70
+ entryChunk
71
+ )) {
72
+ const id = compilation.chunkGraph.getModuleId(mod);
73
+ const normalModule = mod;
74
+ if (id) {
75
+ moduleMap[normalModule.resource || normalModule.request] = id;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ for (const mod of compilation.modules) {
82
+ const id = compilation.chunkGraph.getModuleId(mod);
83
+ if (id && mod.layer?.endsWith("browser")) {
84
+ const normalModule = mod;
85
+ moduleMap[normalModule.resource || normalModule.request] = id;
86
+ }
87
+ }
88
+ if (Object.keys(moduleMap).length > 0) {
89
+ compilation.addRuntimeModule(
90
+ chunk,
91
+ new ModuleIdEmbedRuntimeModule(this.appName, moduleMap)
92
+ );
93
+ set.add(compiler.webpack.RuntimeGlobals.require);
94
+ }
95
+ });
96
+ });
97
+ }
98
+ };
99
+
100
+ // src/next/config/webpack/plugins/conditional-exec.ts
101
+ import { Compilation, sources } from "webpack";
102
+ var ConditionalExecPlugin = class {
103
+ apply(compiler) {
104
+ compiler.hooks.thisCompilation.tap(
105
+ "ConditionalExecPlugin",
106
+ (compilation) => {
107
+ compilation.hooks.processAssets.tap(
108
+ {
109
+ name: "ConditionalExecPlugin",
110
+ stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
111
+ },
112
+ (assets) => {
113
+ for (const [name, source] of Object.entries(assets)) {
114
+ if (name.endsWith(".js")) {
115
+ const patchedSource = source.source().toString().replace(
116
+ `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,
117
+ `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__) return; return __webpack_require__(__webpack_require__.s = moduleId); }`
118
+ );
119
+ compilation.updateAsset(
120
+ name,
121
+ new sources.RawSource(patchedSource)
122
+ );
123
+ }
124
+ }
125
+ }
126
+ );
127
+ }
128
+ );
129
+ }
130
+ };
131
+
132
+ // src/next/config/webpack/plugins/patch-require.ts
133
+ var PatchRequirePlugin = class {
134
+ apply(compiler) {
135
+ compiler.hooks.thisCompilation.tap("PatchRequirePlugin", (compilation) => {
136
+ compilation.mainTemplate.hooks.requireExtensions.tap(
137
+ "PatchRequirePlugin",
138
+ (source) => {
139
+ return new compiler.webpack.sources.ConcatSource(
140
+ source,
141
+ `const __webpack_require_orig__ = __webpack_require__;
142
+ const REMOTE_RE = /\\[(?<bundle>[a-zA-Z0-9-_]+)\\] (?<id>.*)/;
143
+ __webpack_require__ = function __remote_webpack_require__(remoteId) {
144
+ const match = REMOTE_RE.exec(remoteId);
145
+ const bundle = match?.groups?.bundle;
146
+ const id = match?.groups?.id;
147
+ if (!(id && bundle)) {
148
+ return __webpack_require_orig__(remoteId);
149
+ }
150
+ if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {
151
+ throw new Error(\`Remote component loading error: "\${bundle}"\`);
152
+ }
153
+ return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);
154
+ };
155
+ Object.assign(__webpack_require__, __webpack_require_orig__);
156
+ const __webpack_require_l__ = __webpack_require__.l;
157
+ __webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {
158
+ const match = REMOTE_RE.exec(chunkId);
159
+ const bundle = match?.groups?.bundle;
160
+ const id = match?.groups?.id;
161
+ if (!(id && bundle)) {
162
+ return __webpack_require_l__(url, done, key, chunkId);
163
+ }
164
+ return done();
165
+ };
166
+ const __webpack_require_o__ = __webpack_require__.o;
167
+ __webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {
168
+ const match = REMOTE_RE.exec(chunkId);
169
+ const bundle = match?.groups?.bundle;
170
+ const id = match?.groups?.id;
171
+ if (!(id && bundle)) {
172
+ return __webpack_require_o__(installedChunks, chunkId);
173
+ }
174
+ return installedChunks[chunkId] = 0;
175
+ };
176
+ const __webpack_require_e__ = __webpack_require__.e;
177
+ __webpack_require__.e = function __remote_webpack_require_e__(chunkId) {
178
+ const match = REMOTE_RE.exec(chunkId);
179
+ const bundle = match?.groups?.bundle;
180
+ const id = match?.groups?.id;
181
+ if (!(id && bundle)) {
182
+ return __webpack_require_e__(chunkId);
183
+ }
184
+ return Promise.resolve([]);
185
+ };`
186
+ ).source().toString();
187
+ }
188
+ );
189
+ });
190
+ }
191
+ };
192
+
193
+ // src/next/config/webpack/index.ts
194
+ function transform(nextConfig, {
195
+ app,
196
+ alias = {},
197
+ emitSharedFiles = () => {
198
+ }
199
+ }) {
200
+ const webpackConfig = nextConfig.webpack;
201
+ nextConfig.webpack = (baseConfig, webpackContext) => {
202
+ const config = typeof webpackConfig === "function" ? webpackConfig(baseConfig, webpackContext) ?? baseConfig : baseConfig;
203
+ config.plugins.push(
204
+ new RemoteWebpackRequirePlugin(app.name),
205
+ new ModuleIdEmbedPlugin(app.name),
206
+ new ConditionalExecPlugin(),
207
+ new PatchRequirePlugin()
208
+ );
209
+ if (!webpackContext.isServer) {
210
+ config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;
211
+ }
212
+ config.resolve = {
213
+ ...config.resolve,
214
+ alias: {
215
+ ...config.resolve.alias,
216
+ ...Object.fromEntries(
217
+ Object.entries(alias).map(([key, value]) => [
218
+ key,
219
+ join(process.cwd(), value)
220
+ ])
221
+ )
222
+ }
223
+ };
224
+ emitSharedFiles();
225
+ return config;
226
+ };
227
+ return nextConfig;
228
+ }
229
+
230
+ // src/next/config/index.ts
231
+ function withRemoteComponents(nextConfig, options) {
232
+ const virtualRemoteComponentSharedRemote = join2(
233
+ process.cwd(),
234
+ nextConfig.distDir ?? ".next",
235
+ "remote-components/shared/remote.tsx"
236
+ );
237
+ const virtualRemoteComponentSharedHost = join2(
238
+ process.cwd(),
239
+ nextConfig.distDir ?? ".next",
240
+ "remote-components/shared/host.tsx"
241
+ );
242
+ const shared = /* @__PURE__ */ new Set([
243
+ ...[
244
+ "react",
245
+ "react/jsx-dev-runtime",
246
+ "react/jsx-runtime",
247
+ "react-dom",
248
+ "react-dom/client",
249
+ "next/navigation",
250
+ "next/link",
251
+ "next/form",
252
+ "next/image",
253
+ "next/script"
254
+ ],
255
+ ...options?.shared ?? []
256
+ ]);
257
+ const vendorShared = {
258
+ react: `'/react/index.js'`,
259
+ "react/jsx-dev-runtime": `'/react/jsx-dev-runtime.js'`,
260
+ "react/jsx-runtime": `'/react/jsx-runtime.js'`,
261
+ "react-dom": `'/react-dom/index.js'`
262
+ };
263
+ const sharedRemote = `'use client';
264
+ module.exports = { shared: { ${Array.from(
265
+ shared
266
+ ).reduce((acc, curr) => {
267
+ acc.push(
268
+ `[${vendorShared[curr] ?? `require.resolve('${curr}')`}]: '${curr}',`
269
+ );
270
+ return acc;
271
+ }, []).join("\n")} } };
272
+ `;
273
+ const sharedHost = `'use client';
274
+ module.exports = { shared: { ${Array.from(
275
+ shared
276
+ ).reduce((acc, curr) => {
277
+ acc.push(`['${curr}']: () => import('${curr}'),`);
278
+ return acc;
279
+ }, []).join("\n")} } };
280
+ `;
281
+ const emitSharedFiles = () => {
282
+ mkdirSync(dirname(virtualRemoteComponentSharedRemote), {
283
+ recursive: true
284
+ });
285
+ writeFileSync(virtualRemoteComponentSharedRemote, sharedRemote, "utf-8");
286
+ writeFileSync(virtualRemoteComponentSharedHost, sharedHost, "utf-8");
287
+ };
288
+ nextConfig.transpilePackages = [
289
+ ...nextConfig.transpilePackages ?? [],
290
+ "remote-components/next",
291
+ "remote-components/next/host",
292
+ "@remote-component/shared/remote",
293
+ "@remote-component/shared/host"
294
+ ];
295
+ const alias = {
296
+ "@remote-component/shared/remote": `./${relative(
297
+ process.cwd(),
298
+ virtualRemoteComponentSharedRemote
299
+ )}`,
300
+ "@remote-component/shared/host": `./${relative(
301
+ process.cwd(),
302
+ virtualRemoteComponentSharedHost
303
+ )}`
304
+ };
305
+ if (process.env.TURBOPACK) {
306
+ nextConfig.turbopack = {
307
+ ...nextConfig.turbopack,
308
+ moduleIds: "named",
309
+ resolveAlias: {
310
+ ...nextConfig.turbopack?.resolveAlias,
311
+ ...alias
312
+ }
313
+ };
314
+ emitSharedFiles();
315
+ return nextConfig;
316
+ }
317
+ const { name: fromApp } = getApplicationContext();
318
+ const microfrontends = MicrofrontendsServer.infer();
319
+ const app = microfrontends.config.getApplication(fromApp);
320
+ return transform(nextConfig, { app, alias, emitSharedFiles });
321
+ }
322
+ export {
323
+ withRemoteComponents
324
+ };
325
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { dirname, join, relative } from 'node:path';\nimport { mkdirSync, writeFileSync } from 'node:fs';\nimport type { NextConfig } from 'next';\nimport {\n MicrofrontendsServer,\n getApplicationContext,\n} from '@vercel/microfrontends/microfrontends/server';\nimport { transform as webpackTransform } from './webpack';\n\ninterface RemoteComponentsOptions {\n shared?: string[];\n}\n\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: RemoteComponentsOptions,\n) {\n const virtualRemoteComponentSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/remote.tsx',\n );\n const virtualRemoteComponentSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/host.tsx',\n );\n\n const shared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/link',\n 'next/form',\n 'next/image',\n 'next/script',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n const sharedRemote = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(\n `[${vendorShared[curr] ?? `require.resolve('${curr}')`}]: '${curr}',`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const sharedHost = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(virtualRemoteComponentSharedRemote, sharedRemote, 'utf-8');\n writeFileSync(virtualRemoteComponentSharedHost, sharedHost, 'utf-8');\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/host',\n '@remote-component/shared/remote',\n '@remote-component/shared/host',\n ];\n\n const alias = {\n '@remote-component/shared/remote': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedRemote,\n )}`,\n '@remote-component/shared/host': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedHost,\n )}`,\n };\n if (process.env.TURBOPACK) {\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n moduleIds: 'named',\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n const { name: fromApp } = getApplicationContext();\n const microfrontends = MicrofrontendsServer.infer();\n\n // fetch the config for the current app\n const app = microfrontends.config.getApplication(fromApp);\n\n // apply the webpack transform\n return webpackTransform(nextConfig, { app, alias, emitSharedFiles });\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name),\n new ConditionalExecPlugin(),\n new PatchRequirePlugin(),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n","import { RuntimeModule } from 'webpack';\n\nexport class RemoteWebpackRequireRuntimeModule extends RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n}\n","import { type Compiler } from 'webpack';\nimport { RemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(this.appName),\n );\n });\n },\n );\n }\n}\n","import { RuntimeModule } from 'webpack';\n\nexport class ModuleIdEmbedRuntimeModule extends RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n}\n","import type { NormalModule, Compiler } from 'webpack';\nimport { ModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id) {\n moduleMap[normalModule.resource || normalModule.request] =\n id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n moduleMap[normalModule.resource || normalModule.request] = id;\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(this.appName, moduleMap),\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","import { type Compiler, Compilation, sources } from 'webpack';\n\nexport class ConditionalExecPlugin {\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import { type Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new compiler.webpack.sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[a-zA-Z0-9-_]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n throw new Error(\\`Remote component loading error: \"\\${bundle}\"\\`);\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(url, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,QAAAA,OAAM,gBAAgB;AACxC,SAAS,WAAW,qBAAqB;AAEzC;AAAA,EACE;AAAA,EACA;AAAA,OACK;;;ACNP,SAAS,YAAY;;;ACArB,SAAS,qBAAqB;AAEvB,IAAM,oCAAN,cAAgD,cAAc;AAAA,EAGnE,YAAY,SAAiB;AAC3B,UAAM,wBAAwB;AAC9B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,WAA0B;AACxB,WAAO,+HAA+H,KAAK;AAAA,EAC7I;AACF;;;ACVO,IAAM,6BAAN,MAAiC;AAAA,EAGtC,YAAY,SAAiB;AAC3B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAAoB;AACxB,aAAS,MAAM,gBAAgB;AAAA,MAC7B;AAAA,MACA,CAAC,gBAAgB;AACf,oBAAY,MAAM,yBACf,IAAI,qBAAqB,EACzB,IAAI,8BAA8B,CAAC,UAAU;AAC5C,sBAAY;AAAA,YACV;AAAA,YACA,IAAI,kCAAkC,KAAK,OAAO;AAAA,UACpD;AAAA,QACF,CAAC;AAAA,MACL;AAAA,IACF;A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AA,MACX,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,QAAQ,IAAI,sBAAsB;AAChD,QAAM,iBAAiB,qBAAqB,MAAM;AAGlD,QAAM,MAAM,eAAe,OAAO,eAAe,OAAO;AAGxD,SAAO,UAAiB,YAAY,EAAE,KAAK,OAAO,gBAAgB,CAAC;AACrE;","names":["join","RuntimeModule","join"]}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var app_client_exports = {};
21
+ __export(app_client_exports, {
22
+ RemoteComponentClient: () => RemoteComponentClient
23
+ });
24
+ module.exports = __toCommonJS(app_client_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react = require("react");
27
+ var import_react2 = require("react");
28
+ var import_host = require("@remote-component/shared/host");
29
+ var import_remote_component = require("../../shared/client/remote-component");
30
+ function RemoteComponentClient({
31
+ name,
32
+ bundle,
33
+ route = import_remote_component.DEFAULT_ROUTE,
34
+ runtime = import_remote_component.RUNTIME_WEBPACK,
35
+ data,
36
+ nextData,
37
+ scripts = [],
38
+ links = [],
39
+ remoteShared = {},
40
+ children
41
+ }) {
42
+ const [component, setComponent] = (0, import_react2.useState)(null);
43
+ (0, import_react2.useEffect)(() => {
44
+ let mounted = true;
45
+ if (!component) {
46
+ (0, import_remote_component.loadRemoteComponent)({
47
+ name,
48
+ bundle,
49
+ route,
50
+ runtime,
51
+ data,
52
+ nextData,
53
+ scripts,
54
+ shared: import_host.shared,
55
+ remoteShared
56
+ }).then((result) => {
57
+ if (mounted) {
58
+ if (result.error) {
59
+ setComponent(result.error);
60
+ } else {
61
+ setComponent(result.component);
62
+ }
63
+ }
64
+ }).catch((error) => {
65
+ if (mounted) {
66
+ setComponent(error);
67
+ }
68
+ });
69
+ }
70
+ return () => {
71
+ mounted = false;
72
+ };
73
+ }, [
74
+ component,
75
+ name,
76
+ bundle,
77
+ route,
78
+ runtime,
79
+ scripts,
80
+ data,
81
+ nextData,
82
+ remoteShared,
83
+ children,
84
+ links
85
+ ]);
86
+ if (component instanceof Error) {
87
+ throw component;
88
+ }
89
+ const shouldUseChildren = (!component || component && !nextData && typeof component.then !== "function") && // if the remote Next.js Pages Router application is in development mode
90
+ // we don't use the provided static HTML
91
+ // to mitigate layout shift when loading CSS using JavaScript on the client
92
+ nextData?.buildId !== "development";
93
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
94
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
95
+ name,
96
+ bundle,
97
+ route,
98
+ runtime
99
+ }) }),
100
+ shouldUseChildren ? children : component,
101
+ data.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}_rsc`, children: data.join("\n") }) : null,
102
+ nextData ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
103
+ "script",
104
+ {
105
+ id: `${bundle}_${route.replace(/\//g, "_")}${name}_next_data`,
106
+ type: "application/json",
107
+ children: JSON.stringify(nextData)
108
+ }
109
+ ) : null,
110
+ links.map((link) => /* @__PURE__ */ (0, import_react.createElement)(
111
+ "link",
112
+ {
113
+ ...link,
114
+ key: `${link.href}_${link.rel}`,
115
+ precedence: bundle
116
+ }
117
+ ))
118
+ ] });
119
+ }
120
+ // Annotate the CommonJS export names for ESM import in node:
121
+ 0 && (module.exports = {
122
+ RemoteComponentClient
123
+ });
124
+ //# sourceMappingURL=app-client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/host/app-client.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\nimport { shared } from '@remote-component/shared/host';\nimport {\n loadRemoteComponent,\n DEFAULT_ROUTE,\n RUNTIME_WEBPACK,\n} from '../../shared/client/remote-component';\nimport type { RemoteComponentProps } from '../../shared/client/remote-component';\n\n/**\n * RemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function RemoteComponentClient({\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n children,\n}: RemoteComponentProps) {\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n\n useEffect(() => {\n let mounted = true;\n\n // if we have a component, we don't need to load it again\n if (!component) {\n loadRemoteComponent({\n name,\n bundle,\n route,\n runtime,\n data,\n nextData,\n scripts,\n shared,\n remoteShared,\n })\n .then((result) => {\n if (mounted) {\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n })\n .catch((error: Error) => {\n if (mounted) {\n setComponent(error);\n }\n });\n }\n\n return () => {\n mounted = false;\n };\n }, [\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n links,\n ]);\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n return (\n <>\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {shouldUseChildren ? children : (component as React.ReactNode)}\n {data.length > 0 ? (\n <script id={`${name}_rsc`}>{data.join('\\n')}</script>\n ) : null}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(/\\//g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {links.map((link) => (\n <link\n {...link}\n key={`${link.href as string}_${link.rel}`}\n precedence={bundle}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkGI;AAsBI;AAtHR,IAAAA,gBAAoC;AACpC,kBAAuB;AACvB,8BAIO;AASA,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC;AAAA,EAChB;AACF,GAAyB;AACvB,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAkC,IAAI;AAExE,+BAAU,MAAM;AACd,QAAI,UAAU;AAGd,QAAI,CAAC,WAAW;AACd,uDAAoB;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC,EACE,KAAK,CAAC,WAAW;AAChB,YAAI,SAAS;AACX,cAAI,OAAO,OAAO;AAChB,yBAAa,OAAO,KAAK;AAAA,UAC3B,OAAO;AACL,yBAAa,OAAO,SAAS;AAAA,UAC/B;AAAA,QACF;AAAA,MACF,CAAC,EACA,MAAM,CAAC,UAAiB;AACvB,YAAI,SAAS;AACX,uBAAa,KAAK;AAAA,QACpB;AAAA,MACF,CAAC;AAAA,IACL;AAEA,WAAO,MAAM;AACX,gBAAU;AAAA,IACZ;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAGD,MAAI,qBAAqB,OAAO;AAC9B,UAAM;AAAA,EACR;AAGA,QAAM,qBACH,CAAC,aACC,aACC,CAAC,YACD,OAAQ,UAA0C,SAChD;AAAA;AAAA;AAAA,EAIN,UAAU,YAAY;AAExB,SACE,4EACE;AAAA,gDAAC,YAAO,yBAAqB,MAAC,MAAK,oBAChC,eAAK,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,GACH;AAAA,IACC,oBAAoB,WAAY;AAAA,IAChC,KAAK,SAAS,IACb,4CAAC,YAAO,IAAI,GAAG,YAAa,eAAK,KAAK,IAAI,GAAE,IAC1C;AAAA,IACH,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAI,GAAG,UAAU,MAAM,QAAQ,OAAO,GAAG,IAAI;AAAA,QAC7C,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,MAAM,IAAI,CAAC,SACV;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,GAAG,KAAK,QAAkB,KAAK;AAAA,QACpC,YAAY;AAAA;AAAA,IACd,CACD;AAAA,KACH;AAEJ;","names":["import_react"]}
@@ -0,0 +1,33 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { R as RemoteComponentMetadata } from '../../types-280a3640.js';
4
+
5
+ interface RemoteComponentProps {
6
+ name: string;
7
+ bundle: string;
8
+ route?: string;
9
+ runtime?: RemoteComponentMetadata['runtime'];
10
+ data: string[];
11
+ nextData?: {
12
+ props: {
13
+ pageProps: Record<string, unknown>;
14
+ };
15
+ buildId?: string;
16
+ };
17
+ scripts?: {
18
+ src: string;
19
+ }[];
20
+ links?: Record<string, string | boolean>[];
21
+ remoteShared?: Record<string, string>;
22
+ children: react.ReactNode;
23
+ }
24
+
25
+ /**
26
+ * RemoteComponentClient - Main component for rendering remote components
27
+ *
28
+ * This component handles the loading and rendering of remote microfrontends.
29
+ * It supports both RSC (React Server Components) and Next.js Pages Router based components.
30
+ */
31
+ declare function RemoteComponentClient({ name, bundle, route, runtime, data, nextData, scripts, links, remoteShared, children, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
32
+
33
+ export { RemoteComponentClient };
@@ -0,0 +1,104 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { createElement } from "react";
4
+ import { useEffect, useState } from "react";
5
+ import { shared } from "@remote-component/shared/host";
6
+ import {
7
+ loadRemoteComponent,
8
+ DEFAULT_ROUTE,
9
+ RUNTIME_WEBPACK
10
+ } from "../../shared/client/remote-component";
11
+ function RemoteComponentClient({
12
+ name,
13
+ bundle,
14
+ route = DEFAULT_ROUTE,
15
+ runtime = RUNTIME_WEBPACK,
16
+ data,
17
+ nextData,
18
+ scripts = [],
19
+ links = [],
20
+ remoteShared = {},
21
+ children
22
+ }) {
23
+ const [component, setComponent] = useState(null);
24
+ useEffect(() => {
25
+ let mounted = true;
26
+ if (!component) {
27
+ loadRemoteComponent({
28
+ name,
29
+ bundle,
30
+ route,
31
+ runtime,
32
+ data,
33
+ nextData,
34
+ scripts,
35
+ shared,
36
+ remoteShared
37
+ }).then((result) => {
38
+ if (mounted) {
39
+ if (result.error) {
40
+ setComponent(result.error);
41
+ } else {
42
+ setComponent(result.component);
43
+ }
44
+ }
45
+ }).catch((error) => {
46
+ if (mounted) {
47
+ setComponent(error);
48
+ }
49
+ });
50
+ }
51
+ return () => {
52
+ mounted = false;
53
+ };
54
+ }, [
55
+ component,
56
+ name,
57
+ bundle,
58
+ route,
59
+ runtime,
60
+ scripts,
61
+ data,
62
+ nextData,
63
+ remoteShared,
64
+ children,
65
+ links
66
+ ]);
67
+ if (component instanceof Error) {
68
+ throw component;
69
+ }
70
+ const shouldUseChildren = (!component || component && !nextData && typeof component.then !== "function") && // if the remote Next.js Pages Router application is in development mode
71
+ // we don't use the provided static HTML
72
+ // to mitigate layout shift when loading CSS using JavaScript on the client
73
+ nextData?.buildId !== "development";
74
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
75
+ /* @__PURE__ */ jsx("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
76
+ name,
77
+ bundle,
78
+ route,
79
+ runtime
80
+ }) }),
81
+ shouldUseChildren ? children : component,
82
+ data.length > 0 ? /* @__PURE__ */ jsx("script", { id: `${name}_rsc`, children: data.join("\n") }) : null,
83
+ nextData ? /* @__PURE__ */ jsx(
84
+ "script",
85
+ {
86
+ id: `${bundle}_${route.replace(/\//g, "_")}${name}_next_data`,
87
+ type: "application/json",
88
+ children: JSON.stringify(nextData)
89
+ }
90
+ ) : null,
91
+ links.map((link) => /* @__PURE__ */ createElement(
92
+ "link",
93
+ {
94
+ ...link,
95
+ key: `${link.href}_${link.rel}`,
96
+ precedence: bundle
97
+ }
98
+ ))
99
+ ] });
100
+ }
101
+ export {
102
+ RemoteComponentClient
103
+ };
104
+ //# sourceMappingURL=app-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/host/app-client.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\nimport { shared } from '@remote-component/shared/host';\nimport {\n loadRemoteComponent,\n DEFAULT_ROUTE,\n RUNTIME_WEBPACK,\n} from '../../shared/client/remote-component';\nimport type { RemoteComponentProps } from '../../shared/client/remote-component';\n\n/**\n * RemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function RemoteComponentClient({\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n children,\n}: RemoteComponentProps) {\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n\n useEffect(() => {\n let mounted = true;\n\n // if we have a component, we don't need to load it again\n if (!component) {\n loadRemoteComponent({\n name,\n bundle,\n route,\n runtime,\n data,\n nextData,\n scripts,\n shared,\n remoteShared,\n })\n .then((result) => {\n if (mounted) {\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n })\n .catch((error: Error) => {\n if (mounted) {\n setComponent(error);\n }\n });\n }\n\n return () => {\n mounted = false;\n };\n }, [\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n links,\n ]);\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n return (\n <>\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {shouldUseChildren ? children : (component as React.ReactNode)}\n {data.length > 0 ? (\n <script id={`${name}_rsc`}>{data.join('\\n')}</script>\n ) : null}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(/\\//g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {links.map((link) => (\n <link\n {...link}\n key={`${link.href as string}_${link.rel}`}\n precedence={bundle}\n />\n ))}\n </>\n );\n}\n"],"mappings":";AAkGI,mBACE,KADF;AAsBI;AAtHR,SA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