remote-components 0.4.2 → 0.4.3

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 (114) hide show
  1. package/dist/{chunk-KVQI55BZ.cjs → chunk-2W7JBTID.cjs} +37 -36
  2. package/dist/chunk-2W7JBTID.cjs.map +1 -0
  3. package/dist/{chunk-TZT7DLO5.cjs → chunk-3AX5WLZD.cjs} +4 -4
  4. package/dist/{chunk-4O3EOST4.cjs → chunk-4AH3KXDW.cjs} +27 -27
  5. package/dist/{chunk-MTMDXJLM.js → chunk-4NW46ZVD.js} +410 -146
  6. package/dist/chunk-4NW46ZVD.js.map +1 -0
  7. package/dist/{chunk-SAGYPGIQ.js → chunk-55TEMSB5.js} +92 -23
  8. package/dist/chunk-55TEMSB5.js.map +1 -0
  9. package/dist/{chunk-RLI4YTBJ.cjs → chunk-7XXO2DLF.cjs} +96 -27
  10. package/dist/chunk-7XXO2DLF.cjs.map +1 -0
  11. package/dist/{chunk-RUWR74XQ.cjs → chunk-BBXVML3D.cjs} +1 -1
  12. package/dist/{chunk-RUWR74XQ.cjs.map → chunk-BBXVML3D.cjs.map} +1 -1
  13. package/dist/{chunk-42TVDI3G.cjs → chunk-C5EYU7EQ.cjs} +7 -7
  14. package/dist/{chunk-CC3WOSDO.js → chunk-DGZVFKSQ.js} +10 -9
  15. package/dist/chunk-DGZVFKSQ.js.map +1 -0
  16. package/dist/{chunk-AKOMV2UF.js → chunk-HL6BL5HY.js} +3 -3
  17. package/dist/chunk-HMB3SIVJ.cjs +973 -0
  18. package/dist/chunk-HMB3SIVJ.cjs.map +1 -0
  19. package/dist/{chunk-LOYJP2V2.js → chunk-HYVNEUIK.js} +5 -5
  20. package/dist/chunk-KV5J7PNM.js +152 -0
  21. package/dist/chunk-KV5J7PNM.js.map +1 -0
  22. package/dist/{chunk-LQ7VQ74E.js → chunk-LEKG4YWI.js} +2 -2
  23. package/dist/chunk-SECN7UAL.cjs +152 -0
  24. package/dist/chunk-SECN7UAL.cjs.map +1 -0
  25. package/dist/{chunk-S2A4TFLS.js → chunk-ULXU6XWH.js} +1 -1
  26. package/dist/{chunk-S2A4TFLS.js.map → chunk-ULXU6XWH.js.map} +1 -1
  27. package/dist/config/nextjs.cjs +7 -7
  28. package/dist/config/nextjs.js +2 -2
  29. package/dist/host/html.cjs +36 -36
  30. package/dist/host/html.js +10 -10
  31. package/dist/host/nextjs/app/client-only.cjs +17 -17
  32. package/dist/host/nextjs/app/client-only.js +8 -8
  33. package/dist/host/react.cjs +9 -9
  34. package/dist/host/react.js +8 -8
  35. package/dist/internal/config/webpack/next-client-pages-loader.cjs +151 -53
  36. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  37. package/dist/internal/config/webpack/next-client-pages-loader.d.ts +8 -4
  38. package/dist/internal/config/webpack/next-client-pages-loader.js +153 -53
  39. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  40. package/dist/internal/host/shared/pipeline.d.ts +1 -1
  41. package/dist/internal/host/shared/shared-broker.cjs +106 -0
  42. package/dist/internal/host/shared/shared-broker.cjs.map +1 -0
  43. package/dist/internal/host/shared/shared-broker.d.ts +35 -0
  44. package/dist/internal/host/shared/shared-broker.js +80 -0
  45. package/dist/internal/host/shared/shared-broker.js.map +1 -0
  46. package/dist/internal/host/shared/shared-module-resolver.cjs +13 -22
  47. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -1
  48. package/dist/internal/host/shared/shared-module-resolver.d.ts +1 -1
  49. package/dist/internal/host/shared/shared-module-resolver.js +16 -22
  50. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -1
  51. package/dist/internal/runtime/loaders/component-loader.cjs +2 -1
  52. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  53. package/dist/internal/runtime/loaders/component-loader.d.ts +1 -1
  54. package/dist/internal/runtime/loaders/component-loader.js +2 -1
  55. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  56. package/dist/internal/runtime/loaders/static-loader.d.ts +1 -1
  57. package/dist/internal/runtime/namespace.d.ts +1 -1
  58. package/dist/internal/runtime/turbopack/module.cjs +26 -4
  59. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  60. package/dist/internal/runtime/turbopack/module.d.ts +14 -7
  61. package/dist/internal/runtime/turbopack/module.js +27 -5
  62. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  63. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs +5 -4
  64. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -1
  65. package/dist/internal/runtime/turbopack/remote-scope-setup.js +5 -4
  66. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -1
  67. package/dist/internal/runtime/turbopack/shared-modules.cjs +113 -26
  68. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  69. package/dist/internal/runtime/turbopack/shared-modules.d.ts +3 -1
  70. package/dist/internal/runtime/turbopack/shared-modules.js +116 -26
  71. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  72. package/dist/internal/runtime/types.cjs.map +1 -1
  73. package/dist/internal/runtime/types.d.ts +1 -1
  74. package/dist/internal/utils/logger.cjs.map +1 -1
  75. package/dist/internal/utils/logger.d.ts +1 -1
  76. package/dist/internal/utils/logger.js.map +1 -1
  77. package/dist/remote/html.cjs +6 -6
  78. package/dist/remote/html.js +2 -2
  79. package/dist/{script-VPOI7ARP.js → script-ISAHSV3X.js} +3 -3
  80. package/dist/{script-D5AD7HLV.cjs → script-YQCDUYDP.cjs} +4 -4
  81. package/dist/static-loader-EOJQHFZ6.cjs +11 -0
  82. package/dist/{static-loader-OHSAUD62.js → static-loader-Z24427MK.js} +3 -3
  83. package/dist/{turbopack-5N44NVPT.js → turbopack-7F757Z7V.js} +6 -6
  84. package/dist/{turbopack-EPXGK4EV.cjs → turbopack-DULMVTWV.cjs} +12 -12
  85. package/dist/{types-8b0edd78.d.ts → types-bd7be268.d.ts} +1 -5
  86. package/dist/{webpack-SIFRCBIN.cjs → webpack-6LXCB7WA.cjs} +14 -14
  87. package/dist/{webpack-KSDNIXMS.js → webpack-WGVTKJ3W.js} +5 -5
  88. package/package.json +1 -1
  89. package/dist/chunk-CC3WOSDO.js.map +0 -1
  90. package/dist/chunk-JJTCFQHE.cjs +0 -202
  91. package/dist/chunk-JJTCFQHE.cjs.map +0 -1
  92. package/dist/chunk-KVQI55BZ.cjs.map +0 -1
  93. package/dist/chunk-MKO52FRO.js +0 -202
  94. package/dist/chunk-MKO52FRO.js.map +0 -1
  95. package/dist/chunk-MQ2BBSL4.cjs +0 -709
  96. package/dist/chunk-MQ2BBSL4.cjs.map +0 -1
  97. package/dist/chunk-MTMDXJLM.js.map +0 -1
  98. package/dist/chunk-RLI4YTBJ.cjs.map +0 -1
  99. package/dist/chunk-SAGYPGIQ.js.map +0 -1
  100. package/dist/static-loader-UDIXK5MV.cjs +0 -11
  101. /package/dist/{chunk-TZT7DLO5.cjs.map → chunk-3AX5WLZD.cjs.map} +0 -0
  102. /package/dist/{chunk-4O3EOST4.cjs.map → chunk-4AH3KXDW.cjs.map} +0 -0
  103. /package/dist/{chunk-42TVDI3G.cjs.map → chunk-C5EYU7EQ.cjs.map} +0 -0
  104. /package/dist/{chunk-AKOMV2UF.js.map → chunk-HL6BL5HY.js.map} +0 -0
  105. /package/dist/{chunk-LOYJP2V2.js.map → chunk-HYVNEUIK.js.map} +0 -0
  106. /package/dist/{chunk-LQ7VQ74E.js.map → chunk-LEKG4YWI.js.map} +0 -0
  107. /package/dist/{script-VPOI7ARP.js.map → script-ISAHSV3X.js.map} +0 -0
  108. /package/dist/{script-D5AD7HLV.cjs.map → script-YQCDUYDP.cjs.map} +0 -0
  109. /package/dist/{static-loader-UDIXK5MV.cjs.map → static-loader-EOJQHFZ6.cjs.map} +0 -0
  110. /package/dist/{static-loader-OHSAUD62.js.map → static-loader-Z24427MK.js.map} +0 -0
  111. /package/dist/{turbopack-5N44NVPT.js.map → turbopack-7F757Z7V.js.map} +0 -0
  112. /package/dist/{turbopack-EPXGK4EV.cjs.map → turbopack-DULMVTWV.cjs.map} +0 -0
  113. /package/dist/{webpack-SIFRCBIN.cjs.map → webpack-6LXCB7WA.cjs.map} +0 -0
  114. /package/dist/{webpack-KSDNIXMS.js.map → webpack-WGVTKJ3W.js.map} +0 -0
@@ -22,12 +22,18 @@ __export(next_client_pages_loader_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(next_client_pages_loader_exports);
24
24
  var import_namespace = require("#internal/runtime/namespace");
25
+ var import_module = require("#internal/runtime/turbopack/module");
26
+ var import_remote_scope = require("#internal/runtime/turbopack/remote-scope");
27
+ var import_shared_modules = require("#internal/runtime/turbopack/shared-modules");
25
28
  var import_error = require("#internal/utils/error");
29
+ var import_logger = require("#internal/utils/logger");
26
30
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
27
31
  const self = globalThis;
28
32
  const ns = (0, import_namespace.getNamespace)();
29
33
  ns.pageComponentCache ??= {};
30
34
  const cacheKey = `${bundle}:${route}`;
35
+ const remoteRequire = self.__remote_webpack_require__?.[bundle];
36
+ const turbopackScope = remoteRequire?.type === "turbopack" ? (0, import_remote_scope.getScope)(bundle) : void 0;
31
37
  const applyBundleCss = () => {
32
38
  const elements = ns.cssCache[bundle] ?? [];
33
39
  if (styleContainer) {
@@ -48,8 +54,10 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
48
54
  const nextCssOriginal = document.querySelector(
49
55
  `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
50
56
  );
57
+ const nextCssOriginalParent = nextCssOriginal?.parentNode ?? null;
58
+ const nextCssOriginalNextSibling = nextCssOriginal?.nextSibling ?? null;
51
59
  if (nextCssOriginal) {
52
- nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
60
+ nextCssOriginalParent?.removeChild(nextCssOriginal);
53
61
  }
54
62
  const nextCss = document.createElement("noscript");
55
63
  nextCss.id = "__next_css__DO_NOT_USE__";
@@ -61,25 +69,25 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
61
69
  nextCssEnd.setAttribute("data-route", route);
62
70
  document.head.appendChild(nextCssEnd);
63
71
  document.head.appendChild(nextCss);
64
- const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
72
+ const componentLoaderChunk = (turbopackScope ? findTurbopackPagesLoaderId(turbopackScope, route) : void 0) ?? Object.keys(remoteRequire?.m ?? {}).find(
65
73
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
66
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
74
+ ) ?? Object.keys(remoteRequire?.m ?? {}).find(
67
75
  (key) => key.includes("/next/dist/client/page-loader.js")
68
76
  ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
69
77
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
70
78
  ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
71
79
  (key) => key.includes("/next/dist/client/page-loader.js")
72
80
  ) ?? ""] ?? -1;
73
- const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
81
+ const appLoaderChunk = (turbopackScope ? findTurbopackPagesLoaderId(turbopackScope, "/_app") : void 0) ?? Object.keys(remoteRequire?.m ?? {}).find(
74
82
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
75
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
83
+ ) ?? Object.keys(remoteRequire?.m ?? {}).find(
76
84
  (key) => key.includes("/next/dist/client/page-loader.js")
77
85
  ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
78
86
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
79
87
  ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
80
88
  (key) => key.includes("/next/dist/client/page-loader.js")
81
89
  ) ?? ""] ?? -1;
82
- if (!(componentLoaderChunk && appLoaderChunk)) {
90
+ if (!isLoaderId(componentLoaderChunk) || !isLoaderId(appLoaderChunk)) {
83
91
  throw new import_error.RemoteComponentsError(
84
92
  `Next.js client pages loader not found in bundle "${bundle}".`
85
93
  );
@@ -87,61 +95,151 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
87
95
  const __NEXT_P_ORIGINAL = self.__NEXT_P;
88
96
  const selfOriginal = self;
89
97
  delete selfOriginal.__NEXT_P;
90
- self.__remote_webpack_require__?.[bundle]?.(
91
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? componentLoaderChunk : `[${bundle}] ${componentLoaderChunk}`
92
- );
93
- if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
94
- self.__remote_webpack_require__?.[bundle]?.(
95
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? appLoaderChunk : `[${bundle}] ${appLoaderChunk}`
96
- );
97
- }
98
- if (self.__NEXT_P) {
99
- const [, componentLoader] = self.__NEXT_P[0] ?? [
100
- void 0,
101
- () => ({ default: null })
102
- ];
103
- const [, appLoader] = self.__NEXT_P[2] ?? [
104
- void 0,
105
- () => ({
106
- default: null
107
- })
108
- ];
109
- const { default: Component = null } = componentLoader();
110
- const { default: App = null } = appLoader();
111
- const cssCache = ns.cssCache;
112
- if (!cssCache[bundle]) {
113
- const cssRE = /\.s?css$/;
114
- Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
115
- self.__remote_webpack_require__?.[bundle]?.(id);
116
- });
117
- Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
118
- const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
119
- if (id) {
98
+ try {
99
+ loadPagesLoaderModule(bundle, componentLoaderChunk, turbopackScope);
100
+ if (isLoaderId(appLoaderChunk)) {
101
+ loadPagesLoaderModule(bundle, appLoaderChunk, turbopackScope);
102
+ }
103
+ if (self.__NEXT_P) {
104
+ (0, import_logger.logDebug)(
105
+ "ComponentLoader",
106
+ `Next.js Pages loader registry for "${route}" in "${bundle}": ${self.__NEXT_P.map((entry) => entry?.[0] ?? "<empty>").join(", ")}`
107
+ );
108
+ const componentEntry = self.__NEXT_P.find(
109
+ (entry) => entry?.[0] === route
110
+ ) ?? self.__NEXT_P[0];
111
+ const appEntry = self.__NEXT_P.find((entry) => entry?.[0] === "/_app") ?? self.__NEXT_P[2];
112
+ const [, componentLoader] = componentEntry ?? [
113
+ void 0,
114
+ () => ({ default: null })
115
+ ];
116
+ const [, appLoader] = appEntry ?? [
117
+ void 0,
118
+ () => ({
119
+ default: null
120
+ })
121
+ ];
122
+ const { default: Component = null } = componentLoader();
123
+ const { default: App = null } = appLoader();
124
+ const cssCache = ns.cssCache;
125
+ if (!cssCache[bundle]) {
126
+ const cssRE = /\.s?css$/;
127
+ Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
120
128
  self.__remote_webpack_require__?.[bundle]?.(id);
129
+ });
130
+ Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
131
+ const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
132
+ if (id) {
133
+ self.__remote_webpack_require__?.[bundle]?.(id);
134
+ }
135
+ });
136
+ const elements = [];
137
+ let node = nextCss.previousSibling;
138
+ while (node && node !== nextCssEnd) {
139
+ elements.push(node);
140
+ node.remove();
141
+ node = nextCss.previousSibling;
121
142
  }
122
- });
123
- const elements = [];
124
- let node = nextCss.previousSibling;
125
- while (node && node !== nextCssEnd) {
126
- elements.push(node);
127
- node.remove();
128
- node = nextCss.previousSibling;
143
+ cssCache[bundle] = elements;
129
144
  }
130
- cssCache[bundle] = elements;
145
+ applyBundleCss();
146
+ const result = { Component, App };
147
+ ns.pageComponentCache[cacheKey] = result;
148
+ return result;
131
149
  }
132
- applyBundleCss();
133
- delete self.__NEXT_P;
134
- self.__NEXT_P = __NEXT_P_ORIGINAL;
135
- if (nextCssOriginal) {
136
- nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
150
+ (0, import_logger.logDebug)(
151
+ "ComponentLoader",
152
+ `Next.js Pages loaders for route "${route}" in "${bundle}" did not populate __NEXT_P`
153
+ );
154
+ return { Component: null, App: null };
155
+ } finally {
156
+ if (typeof __NEXT_P_ORIGINAL === "undefined") {
157
+ delete self.__NEXT_P;
158
+ } else {
159
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
160
+ }
161
+ if (nextCssOriginal && nextCssOriginalParent) {
162
+ const restoreBefore = nextCssOriginalNextSibling?.parentNode === nextCssOriginalParent ? nextCssOriginalNextSibling : null;
163
+ nextCssOriginalParent.insertBefore(nextCssOriginal, restoreBefore);
137
164
  }
138
165
  nextCss.remove();
139
166
  nextCssEnd.remove();
140
- const result = { Component, App };
141
- ns.pageComponentCache[cacheKey] = result;
142
- return result;
143
167
  }
144
- return { Component: null, App: null };
168
+ }
169
+ function isLoaderId(id) {
170
+ return typeof id === "string" && id.length > 0 || typeof id === "number" && id !== -1;
171
+ }
172
+ function loadPagesLoaderModule(bundle, id, turbopackScope) {
173
+ const self = globalThis;
174
+ if (turbopackScope) {
175
+ delete turbopackScope.moduleCache[String(id)];
176
+ (0, import_module.requireModule)(turbopackScope, id);
177
+ return;
178
+ }
179
+ const remoteRequire = self.__remote_webpack_require__?.[bundle];
180
+ if (remoteRequire?.c) {
181
+ delete remoteRequire.c[id];
182
+ }
183
+ remoteRequire?.(id);
184
+ }
185
+ function findTurbopackPagesLoaderId(scope, route) {
186
+ const modules = (0, import_shared_modules.getTurbopackModules)(scope);
187
+ if (!modules)
188
+ return void 0;
189
+ const routeLiteral = JSON.stringify(route);
190
+ const singleQuotedRouteLiteral = `'${route.replaceAll("'", "\\'")}'`;
191
+ const flat = modules.flat();
192
+ for (let index = 0; index < flat.length; index++) {
193
+ const entry = flat[index];
194
+ if (typeof entry === "function") {
195
+ const code = entry.toString();
196
+ if (code.includes("__NEXT_P") && (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral))) {
197
+ const id = findPreviousModuleId(flat, index);
198
+ if (isLoaderId(id) && isTurbopackPagesLoaderId(id)) {
199
+ (0, import_logger.logDebug)(
200
+ "SharedModules",
201
+ `Resolved Turbopack Pages loader for route "${route}" in "${scope.scopedName}" as "${id}"`
202
+ );
203
+ return id;
204
+ }
205
+ }
206
+ continue;
207
+ }
208
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
209
+ continue;
210
+ if (typeof Element !== "undefined" && entry instanceof Element)
211
+ continue;
212
+ for (const [id, moduleInit] of Object.entries(
213
+ entry
214
+ )) {
215
+ if (typeof moduleInit !== "function")
216
+ continue;
217
+ const code = moduleInit.toString();
218
+ if (code.includes("__NEXT_P") && (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral)) && isTurbopackPagesLoaderId(id)) {
219
+ (0, import_logger.logDebug)(
220
+ "SharedModules",
221
+ `Resolved Turbopack Pages loader for route "${route}" in "${scope.scopedName}" as "${id}"`
222
+ );
223
+ return id;
224
+ }
225
+ }
226
+ }
227
+ return void 0;
228
+ }
229
+ function isTurbopackPagesLoaderId(id) {
230
+ if (typeof id === "number")
231
+ return true;
232
+ return id.includes("[next]/entry/page-loader.ts") || id.includes("/next/dist/client/page-loader.js");
233
+ }
234
+ function findPreviousModuleId(entries, factoryIndex) {
235
+ for (let index = factoryIndex - 1; index >= 0; index--) {
236
+ const entry = entries[index];
237
+ if (isLoaderId(entry))
238
+ return entry;
239
+ if (typeof entry === "function")
240
+ return void 0;
241
+ }
242
+ return void 0;
145
243
  }
146
244
  // Annotate the CommonJS export names for ESM import in node:
147
245
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/config/webpack/next-client-pages-loader.ts"],"sourcesContent":["import { getNamespace } from '#internal/runtime/namespace';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// module loader for Next.js Pages Router\nexport function nextClientPagesLoader(\n bundle: string,\n route: string,\n styleContainer: HTMLHeadElement | ShadowRoot | null = document.head,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\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';\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // Next.js client pages loader reference storage\n __NEXT_P?: [\n (\n | [\n string,\n () => { default?: React.ComponentType<Record<string, unknown>> },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n ];\n };\n\n const ns = getNamespace();\n ns.pageComponentCache ??= {};\n const cacheKey = `${bundle}:${route}`;\n\n // Applies the cached CSS for `bundle` into the caller's styleContainer.\n // Mirrors the final CSS-attach step of the fresh-load path so that cache\n // hits and additional host instances (each with their own shadow root)\n // still receive the styles.\n const applyBundleCss = () => {\n const elements = ns.cssCache[bundle] ?? [];\n if (styleContainer) {\n for (const el of elements) {\n styleContainer.appendChild(el.cloneNode(true));\n }\n } else {\n for (const el of elements) {\n document.head.appendChild(el);\n }\n }\n };\n\n // On repeat loads (e.g. after history.back()) the next-client-pages-loader\n // chunk is already cached by webpack and its factory won't re-run, so\n // __NEXT_P wouldn't be populated. Reuse the Component/App extracted on the\n // first load, but still run the CSS attach below because the caller may be\n // a different host instance with its own styleContainer.\n const cachedEntry = ns.pageComponentCache[cacheKey];\n if (cachedEntry) {\n applyBundleCss();\n return cachedEntry;\n }\n\n // temporarily remove the original Next.js CSS loader\n const nextCssOriginal = document.querySelector(\n `[id=\"__next_css__DO_NOT_USE__\"]:not([data-bundle=\"${bundle}\"][data-route=\"${route}\"])`,\n );\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.removeChild(nextCssOriginal);\n }\n\n // create a new Next.js CSS loader element\n const nextCss = document.createElement('noscript');\n nextCss.id = '__next_css__DO_NOT_USE__';\n nextCss.setAttribute('data-bundle', bundle);\n nextCss.setAttribute('data-route', route);\n const nextCssEnd = document.createElement('noscript');\n nextCssEnd.id = '__next_css__DO_NOT_USE_END__';\n nextCssEnd.setAttribute('data-bundle', bundle);\n nextCssEnd.setAttribute('data-route', route);\n document.head.appendChild(nextCssEnd);\n document.head.appendChild(nextCss);\n\n // find the page component loader chunk\n const componentLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // find the app loader chunk\n const appLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // if we didn't find the component loader or app loader, throw an error\n if (!(componentLoaderChunk && appLoaderChunk)) {\n throw new RemoteComponentsError(\n `Next.js client pages loader not found in bundle \"${bundle}\".`,\n );\n }\n\n // temporarily store the original __NEXT_P reference\n // this is required to avoid conflicts with the Next.js client pages loader\n // which uses the same global variable to store the page components\n const __NEXT_P_ORIGINAL = self.__NEXT_P;\n const selfOriginal = self;\n delete selfOriginal.__NEXT_P;\n\n // load the component and app loader chunks\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? componentLoaderChunk\n : `[${bundle}] ${componentLoaderChunk}`,\n );\n if (\n typeof appLoaderChunk === 'string' ||\n (typeof appLoaderChunk === 'number' && appLoaderChunk !== -1)\n ) {\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? appLoaderChunk\n : `[${bundle}] ${appLoaderChunk}`,\n );\n }\n\n // if we have the __NEXT_P global variable, we can extract the component and app\n if (self.__NEXT_P) {\n const [, componentLoader] = self.__NEXT_P[0] ?? [\n undefined,\n () => ({ default: null }),\n ];\n const [, appLoader] = self.__NEXT_P[2] ?? [\n undefined,\n () => ({\n default: null,\n }),\n ];\n const { default: Component = null } = componentLoader();\n const { default: App = null } = appLoader();\n\n const cssCache = ns.cssCache;\n\n if (!cssCache[bundle]) {\n // load the CSS files from the remote bundle\n const cssRE = /\\.s?css$/;\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {})\n .filter((id) => cssRE.test(id))\n .forEach((id) => {\n self.__remote_webpack_require__?.[bundle]?.(id);\n });\n\n Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {})\n .filter((path) => cssRE.test(path))\n .forEach((path) => {\n const id = self.__remote_webpack_module_map__?.[bundle]?.[path];\n if (id) {\n self.__remote_webpack_require__?.[bundle]?.(id);\n }\n });\n\n const elements = [];\n let node = nextCss.previousSibling;\n while (node && node !== nextCssEnd) {\n elements.push(node);\n node.remove();\n node = nextCss.previousSibling;\n }\n cssCache[bundle] = elements;\n }\n\n applyBundleCss();\n\n // restore the original __NEXT_P reference\n delete self.__NEXT_P;\n self.__NEXT_P = __NEXT_P_ORIGINAL;\n\n // restore the original Next.js CSS loader\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.appendChild(nextCssOriginal);\n }\n\n nextCss.remove();\n nextCssEnd.remove();\n\n const result = { Component, App };\n ns.pageComponentCache[cacheKey] = result;\n return result;\n }\n\n return { Component: null, App: null };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA6B;AAC7B,mBAAsC;AAG/B,SAAS,sBACd,QACA,OACA,iBAAsD,SAAS,MAC/D;AAEA,QAAM,OAAO;AAqDb,QAAM,SAAK,+BAAa;AACxB,KAAG,uBAAuB,CAAC;AAC3B,QAAM,WAAW,GAAG,UAAU;AAM9B,QAAM,iBAAiB,MAAM;AAC3B,UAAM,WAAW,GAAG,SAAS,MAAM,KAAK,CAAC;AACzC,QAAI,gBAAgB;AAClB,iBAAW,MAAM,UAAU;AACzB,uBAAe,YAAY,GAAG,UAAU,IAAI,CAAC;AAAA,MAC/C;AAAA,IACF,OAAO;AACL,iBAAW,MAAM,UAAU;AACzB,iBAAS,KAAK,YAAY,EAAE;AAAA,MAC9B;AAAA,IACF;AAAA,EACF;AAOA,QAAM,c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AAA,IACF;AACA,UAAM,EAAE,SAAS,YAAY,KAAK,IAAI,gBAAgB;AACtD,UAAM,EAAE,SAAS,MAAM,KAAK,IAAI,UAAU;AAE1C,UAAM,WAAW,GAAG;AAEpB,QAAI,CAAC,SAAS,MAAM,GAAG;AAErB,YAAM,QAAQ;AACd,aAAO,KAAK,KAAK,6BAA6B,MAAM,GAAG,KAAK,CAAC,CAAC,EAC3D,OAAO,CAAC,OAAO,MAAM,KAAK,EAAE,CAAC,EAC7B,QAAQ,CAAC,OAAO;AACf,aAAK,6BAA6B,MAAM,IAAI,EAAE;AAAA,MAChD,CAAC;AAEH,aAAO,KAAK,KAAK,gCAAgC,MAAM,KAAK,CAAC,CAAC,EAC3D,OAAO,CAAC,SAAS,MAAM,KAAK,IAAI,CAAC,EACjC,QAAQ,CAAC,SAAS;AACjB,cAAM,KAAK,KAAK,gCAAgC,MAAM,IAAI,IAAI;AAC9D,YAAI,IAAI;AACN,eAAK,6BAA6B,MAAM,IAAI,EAAE;AAAA,QAChD;AAAA,MACF,CAAC;AAEH,YAAM,WAAW,CAAC;AAClB,UAAI,OAAO,QAAQ;AACnB,aAAO,QAAQ,SAAS,YAAY;AAClC,iBAAS,KAAK,IAAI;AAClB,aAAK,OAAO;AACZ,eAAO,QAAQ;AAAA,MACjB;AACA,eAAS,MAAM,IAAI;AAAA,IACrB;AAEA,mBAAe;AAGf,WAAO,KAAK;AACZ,SAAK,WAAW;AAGhB,QAAI,iBAAiB;AACnB,sBAAgB,YAAY,YAAY,eAAe;AAAA,IACzD;AAEA,YAAQ,OAAO;AACf,eAAW,OAAO;AAElB,UAAM,SAAS,EAAE,WAAW,IAAI;AAChC,OAAG,mBAAmB,QAAQ,IAAI;AAClC,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,WAAW,MAAM,KAAK,KAAK;AACtC;","names":[]}
1
+ {"version":3,"sources":["../../../../src/config/webpack/next-client-pages-loader.ts"],"sourcesContent":["import type React from 'react';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { requireModule } from '#internal/runtime/turbopack/module';\nimport {\n getScope,\n type RemoteScope,\n} from '#internal/runtime/turbopack/remote-scope';\nimport { getTurbopackModules } from '#internal/runtime/turbopack/shared-modules';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug } from '#internal/utils/logger';\n\ntype PageComponent = React.ComponentType<Record<string, unknown>>;\ntype AppComponent = React.ComponentType<\n { Component: PageComponent } & Record<string, unknown>\n>;\ntype NextPageEntry = [string, () => { default?: PageComponent }];\ntype NextAppEntry = [string, () => { default?: AppComponent }];\n\n// module loader for Next.js Pages Router\nexport function nextClientPagesLoader(\n bundle: string,\n route: string,\n styleContainer: HTMLHeadElement | ShadowRoot | null = document.head,\n): { Component: PageComponent | null; App: AppComponent | null } {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\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';\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // Next.js client pages loader reference storage\n __NEXT_P?: [\n (\n | [\n string,\n () => { default?: React.ComponentType<Record<string, unknown>> },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n ];\n };\n\n const ns = getNamespace();\n ns.pageComponentCache ??= {};\n const cacheKey = `${bundle}:${route}`;\n const remoteRequire = self.__remote_webpack_require__?.[bundle];\n const turbopackScope =\n remoteRequire?.type === 'turbopack' ? getScope(bundle) : undefined;\n\n // Applies the cached CSS for `bundle` into the caller's styleContainer.\n // Mirrors the final CSS-attach step of the fresh-load path so that cache\n // hits and additional host instances (each with their own shadow root)\n // still receive the styles.\n const applyBundleCss = () => {\n const elements = ns.cssCache[bundle] ?? [];\n if (styleContainer) {\n for (const el of elements) {\n styleContainer.appendChild(el.cloneNode(true));\n }\n } else {\n for (const el of elements) {\n document.head.appendChild(el);\n }\n }\n };\n\n // On repeat loads (e.g. after history.back()) the next-client-pages-loader\n // chunk is already cached by webpack and its factory won't re-run, so\n // __NEXT_P wouldn't be populated. Reuse the Component/App extracted on the\n // first load, but still run the CSS attach below because the caller may be\n // a different host instance with its own styleContainer.\n const cachedEntry = ns.pageComponentCache[cacheKey];\n if (cachedEntry) {\n applyBundleCss();\n return cachedEntry;\n }\n\n // temporarily remove the original Next.js CSS loader\n const nextCssOriginal = document.querySelector(\n `[id=\"__next_css__DO_NOT_USE__\"]:not([data-bundle=\"${bundle}\"][data-route=\"${route}\"])`,\n );\n const nextCssOriginalParent = nextCssOriginal?.parentNode ?? null;\n const nextCssOriginalNextSibling = nextCssOriginal?.nextSibling ?? null;\n if (nextCssOriginal) {\n nextCssOriginalParent?.removeChild(nextCssOriginal);\n }\n\n // create a new Next.js CSS loader element\n const nextCss = document.createElement('noscript');\n nextCss.id = '__next_css__DO_NOT_USE__';\n nextCss.setAttribute('data-bundle', bundle);\n nextCss.setAttribute('data-route', route);\n const nextCssEnd = document.createElement('noscript');\n nextCssEnd.id = '__next_css__DO_NOT_USE_END__';\n nextCssEnd.setAttribute('data-bundle', bundle);\n nextCssEnd.setAttribute('data-route', route);\n document.head.appendChild(nextCssEnd);\n document.head.appendChild(nextCss);\n\n // find the page component loader chunk\n const componentLoaderChunk =\n (turbopackScope\n ? findTurbopackPagesLoaderId(turbopackScope, route)\n : undefined) ??\n Object.keys(remoteRequire?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(remoteRequire?.m ?? {}).find((key) =>\n key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // find the app loader chunk\n const appLoaderChunk =\n (turbopackScope\n ? findTurbopackPagesLoaderId(turbopackScope, '/_app')\n : undefined) ??\n Object.keys(remoteRequire?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(remoteRequire?.m ?? {}).find((key) =>\n key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // if we didn't find the component loader or app loader, throw an error\n if (!isLoaderId(componentLoaderChunk) || !isLoaderId(appLoaderChunk)) {\n throw new RemoteComponentsError(\n `Next.js client pages loader not found in bundle \"${bundle}\".`,\n );\n }\n\n // temporarily store the original __NEXT_P reference\n // this is required to avoid conflicts with the Next.js client pages loader\n // which uses the same global variable to store the page components\n const __NEXT_P_ORIGINAL = self.__NEXT_P;\n const selfOriginal = self;\n delete selfOriginal.__NEXT_P;\n\n try {\n // load the component and app loader chunks\n loadPagesLoaderModule(bundle, componentLoaderChunk, turbopackScope);\n if (isLoaderId(appLoaderChunk)) {\n loadPagesLoaderModule(bundle, appLoaderChunk, turbopackScope);\n }\n\n // if we have the __NEXT_P global variable, we can extract the component and app\n if (self.__NEXT_P) {\n logDebug(\n 'ComponentLoader',\n `Next.js Pages loader registry for \"${route}\" in \"${bundle}\": ${self.__NEXT_P.map((entry) => entry?.[0] ?? '<empty>').join(', ')}`,\n );\n const componentEntry = (self.__NEXT_P.find(\n (entry) => entry?.[0] === route,\n ) ?? self.__NEXT_P[0]) as NextPageEntry | undefined;\n const appEntry = (self.__NEXT_P.find((entry) => entry?.[0] === '/_app') ??\n self.__NEXT_P[2]) as NextAppEntry | undefined;\n const [, componentLoader] = componentEntry ?? [\n undefined,\n () => ({ default: null }),\n ];\n const [, appLoader] = appEntry ?? [\n undefined,\n () => ({\n default: null,\n }),\n ];\n const { default: Component = null } = componentLoader();\n const { default: App = null } = appLoader();\n\n const cssCache = ns.cssCache;\n\n if (!cssCache[bundle]) {\n // load the CSS files from the remote bundle\n const cssRE = /\\.s?css$/;\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {})\n .filter((id) => cssRE.test(id))\n .forEach((id) => {\n self.__remote_webpack_require__?.[bundle]?.(id);\n });\n\n Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {})\n .filter((path) => cssRE.test(path))\n .forEach((path) => {\n const id = self.__remote_webpack_module_map__?.[bundle]?.[path];\n if (id) {\n self.__remote_webpack_require__?.[bundle]?.(id);\n }\n });\n\n const elements = [];\n let node = nextCss.previousSibling;\n while (node && node !== nextCssEnd) {\n elements.push(node);\n node.remove();\n node = nextCss.previousSibling;\n }\n cssCache[bundle] = elements;\n }\n\n applyBundleCss();\n\n const result = { Component, App };\n ns.pageComponentCache[cacheKey] = result;\n return result;\n }\n\n logDebug(\n 'ComponentLoader',\n `Next.js Pages loaders for route \"${route}\" in \"${bundle}\" did not populate __NEXT_P`,\n );\n return { Component: null, App: null };\n } finally {\n // restore the original __NEXT_P reference\n if (typeof __NEXT_P_ORIGINAL === 'undefined') {\n delete self.__NEXT_P;\n } else {\n self.__NEXT_P = __NEXT_P_ORIGINAL;\n }\n // restore the original Next.js CSS loader\n if (nextCssOriginal && nextCssOriginalParent) {\n const restoreBefore =\n nextCssOriginalNextSibling?.parentNode === nextCssOriginalParent\n ? nextCssOriginalNextSibling\n : null;\n nextCssOriginalParent.insertBefore(nextCssOriginal, restoreBefore);\n }\n\n nextCss.remove();\n nextCssEnd.remove();\n }\n}\n\ntype LoaderId = string | number;\n\nfunction isLoaderId(id: unknown): id is LoaderId {\n return (\n (typeof id === 'string' && id.length > 0) ||\n (typeof id === 'number' && id !== -1)\n );\n}\n\nfunction loadPagesLoaderModule(\n bundle: string,\n id: LoaderId,\n turbopackScope: RemoteScope | undefined,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string | number) => unknown) & {\n c?: Record<string | number, unknown>;\n type?: 'turbopack' | 'webpack';\n }\n >;\n };\n\n if (turbopackScope) {\n delete turbopackScope.moduleCache[String(id)];\n requireModule(turbopackScope, id);\n return;\n }\n\n const remoteRequire = self.__remote_webpack_require__?.[bundle];\n if (remoteRequire?.c) {\n delete remoteRequire.c[id];\n }\n remoteRequire?.(id);\n}\n\nfunction findTurbopackPagesLoaderId(\n scope: RemoteScope,\n route: string,\n): LoaderId | undefined {\n const modules = getTurbopackModules(scope);\n if (!modules) return undefined;\n\n const routeLiteral = JSON.stringify(route);\n const singleQuotedRouteLiteral = `'${route.replaceAll(\"'\", \"\\\\'\")}'`;\n const flat = modules.flat();\n\n for (let index = 0; index < flat.length; index++) {\n const entry = flat[index];\n\n if (typeof entry === 'function') {\n const code = entry.toString();\n if (\n code.includes('__NEXT_P') &&\n (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral))\n ) {\n const id = findPreviousModuleId(flat, index);\n if (isLoaderId(id) && isTurbopackPagesLoaderId(id)) {\n logDebug(\n 'SharedModules',\n `Resolved Turbopack Pages loader for route \"${route}\" in \"${scope.scopedName}\" as \"${id}\"`,\n );\n return id;\n }\n }\n continue;\n }\n\n if (!entry || typeof entry !== 'object' || Array.isArray(entry)) continue;\n if (typeof Element !== 'undefined' && entry instanceof Element) continue;\n\n for (const [id, moduleInit] of Object.entries(\n entry as Record<string, unknown>,\n )) {\n if (typeof moduleInit !== 'function') continue;\n const code = moduleInit.toString();\n if (\n code.includes('__NEXT_P') &&\n (code.includes(routeLiteral) ||\n code.includes(singleQuotedRouteLiteral)) &&\n isTurbopackPagesLoaderId(id)\n ) {\n logDebug(\n 'SharedModules',\n `Resolved Turbopack Pages loader for route \"${route}\" in \"${scope.scopedName}\" as \"${id}\"`,\n );\n return id;\n }\n }\n }\n\n return undefined;\n}\n\nfunction isTurbopackPagesLoaderId(id: LoaderId): boolean {\n if (typeof id === 'number') return true;\n return (\n id.includes('[next]/entry/page-loader.ts') ||\n id.includes('/next/dist/client/page-loader.js')\n );\n}\n\nfunction findPreviousModuleId(\n entries: unknown[],\n factoryIndex: number,\n): LoaderId | undefined {\n for (let index = factoryIndex - 1; index >= 0; index--) {\n const entry = entries[index];\n if (isLoaderId(entry)) return entry;\n if (typeof entry === 'function') return undefined;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA6B;AAC7B,oBAA8B;AAC9B,0BAGO;AACP,4BAAoC;AACpC,mBAAsC;AACtC,oBAAyB;AAUlB,SAAS,sBACd,QACA,OACA,iBAAsD,SAAS,MACA;AAE/D,QAAM,OAAO;AAqDb,QAAM,SAAK,+BAAa;AACxB,KAAG,uBAAuB,CAAC;AAC3B,QAAM,WAAW,GAAG,UAAU;AAC9B,QAAM,gBAAgB,KAAK,6BAA6B,MAAM;AAC9D,QAAM,iBACJ,eAAe,SAAS,kBAAc,8BAAS,MAAM,IAAI;AAM3D,QAAM,iBAAiB,MAAM;AAC3B,UAAM,WAAW,GAAG,SAAS,MAAM,KAAK,CAAC;AACzC,QAAI,gBAAgB;AAClB,iBAAW,MAAM,UAAU;AACz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AAM,OAAO,MAAM,SAAS;AAC5B,UACE,KAAK,SAAS,UAAU,MACvB,KAAK,SAAS,YAAY,KAAK,KAAK,SAAS,wBAAwB,IACtE;AACA,cAAM,KAAK,qBAAqB,MAAM,KAAK;AAC3C,YAAI,WAAW,EAAE,KAAK,yBAAyB,EAAE,GAAG;AAClD;AAAA,YACE;AAAA,YACA,8CAA8C,cAAc,MAAM,mBAAmB;AAAA,UACvF;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA;AAAA,IACF;AAEA,QAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK;AAAG;AACjE,QAAI,OAAO,YAAY,eAAe,iBAAiB;AAAS;AAEhE,eAAW,CAAC,IAAI,UAAU,KAAK,OAAO;AAAA,MACpC;AAAA,IACF,GAAG;AACD,UAAI,OAAO,eAAe;AAAY;AACtC,YAAM,OAAO,WAAW,SAAS;AACjC,UACE,KAAK,SAAS,UAAU,MACvB,KAAK,SAAS,YAAY,KACzB,KAAK,SAAS,wBAAwB,MACxC,yBAAyB,EAAE,GAC3B;AACA;AAAA,UACE;AAAA,UACA,8CAA8C,cAAc,MAAM,mBAAmB;AAAA,QACvF;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,yBAAyB,IAAuB;AACvD,MAAI,OAAO,OAAO;AAAU,WAAO;AACnC,SACE,GAAG,SAAS,6BAA6B,KACzC,GAAG,SAAS,kCAAkC;AAElD;AAEA,SAAS,qBACP,SACA,cACsB;AACtB,WAAS,QAAQ,eAAe,GAAG,SAAS,GAAG,SAAS;AACtD,UAAM,QAAQ,QAAQ,KAAK;AAC3B,QAAI,WAAW,KAAK;AAAG,aAAO;AAC9B,QAAI,OAAO,UAAU;AAAY,aAAO;AAAA,EAC1C;AACA,SAAO;AACT;","names":[]}
@@ -1,8 +1,12 @@
1
+ import React__default from 'react';
2
+
3
+ type PageComponent = React__default.ComponentType<Record<string, unknown>>;
4
+ type AppComponent = React__default.ComponentType<{
5
+ Component: PageComponent;
6
+ } & Record<string, unknown>>;
1
7
  declare function nextClientPagesLoader(bundle: string, route: string, styleContainer?: HTMLHeadElement | ShadowRoot | null): {
2
- Component: React.ComponentType<Record<string, unknown>> | null;
3
- App: React.ComponentType<{
4
- Component: React.ComponentType<Record<string, unknown>>;
5
- } & Record<string, unknown>> | null;
8
+ Component: PageComponent | null;
9
+ App: AppComponent | null;
6
10
  };
7
11
 
8
12
  export { nextClientPagesLoader };
@@ -1,10 +1,18 @@
1
1
  import { getNamespace } from "#internal/runtime/namespace";
2
+ import { requireModule } from "#internal/runtime/turbopack/module";
3
+ import {
4
+ getScope
5
+ } from "#internal/runtime/turbopack/remote-scope";
6
+ import { getTurbopackModules } from "#internal/runtime/turbopack/shared-modules";
2
7
  import { RemoteComponentsError } from "#internal/utils/error";
8
+ import { logDebug } from "#internal/utils/logger";
3
9
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
4
10
  const self = globalThis;
5
11
  const ns = getNamespace();
6
12
  ns.pageComponentCache ??= {};
7
13
  const cacheKey = `${bundle}:${route}`;
14
+ const remoteRequire = self.__remote_webpack_require__?.[bundle];
15
+ const turbopackScope = remoteRequire?.type === "turbopack" ? getScope(bundle) : void 0;
8
16
  const applyBundleCss = () => {
9
17
  const elements = ns.cssCache[bundle] ?? [];
10
18
  if (styleContainer) {
@@ -25,8 +33,10 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
25
33
  const nextCssOriginal = document.querySelector(
26
34
  `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
27
35
  );
36
+ const nextCssOriginalParent = nextCssOriginal?.parentNode ?? null;
37
+ const nextCssOriginalNextSibling = nextCssOriginal?.nextSibling ?? null;
28
38
  if (nextCssOriginal) {
29
- nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
39
+ nextCssOriginalParent?.removeChild(nextCssOriginal);
30
40
  }
31
41
  const nextCss = document.createElement("noscript");
32
42
  nextCss.id = "__next_css__DO_NOT_USE__";
@@ -38,25 +48,25 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
38
48
  nextCssEnd.setAttribute("data-route", route);
39
49
  document.head.appendChild(nextCssEnd);
40
50
  document.head.appendChild(nextCss);
41
- const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
51
+ const componentLoaderChunk = (turbopackScope ? findTurbopackPagesLoaderId(turbopackScope, route) : void 0) ?? Object.keys(remoteRequire?.m ?? {}).find(
42
52
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
43
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
53
+ ) ?? Object.keys(remoteRequire?.m ?? {}).find(
44
54
  (key) => key.includes("/next/dist/client/page-loader.js")
45
55
  ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
46
56
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
47
57
  ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
48
58
  (key) => key.includes("/next/dist/client/page-loader.js")
49
59
  ) ?? ""] ?? -1;
50
- const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
60
+ const appLoaderChunk = (turbopackScope ? findTurbopackPagesLoaderId(turbopackScope, "/_app") : void 0) ?? Object.keys(remoteRequire?.m ?? {}).find(
51
61
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
52
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
62
+ ) ?? Object.keys(remoteRequire?.m ?? {}).find(
53
63
  (key) => key.includes("/next/dist/client/page-loader.js")
54
64
  ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
55
65
  (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
56
66
  ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
57
67
  (key) => key.includes("/next/dist/client/page-loader.js")
58
68
  ) ?? ""] ?? -1;
59
- if (!(componentLoaderChunk && appLoaderChunk)) {
69
+ if (!isLoaderId(componentLoaderChunk) || !isLoaderId(appLoaderChunk)) {
60
70
  throw new RemoteComponentsError(
61
71
  `Next.js client pages loader not found in bundle "${bundle}".`
62
72
  );
@@ -64,61 +74,151 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
64
74
  const __NEXT_P_ORIGINAL = self.__NEXT_P;
65
75
  const selfOriginal = self;
66
76
  delete selfOriginal.__NEXT_P;
67
- self.__remote_webpack_require__?.[bundle]?.(
68
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? componentLoaderChunk : `[${bundle}] ${componentLoaderChunk}`
69
- );
70
- if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
71
- self.__remote_webpack_require__?.[bundle]?.(
72
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? appLoaderChunk : `[${bundle}] ${appLoaderChunk}`
73
- );
74
- }
75
- if (self.__NEXT_P) {
76
- const [, componentLoader] = self.__NEXT_P[0] ?? [
77
- void 0,
78
- () => ({ default: null })
79
- ];
80
- const [, appLoader] = self.__NEXT_P[2] ?? [
81
- void 0,
82
- () => ({
83
- default: null
84
- })
85
- ];
86
- const { default: Component = null } = componentLoader();
87
- const { default: App = null } = appLoader();
88
- const cssCache = ns.cssCache;
89
- if (!cssCache[bundle]) {
90
- const cssRE = /\.s?css$/;
91
- Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
92
- self.__remote_webpack_require__?.[bundle]?.(id);
93
- });
94
- Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
95
- const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
96
- if (id) {
77
+ try {
78
+ loadPagesLoaderModule(bundle, componentLoaderChunk, turbopackScope);
79
+ if (isLoaderId(appLoaderChunk)) {
80
+ loadPagesLoaderModule(bundle, appLoaderChunk, turbopackScope);
81
+ }
82
+ if (self.__NEXT_P) {
83
+ logDebug(
84
+ "ComponentLoader",
85
+ `Next.js Pages loader registry for "${route}" in "${bundle}": ${self.__NEXT_P.map((entry) => entry?.[0] ?? "<empty>").join(", ")}`
86
+ );
87
+ const componentEntry = self.__NEXT_P.find(
88
+ (entry) => entry?.[0] === route
89
+ ) ?? self.__NEXT_P[0];
90
+ const appEntry = self.__NEXT_P.find((entry) => entry?.[0] === "/_app") ?? self.__NEXT_P[2];
91
+ const [, componentLoader] = componentEntry ?? [
92
+ void 0,
93
+ () => ({ default: null })
94
+ ];
95
+ const [, appLoader] = appEntry ?? [
96
+ void 0,
97
+ () => ({
98
+ default: null
99
+ })
100
+ ];
101
+ const { default: Component = null } = componentLoader();
102
+ const { default: App = null } = appLoader();
103
+ const cssCache = ns.cssCache;
104
+ if (!cssCache[bundle]) {
105
+ const cssRE = /\.s?css$/;
106
+ Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
97
107
  self.__remote_webpack_require__?.[bundle]?.(id);
108
+ });
109
+ Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
110
+ const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
111
+ if (id) {
112
+ self.__remote_webpack_require__?.[bundle]?.(id);
113
+ }
114
+ });
115
+ const elements = [];
116
+ let node = nextCss.previousSibling;
117
+ while (node && node !== nextCssEnd) {
118
+ elements.push(node);
119
+ node.remove();
120
+ node = nextCss.previousSibling;
98
121
  }
99
- });
100
- const elements = [];
101
- let node = nextCss.previousSibling;
102
- while (node && node !== nextCssEnd) {
103
- elements.push(node);
104
- node.remove();
105
- node = nextCss.previousSibling;
122
+ cssCache[bundle] = elements;
106
123
  }
107
- cssCache[bundle] = elements;
124
+ applyBundleCss();
125
+ const result = { Component, App };
126
+ ns.pageComponentCache[cacheKey] = result;
127
+ return result;
108
128
  }
109
- applyBundleCss();
110
- delete self.__NEXT_P;
111
- self.__NEXT_P = __NEXT_P_ORIGINAL;
112
- if (nextCssOriginal) {
113
- nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
129
+ logDebug(
130
+ "ComponentLoader",
131
+ `Next.js Pages loaders for route "${route}" in "${bundle}" did not populate __NEXT_P`
132
+ );
133
+ return { Component: null, App: null };
134
+ } finally {
135
+ if (typeof __NEXT_P_ORIGINAL === "undefined") {
136
+ delete self.__NEXT_P;
137
+ } else {
138
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
139
+ }
140
+ if (nextCssOriginal && nextCssOriginalParent) {
141
+ const restoreBefore = nextCssOriginalNextSibling?.parentNode === nextCssOriginalParent ? nextCssOriginalNextSibling : null;
142
+ nextCssOriginalParent.insertBefore(nextCssOriginal, restoreBefore);
114
143
  }
115
144
  nextCss.remove();
116
145
  nextCssEnd.remove();
117
- const result = { Component, App };
118
- ns.pageComponentCache[cacheKey] = result;
119
- return result;
120
146
  }
121
- return { Component: null, App: null };
147
+ }
148
+ function isLoaderId(id) {
149
+ return typeof id === "string" && id.length > 0 || typeof id === "number" && id !== -1;
150
+ }
151
+ function loadPagesLoaderModule(bundle, id, turbopackScope) {
152
+ const self = globalThis;
153
+ if (turbopackScope) {
154
+ delete turbopackScope.moduleCache[String(id)];
155
+ requireModule(turbopackScope, id);
156
+ return;
157
+ }
158
+ const remoteRequire = self.__remote_webpack_require__?.[bundle];
159
+ if (remoteRequire?.c) {
160
+ delete remoteRequire.c[id];
161
+ }
162
+ remoteRequire?.(id);
163
+ }
164
+ function findTurbopackPagesLoaderId(scope, route) {
165
+ const modules = getTurbopackModules(scope);
166
+ if (!modules)
167
+ return void 0;
168
+ const routeLiteral = JSON.stringify(route);
169
+ const singleQuotedRouteLiteral = `'${route.replaceAll("'", "\\'")}'`;
170
+ const flat = modules.flat();
171
+ for (let index = 0; index < flat.length; index++) {
172
+ const entry = flat[index];
173
+ if (typeof entry === "function") {
174
+ const code = entry.toString();
175
+ if (code.includes("__NEXT_P") && (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral))) {
176
+ const id = findPreviousModuleId(flat, index);
177
+ if (isLoaderId(id) && isTurbopackPagesLoaderId(id)) {
178
+ logDebug(
179
+ "SharedModules",
180
+ `Resolved Turbopack Pages loader for route "${route}" in "${scope.scopedName}" as "${id}"`
181
+ );
182
+ return id;
183
+ }
184
+ }
185
+ continue;
186
+ }
187
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
188
+ continue;
189
+ if (typeof Element !== "undefined" && entry instanceof Element)
190
+ continue;
191
+ for (const [id, moduleInit] of Object.entries(
192
+ entry
193
+ )) {
194
+ if (typeof moduleInit !== "function")
195
+ continue;
196
+ const code = moduleInit.toString();
197
+ if (code.includes("__NEXT_P") && (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral)) && isTurbopackPagesLoaderId(id)) {
198
+ logDebug(
199
+ "SharedModules",
200
+ `Resolved Turbopack Pages loader for route "${route}" in "${scope.scopedName}" as "${id}"`
201
+ );
202
+ return id;
203
+ }
204
+ }
205
+ }
206
+ return void 0;
207
+ }
208
+ function isTurbopackPagesLoaderId(id) {
209
+ if (typeof id === "number")
210
+ return true;
211
+ return id.includes("[next]/entry/page-loader.ts") || id.includes("/next/dist/client/page-loader.js");
212
+ }
213
+ function findPreviousModuleId(entries, factoryIndex) {
214
+ for (let index = factoryIndex - 1; index >= 0; index--) {
215
+ const entry = entries[index];
216
+ if (isLoaderId(entry))
217
+ return entry;
218
+ if (typeof entry === "function")
219
+ return void 0;
220
+ }
221
+ return void 0;
122
222
  }
123
223
  export {
124
224
  nextClientPagesLoader