@payloadcms/tanstack-start 4.0.0-beta.0

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 (186) hide show
  1. package/LICENSE.md +22 -0
  2. package/dist/adapters/handleServerFunctions.d.ts +2 -0
  3. package/dist/adapters/handleServerFunctions.d.ts.map +1 -0
  4. package/dist/adapters/handleServerFunctions.js +9 -0
  5. package/dist/adapters/handleServerFunctions.js.map +1 -0
  6. package/dist/adapters/layout/index.d.ts +66 -0
  7. package/dist/adapters/layout/index.d.ts.map +1 -0
  8. package/dist/adapters/layout/index.js +105 -0
  9. package/dist/adapters/layout/index.js.map +1 -0
  10. package/dist/adapters/layout/lazy.d.ts +11 -0
  11. package/dist/adapters/layout/lazy.d.ts.map +1 -0
  12. package/dist/adapters/layout/lazy.js +23 -0
  13. package/dist/adapters/layout/lazy.js.map +1 -0
  14. package/dist/adapters/layout/server.d.ts +29 -0
  15. package/dist/adapters/layout/server.d.ts.map +1 -0
  16. package/dist/adapters/layout/server.js +63 -0
  17. package/dist/adapters/layout/server.js.map +1 -0
  18. package/dist/adapters/metadata.d.ts +80 -0
  19. package/dist/adapters/metadata.d.ts.map +1 -0
  20. package/dist/adapters/metadata.js +202 -0
  21. package/dist/adapters/metadata.js.map +1 -0
  22. package/dist/adapters/router.d.ts +3 -0
  23. package/dist/adapters/router.d.ts.map +1 -0
  24. package/dist/adapters/router.js +179 -0
  25. package/dist/adapters/router.js.map +1 -0
  26. package/dist/adapters/server.d.ts +36 -0
  27. package/dist/adapters/server.d.ts.map +1 -0
  28. package/dist/adapters/server.js +130 -0
  29. package/dist/adapters/server.js.map +1 -0
  30. package/dist/adapters/views/index.d.ts +104 -0
  31. package/dist/adapters/views/index.d.ts.map +1 -0
  32. package/dist/adapters/views/index.js +80 -0
  33. package/dist/adapters/views/index.js.map +1 -0
  34. package/dist/adapters/views/lazy.d.ts +4 -0
  35. package/dist/adapters/views/lazy.d.ts.map +1 -0
  36. package/dist/adapters/views/lazy.js +43 -0
  37. package/dist/adapters/views/lazy.js.map +1 -0
  38. package/dist/adapters/views/server.d.ts +57 -0
  39. package/dist/adapters/views/server.d.ts.map +1 -0
  40. package/dist/adapters/views/server.js +169 -0
  41. package/dist/adapters/views/server.js.map +1 -0
  42. package/dist/auth/login.d.ts +4 -0
  43. package/dist/auth/login.d.ts.map +1 -0
  44. package/dist/auth/login.js +10 -0
  45. package/dist/auth/login.js.map +1 -0
  46. package/dist/auth/logout.d.ts +6 -0
  47. package/dist/auth/logout.d.ts.map +1 -0
  48. package/dist/auth/logout.js +10 -0
  49. package/dist/auth/logout.js.map +1 -0
  50. package/dist/auth/refresh.d.ts +6 -0
  51. package/dist/auth/refresh.d.ts.map +1 -0
  52. package/dist/auth/refresh.js +10 -0
  53. package/dist/auth/refresh.js.map +1 -0
  54. package/dist/exports/client.d.ts +4 -0
  55. package/dist/exports/client.d.ts.map +1 -0
  56. package/dist/exports/client.js +6 -0
  57. package/dist/exports/client.js.map +1 -0
  58. package/dist/exports/layouts.d.ts +3 -0
  59. package/dist/exports/layouts.d.ts.map +1 -0
  60. package/dist/exports/layouts.js +3 -0
  61. package/dist/exports/layouts.js.map +1 -0
  62. package/dist/exports/rsc.browser.d.ts +15 -0
  63. package/dist/exports/rsc.browser.d.ts.map +1 -0
  64. package/dist/exports/rsc.browser.js +15 -0
  65. package/dist/exports/rsc.browser.js.map +1 -0
  66. package/dist/exports/rsc.d.ts +4 -0
  67. package/dist/exports/rsc.d.ts.map +1 -0
  68. package/dist/exports/rsc.js +5 -0
  69. package/dist/exports/rsc.js.map +1 -0
  70. package/dist/exports/server.d.ts +15 -0
  71. package/dist/exports/server.d.ts.map +1 -0
  72. package/dist/exports/server.js +16 -0
  73. package/dist/exports/server.js.map +1 -0
  74. package/dist/exports/shared.d.ts +2 -0
  75. package/dist/exports/shared.d.ts.map +1 -0
  76. package/dist/exports/shared.js +3 -0
  77. package/dist/exports/shared.js.map +1 -0
  78. package/dist/index.d.ts +2 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +3 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/routes/graphql/handler.server.d.ts +10 -0
  83. package/dist/routes/graphql/handler.server.d.ts.map +1 -0
  84. package/dist/routes/graphql/handler.server.js +132 -0
  85. package/dist/routes/graphql/handler.server.js.map +1 -0
  86. package/dist/routes/rest/handler.server.d.ts +11 -0
  87. package/dist/routes/rest/handler.server.d.ts.map +1 -0
  88. package/dist/routes/rest/handler.server.js +17 -0
  89. package/dist/routes/rest/handler.server.js.map +1 -0
  90. package/dist/routes/rest/index.d.ts +34 -0
  91. package/dist/routes/rest/index.d.ts.map +1 -0
  92. package/dist/routes/rest/index.js +43 -0
  93. package/dist/routes/rest/index.js.map +1 -0
  94. package/dist/rsc/CollectionCards.d.ts +4 -0
  95. package/dist/rsc/CollectionCards.d.ts.map +1 -0
  96. package/dist/rsc/CollectionCards.js +12 -0
  97. package/dist/rsc/CollectionCards.js.map +1 -0
  98. package/dist/rsc/HierarchyTypeFieldServer.d.ts +9 -0
  99. package/dist/rsc/HierarchyTypeFieldServer.d.ts.map +1 -0
  100. package/dist/rsc/HierarchyTypeFieldServer.js +35 -0
  101. package/dist/rsc/HierarchyTypeFieldServer.js.map +1 -0
  102. package/dist/rsc/renderOnDemand.d.ts +15 -0
  103. package/dist/rsc/renderOnDemand.d.ts.map +1 -0
  104. package/dist/rsc/renderOnDemand.js +25 -0
  105. package/dist/rsc/renderOnDemand.js.map +1 -0
  106. package/dist/utilities/devConfigReload.server.d.ts +2 -0
  107. package/dist/utilities/devConfigReload.server.d.ts.map +1 -0
  108. package/dist/utilities/devConfigReload.server.js +63 -0
  109. package/dist/utilities/devConfigReload.server.js.map +1 -0
  110. package/dist/utilities/devConfigReloadEvent.d.ts +9 -0
  111. package/dist/utilities/devConfigReloadEvent.d.ts.map +1 -0
  112. package/dist/utilities/devConfigReloadEvent.js +9 -0
  113. package/dist/utilities/devConfigReloadEvent.js.map +1 -0
  114. package/dist/utilities/getRequestI18n.server.d.ts +12 -0
  115. package/dist/utilities/getRequestI18n.server.d.ts.map +1 -0
  116. package/dist/utilities/getRequestI18n.server.js +25 -0
  117. package/dist/utilities/getRequestI18n.server.js.map +1 -0
  118. package/dist/utilities/initAdminContext.server.d.ts +9 -0
  119. package/dist/utilities/initAdminContext.server.d.ts.map +1 -0
  120. package/dist/utilities/initAdminContext.server.js +13 -0
  121. package/dist/utilities/initAdminContext.server.js.map +1 -0
  122. package/dist/utilities/routerSearch.d.ts +40 -0
  123. package/dist/utilities/routerSearch.d.ts.map +1 -0
  124. package/dist/utilities/routerSearch.js +45 -0
  125. package/dist/utilities/routerSearch.js.map +1 -0
  126. package/dist/utilities/serializeForRsc.d.ts +26 -0
  127. package/dist/utilities/serializeForRsc.d.ts.map +1 -0
  128. package/dist/utilities/serializeForRsc.js +127 -0
  129. package/dist/utilities/serializeForRsc.js.map +1 -0
  130. package/dist/utilities/serverFunctionClient.d.ts +29 -0
  131. package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
  132. package/dist/utilities/serverFunctionClient.js +114 -0
  133. package/dist/utilities/serverFunctionClient.js.map +1 -0
  134. package/dist/utilities/toSerializable.d.ts +11 -0
  135. package/dist/utilities/toSerializable.d.ts.map +1 -0
  136. package/dist/utilities/toSerializable.js +127 -0
  137. package/dist/utilities/toSerializable.js.map +1 -0
  138. package/dist/withPayload/config/external.d.ts +44 -0
  139. package/dist/withPayload/config/external.d.ts.map +1 -0
  140. package/dist/withPayload/config/external.js +96 -0
  141. package/dist/withPayload/config/external.js.map +1 -0
  142. package/dist/withPayload/config/optimizeDeps.d.ts +25 -0
  143. package/dist/withPayload/config/optimizeDeps.d.ts.map +1 -0
  144. package/dist/withPayload/config/optimizeDeps.js +160 -0
  145. package/dist/withPayload/config/optimizeDeps.js.map +1 -0
  146. package/dist/withPayload/config/scss.d.ts +14 -0
  147. package/dist/withPayload/config/scss.d.ts.map +1 -0
  148. package/dist/withPayload/config/scss.js +28 -0
  149. package/dist/withPayload/config/scss.js.map +1 -0
  150. package/dist/withPayload/devConfigReload.d.ts +14 -0
  151. package/dist/withPayload/devConfigReload.d.ts.map +1 -0
  152. package/dist/withPayload/devConfigReload.js +84 -0
  153. package/dist/withPayload/devConfigReload.js.map +1 -0
  154. package/dist/withPayload/importProtection.d.ts +14 -0
  155. package/dist/withPayload/importProtection.d.ts.map +1 -0
  156. package/dist/withPayload/importProtection.js +54 -0
  157. package/dist/withPayload/importProtection.js.map +1 -0
  158. package/dist/withPayload/index.d.ts +110 -0
  159. package/dist/withPayload/index.d.ts.map +1 -0
  160. package/dist/withPayload/index.js +300 -0
  161. package/dist/withPayload/index.js.map +1 -0
  162. package/dist/withPayload/workarounds/clientModuleResolution.d.ts +14 -0
  163. package/dist/withPayload/workarounds/clientModuleResolution.d.ts.map +1 -0
  164. package/dist/withPayload/workarounds/clientModuleResolution.js +98 -0
  165. package/dist/withPayload/workarounds/clientModuleResolution.js.map +1 -0
  166. package/dist/withPayload/workarounds/devTransforms.d.ts +19 -0
  167. package/dist/withPayload/workarounds/devTransforms.d.ts.map +1 -0
  168. package/dist/withPayload/workarounds/devTransforms.js +72 -0
  169. package/dist/withPayload/workarounds/devTransforms.js.map +1 -0
  170. package/dist/withPayload/workarounds/reactDomServerInRsc.d.ts +27 -0
  171. package/dist/withPayload/workarounds/reactDomServerInRsc.d.ts.map +1 -0
  172. package/dist/withPayload/workarounds/reactDomServerInRsc.js +90 -0
  173. package/dist/withPayload/workarounds/reactDomServerInRsc.js.map +1 -0
  174. package/dist/withPayload/workarounds/stripDistStyleImports.d.ts +21 -0
  175. package/dist/withPayload/workarounds/stripDistStyleImports.d.ts.map +1 -0
  176. package/dist/withPayload/workarounds/stripDistStyleImports.js +140 -0
  177. package/dist/withPayload/workarounds/stripDistStyleImports.js.map +1 -0
  178. package/dist/withPayload/workarounds/stubPrettierInClient.d.ts +13 -0
  179. package/dist/withPayload/workarounds/stubPrettierInClient.d.ts.map +1 -0
  180. package/dist/withPayload/workarounds/stubPrettierInClient.js +32 -0
  181. package/dist/withPayload/workarounds/stubPrettierInClient.js.map +1 -0
  182. package/dist/withPayload/workarounds/wrapCjsForClient.d.ts +15 -0
  183. package/dist/withPayload/workarounds/wrapCjsForClient.d.ts.map +1 -0
  184. package/dist/withPayload/workarounds/wrapCjsForClient.js +106 -0
  185. package/dist/withPayload/workarounds/wrapCjsForClient.js.map +1 -0
  186. package/package.json +114 -0
@@ -0,0 +1,14 @@
1
+ import type { PluginOption } from 'vite';
2
+ /**
3
+ * Client-side module resolution:
4
+ * 1. Stubs RSC modules (`@payloadcms/.../rsc`) with no-op components so the
5
+ * Vite optimizer never tries to bundle their server implementations.
6
+ * 2. Redirects bare `payload` imports made from user code (outside of
7
+ * `node_modules` and our own packages) to `payload/shared`. The main
8
+ * `payload` entry has top-level side effects requiring Node.js APIs.
9
+ * 3. Resolves `/client` subpath exports for `@payloadcms/plugin-*` and
10
+ * `@payloadcms/storage-*` packages when normal Vite resolution fails in
11
+ * monorepo dev (no `dist/` built yet).
12
+ */
13
+ export declare function clientModuleResolution(): PluginOption;
14
+ //# sourceMappingURL=clientModuleResolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientModuleResolution.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/clientModuleResolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAKxC;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CA+ErD"}
@@ -0,0 +1,98 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ /**
4
+ * Client-side module resolution:
5
+ * 1. Stubs RSC modules (`@payloadcms/.../rsc`) with no-op components so the
6
+ * Vite optimizer never tries to bundle their server implementations.
7
+ * 2. Redirects bare `payload` imports made from user code (outside of
8
+ * `node_modules` and our own packages) to `payload/shared`. The main
9
+ * `payload` entry has top-level side effects requiring Node.js APIs.
10
+ * 3. Resolves `/client` subpath exports for `@payloadcms/plugin-*` and
11
+ * `@payloadcms/storage-*` packages when normal Vite resolution fails in
12
+ * monorepo dev (no `dist/` built yet).
13
+ */ export function clientModuleResolution() {
14
+ const stubPrefix = '\0payload:server-stub:';
15
+ const serverOnlyPatterns = [
16
+ /^@payloadcms\/richtext-lexical\/rsc$/,
17
+ /^@payloadcms\/richtext-slate\/rsc$/,
18
+ /^@payloadcms\/next\/rsc$/,
19
+ /^@payloadcms\/tanstack-start\/rsc$/
20
+ ];
21
+ const serverOnlyExports = {
22
+ '@payloadcms/next/rsc': [
23
+ 'CollectionCards',
24
+ 'HierarchyTypeFieldServer'
25
+ ],
26
+ '@payloadcms/richtext-lexical/rsc': [
27
+ 'RscEntryLexicalCell',
28
+ 'RscEntryLexicalField',
29
+ 'LexicalDiffComponent'
30
+ ],
31
+ '@payloadcms/tanstack-start/rsc': [
32
+ 'CollectionCards',
33
+ 'HierarchyTypeFieldServer',
34
+ 'renderPayloadComponentOnServer'
35
+ ]
36
+ };
37
+ return {
38
+ name: 'payload:client-module-resolution',
39
+ enforce: 'pre',
40
+ load (id) {
41
+ if (!id.startsWith(stubPrefix)) {
42
+ return;
43
+ }
44
+ const specifier = id.slice(stubPrefix.length);
45
+ const exports = serverOnlyExports[specifier];
46
+ if (exports) {
47
+ return exports.map((name)=>`export const ${name} = () => null;`).join('\n');
48
+ }
49
+ return `export default null;`;
50
+ },
51
+ async resolveId (id, importer, options) {
52
+ if (options?.ssr) {
53
+ return;
54
+ }
55
+ if (serverOnlyPatterns.some((p)=>p.test(id))) {
56
+ return stubPrefix + id;
57
+ }
58
+ if (id === 'payload' && importer && !importer.includes('/node_modules/')) {
59
+ const isPayloadPackage = /\/packages\/(?:payload|ui|richtext-|tanstack-start|next)\//.test(importer);
60
+ if (!isPayloadPackage) {
61
+ return this.resolve('payload/shared', importer, {
62
+ ...options,
63
+ skipSelf: true
64
+ });
65
+ }
66
+ }
67
+ if (/^@payloadcms\/(?:plugin|storage)-[^/]+\/client$/.test(id)) {
68
+ const resolved = await this.resolve(id, importer, {
69
+ ...options,
70
+ skipSelf: true
71
+ });
72
+ if (resolved) {
73
+ return resolved;
74
+ }
75
+ const pkgName = id.replace(/\/client$/, '');
76
+ const pkgResolved = await this.resolve(pkgName, importer, {
77
+ ...options,
78
+ skipSelf: true
79
+ });
80
+ if (pkgResolved) {
81
+ const pkgDir = path.dirname(pkgResolved.id);
82
+ const candidates = [
83
+ path.resolve(pkgDir, 'src', 'exports', 'client.ts'),
84
+ path.resolve(pkgDir, 'src', 'exports', 'client.js'),
85
+ path.resolve(pkgDir, 'dist', 'exports', 'client.js')
86
+ ];
87
+ for (const candidate of candidates){
88
+ if (fs.existsSync(candidate)) {
89
+ return candidate;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ };
96
+ }
97
+
98
+ //# sourceMappingURL=clientModuleResolution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/withPayload/workarounds/clientModuleResolution.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * Client-side module resolution:\n * 1. Stubs RSC modules (`@payloadcms/.../rsc`) with no-op components so the\n * Vite optimizer never tries to bundle their server implementations.\n * 2. Redirects bare `payload` imports made from user code (outside of\n * `node_modules` and our own packages) to `payload/shared`. The main\n * `payload` entry has top-level side effects requiring Node.js APIs.\n * 3. Resolves `/client` subpath exports for `@payloadcms/plugin-*` and\n * `@payloadcms/storage-*` packages when normal Vite resolution fails in\n * monorepo dev (no `dist/` built yet).\n */\nexport function clientModuleResolution(): PluginOption {\n const stubPrefix = '\\0payload:server-stub:'\n\n const serverOnlyPatterns: RegExp[] = [\n /^@payloadcms\\/richtext-lexical\\/rsc$/,\n /^@payloadcms\\/richtext-slate\\/rsc$/,\n /^@payloadcms\\/next\\/rsc$/,\n /^@payloadcms\\/tanstack-start\\/rsc$/,\n ]\n\n const serverOnlyExports: Record<string, string[]> = {\n '@payloadcms/next/rsc': ['CollectionCards', 'HierarchyTypeFieldServer'],\n '@payloadcms/richtext-lexical/rsc': [\n 'RscEntryLexicalCell',\n 'RscEntryLexicalField',\n 'LexicalDiffComponent',\n ],\n '@payloadcms/tanstack-start/rsc': [\n 'CollectionCards',\n 'HierarchyTypeFieldServer',\n 'renderPayloadComponentOnServer',\n ],\n }\n\n return {\n name: 'payload:client-module-resolution',\n enforce: 'pre',\n load(id) {\n if (!id.startsWith(stubPrefix)) {\n return\n }\n const specifier = id.slice(stubPrefix.length)\n const exports = serverOnlyExports[specifier]\n if (exports) {\n return exports.map((name) => `export const ${name} = () => null;`).join('\\n')\n }\n return `export default null;`\n },\n async resolveId(id, importer, options) {\n if (options?.ssr) {\n return\n }\n\n if (serverOnlyPatterns.some((p) => p.test(id))) {\n return stubPrefix + id\n }\n\n if (id === 'payload' && importer && !importer.includes('/node_modules/')) {\n const isPayloadPackage = /\\/packages\\/(?:payload|ui|richtext-|tanstack-start|next)\\//.test(\n importer,\n )\n if (!isPayloadPackage) {\n return this.resolve('payload/shared', importer, { ...options, skipSelf: true })\n }\n }\n\n if (/^@payloadcms\\/(?:plugin|storage)-[^/]+\\/client$/.test(id)) {\n const resolved = await this.resolve(id, importer, { ...options, skipSelf: true })\n if (resolved) {\n return resolved\n }\n const pkgName = id.replace(/\\/client$/, '')\n const pkgResolved = await this.resolve(pkgName, importer, { ...options, skipSelf: true })\n if (pkgResolved) {\n const pkgDir = path.dirname(pkgResolved.id)\n const candidates = [\n path.resolve(pkgDir, 'src', 'exports', 'client.ts'),\n path.resolve(pkgDir, 'src', 'exports', 'client.js'),\n path.resolve(pkgDir, 'dist', 'exports', 'client.js'),\n ]\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n return candidate\n }\n }\n }\n }\n },\n }\n}\n"],"names":["fs","path","clientModuleResolution","stubPrefix","serverOnlyPatterns","serverOnlyExports","name","enforce","load","id","startsWith","specifier","slice","length","exports","map","join","resolveId","importer","options","ssr","some","p","test","includes","isPayloadPackage","resolve","skipSelf","resolved","pkgName","replace","pkgResolved","pkgDir","dirname","candidates","candidate","existsSync"],"mappings":"AAEA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAE5B;;;;;;;;;;CAUC,GACD,OAAO,SAASC;IACd,MAAMC,aAAa;IAEnB,MAAMC,qBAA+B;QACnC;QACA;QACA;QACA;KACD;IAED,MAAMC,oBAA8C;QAClD,wBAAwB;YAAC;YAAmB;SAA2B;QACvE,oCAAoC;YAClC;YACA;YACA;SACD;QACD,kCAAkC;YAChC;YACA;YACA;SACD;IACH;IAEA,OAAO;QACLC,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAI,CAACA,GAAGC,UAAU,CAACP,aAAa;gBAC9B;YACF;YACA,MAAMQ,YAAYF,GAAGG,KAAK,CAACT,WAAWU,MAAM;YAC5C,MAAMC,UAAUT,iBAAiB,CAACM,UAAU;YAC5C,IAAIG,SAAS;gBACX,OAAOA,QAAQC,GAAG,CAAC,CAACT,OAAS,CAAC,aAAa,EAAEA,KAAK,cAAc,CAAC,EAAEU,IAAI,CAAC;YAC1E;YACA,OAAO,CAAC,oBAAoB,CAAC;QAC/B;QACA,MAAMC,WAAUR,EAAE,EAAES,QAAQ,EAAEC,OAAO;YACnC,IAAIA,SAASC,KAAK;gBAChB;YACF;YAEA,IAAIhB,mBAAmBiB,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,CAACd,MAAM;gBAC9C,OAAON,aAAaM;YACtB;YAEA,IAAIA,OAAO,aAAaS,YAAY,CAACA,SAASM,QAAQ,CAAC,mBAAmB;gBACxE,MAAMC,mBAAmB,6DAA6DF,IAAI,CACxFL;gBAEF,IAAI,CAACO,kBAAkB;oBACrB,OAAO,IAAI,CAACC,OAAO,CAAC,kBAAkBR,UAAU;wBAAE,GAAGC,OAAO;wBAAEQ,UAAU;oBAAK;gBAC/E;YACF;YAEA,IAAI,kDAAkDJ,IAAI,CAACd,KAAK;gBAC9D,MAAMmB,WAAW,MAAM,IAAI,CAACF,OAAO,CAACjB,IAAIS,UAAU;oBAAE,GAAGC,OAAO;oBAAEQ,UAAU;gBAAK;gBAC/E,IAAIC,UAAU;oBACZ,OAAOA;gBACT;gBACA,MAAMC,UAAUpB,GAAGqB,OAAO,CAAC,aAAa;gBACxC,MAAMC,cAAc,MAAM,IAAI,CAACL,OAAO,CAACG,SAASX,UAAU;oBAAE,GAAGC,OAAO;oBAAEQ,UAAU;gBAAK;gBACvF,IAAII,aAAa;oBACf,MAAMC,SAAS/B,KAAKgC,OAAO,CAACF,YAAYtB,EAAE;oBAC1C,MAAMyB,aAAa;wBACjBjC,KAAKyB,OAAO,CAACM,QAAQ,OAAO,WAAW;wBACvC/B,KAAKyB,OAAO,CAACM,QAAQ,OAAO,WAAW;wBACvC/B,KAAKyB,OAAO,CAACM,QAAQ,QAAQ,WAAW;qBACzC;oBACD,KAAK,MAAMG,aAAaD,WAAY;wBAClC,IAAIlC,GAAGoC,UAAU,CAACD,YAAY;4BAC5B,OAAOA;wBACT;oBACF;gBACF;YACF;QACF;IACF;AACF"}
@@ -0,0 +1,19 @@
1
+ import type { PluginOption } from 'vite';
2
+ /**
3
+ * Dev-time transforms:
4
+ * - Replaces `process.cwd()` with `"/"` in client code (non-SSR, non-prebundled)
5
+ * - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)
6
+ *
7
+ * The preamble is injected just before `</head>`, *after* everything React
8
+ * renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`
9
+ * as hoistable resources it matches by key (position-tolerant), but a
10
+ * non-hoistable inline `<script type="module">` placed *before* React's first
11
+ * rendered head node makes hydration position-match that script against a
12
+ * `<style>`/`<meta>` and throw — discarding the whole tree client-side, which
13
+ * aborts in-flight server-function fetches and intermittently breaks drawers,
14
+ * forms, and navigation. Appending after React's head content keeps the
15
+ * preamble out of that positional comparison while still running before the
16
+ * body's app-entry module.
17
+ */
18
+ export declare function payloadDevTransforms(): PluginOption;
19
+ //# sourceMappingURL=devTransforms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devTransforms.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/devTransforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAgEnD"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Dev-time transforms:
3
+ * - Replaces `process.cwd()` with `"/"` in client code (non-SSR, non-prebundled)
4
+ * - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)
5
+ *
6
+ * The preamble is injected just before `</head>`, *after* everything React
7
+ * renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`
8
+ * as hoistable resources it matches by key (position-tolerant), but a
9
+ * non-hoistable inline `<script type="module">` placed *before* React's first
10
+ * rendered head node makes hydration position-match that script against a
11
+ * `<style>`/`<meta>` and throw — discarding the whole tree client-side, which
12
+ * aborts in-flight server-function fetches and intermittently breaks drawers,
13
+ * forms, and navigation. Appending after React's head content keeps the
14
+ * preamble out of that positional comparison while still running before the
15
+ * body's app-entry module.
16
+ */ export function payloadDevTransforms() {
17
+ const devScripts = `<script type="module" src="/@vite/client"></script>
18
+ <script type="module">
19
+ import RefreshRuntime from "/@react-refresh"
20
+ RefreshRuntime.injectIntoGlobalHook(window)
21
+ window.$RefreshReg$ = () => {}
22
+ window.$RefreshSig$ = () => (type) => type
23
+ window.__vite_plugin_react_preamble_installed__ = true
24
+ </script>`;
25
+ return {
26
+ name: 'payload:dev-transforms',
27
+ configureServer (server) {
28
+ server.middlewares.use((_req, res, next)=>{
29
+ let injected = false;
30
+ const origWrite = res.write;
31
+ const origEnd = res.end;
32
+ function tryInject(chunk) {
33
+ if (injected || chunk == null) {
34
+ return chunk;
35
+ }
36
+ const ct = res.getHeader('content-type');
37
+ if (typeof ct !== 'string' || !ct.includes('text/html')) {
38
+ return chunk;
39
+ }
40
+ const str = typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : chunk instanceof Uint8Array ? Buffer.from(chunk).toString() : null;
41
+ // Skip if a host already injected the preamble — a second copy breaks HMR.
42
+ if (str && str.includes('__vite_plugin_react_preamble_installed__')) {
43
+ injected = true;
44
+ return chunk;
45
+ }
46
+ if (str && str.includes('</head>')) {
47
+ injected = true;
48
+ return str.replace('</head>', `${devScripts}</head>`);
49
+ }
50
+ return chunk;
51
+ }
52
+ res.write = function(chunk, encodingOrCb, cb) {
53
+ return origWrite.call(this, tryInject(chunk), encodingOrCb, cb);
54
+ };
55
+ res.end = function(chunk, encodingOrCb, cb) {
56
+ return origEnd.call(this, tryInject(chunk), encodingOrCb, cb);
57
+ };
58
+ next();
59
+ });
60
+ },
61
+ transform (code, id, options) {
62
+ if (options?.ssr) {
63
+ return;
64
+ }
65
+ if (code.includes('process.cwd') && !id.includes('node_modules/.vite')) {
66
+ return code.replace(/process\.cwd\(\)/g, '"/"');
67
+ }
68
+ }
69
+ };
70
+ }
71
+
72
+ //# sourceMappingURL=devTransforms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/withPayload/workarounds/devTransforms.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Dev-time transforms:\n * - Replaces `process.cwd()` with `\"/\"` in client code (non-SSR, non-prebundled)\n * - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)\n *\n * The preamble is injected just before `</head>`, *after* everything React\n * renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`\n * as hoistable resources it matches by key (position-tolerant), but a\n * non-hoistable inline `<script type=\"module\">` placed *before* React's first\n * rendered head node makes hydration position-match that script against a\n * `<style>`/`<meta>` and throw — discarding the whole tree client-side, which\n * aborts in-flight server-function fetches and intermittently breaks drawers,\n * forms, and navigation. Appending after React's head content keeps the\n * preamble out of that positional comparison while still running before the\n * body's app-entry module.\n */\nexport function payloadDevTransforms(): PluginOption {\n const devScripts = `<script type=\"module\" src=\"/@vite/client\"></script>\n<script type=\"module\">\nimport RefreshRuntime from \"/@react-refresh\"\nRefreshRuntime.injectIntoGlobalHook(window)\nwindow.$RefreshReg$ = () => {}\nwindow.$RefreshSig$ = () => (type) => type\nwindow.__vite_plugin_react_preamble_installed__ = true\n</script>`\n\n return {\n name: 'payload:dev-transforms',\n configureServer(server) {\n server.middlewares.use((_req, res, next) => {\n let injected = false\n const origWrite = res.write\n const origEnd = res.end\n\n function tryInject(chunk: any): any {\n if (injected || chunk == null) {\n return chunk\n }\n const ct = res.getHeader('content-type')\n if (typeof ct !== 'string' || !ct.includes('text/html')) {\n return chunk\n }\n const str =\n typeof chunk === 'string'\n ? chunk\n : Buffer.isBuffer(chunk)\n ? chunk.toString()\n : chunk instanceof Uint8Array\n ? Buffer.from(chunk).toString()\n : null\n // Skip if a host already injected the preamble — a second copy breaks HMR.\n if (str && str.includes('__vite_plugin_react_preamble_installed__')) {\n injected = true\n return chunk\n }\n if (str && str.includes('</head>')) {\n injected = true\n return str.replace('</head>', `${devScripts}</head>`)\n }\n return chunk\n }\n\n res.write = function (this: any, chunk: any, encodingOrCb?: any, cb?: any) {\n return origWrite.call(this, tryInject(chunk), encodingOrCb, cb)\n } as typeof res.write\n res.end = function (this: any, chunk?: any, encodingOrCb?: any, cb?: any) {\n return origEnd.call(this, tryInject(chunk), encodingOrCb, cb)\n } as typeof res.end\n next()\n })\n },\n transform(code, id, options) {\n if (options?.ssr) {\n return\n }\n if (code.includes('process.cwd') && !id.includes('node_modules/.vite')) {\n return code.replace(/process\\.cwd\\(\\)/g, '\"/\"')\n }\n },\n }\n}\n"],"names":["payloadDevTransforms","devScripts","name","configureServer","server","middlewares","use","_req","res","next","injected","origWrite","write","origEnd","end","tryInject","chunk","ct","getHeader","includes","str","Buffer","isBuffer","toString","Uint8Array","from","replace","encodingOrCb","cb","call","transform","code","id","options","ssr"],"mappings":"AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASA;IACd,MAAMC,aAAa,CAAC;;;;;;;SAOb,CAAC;IAER,OAAO;QACLC,MAAM;QACNC,iBAAgBC,MAAM;YACpBA,OAAOC,WAAW,CAACC,GAAG,CAAC,CAACC,MAAMC,KAAKC;gBACjC,IAAIC,WAAW;gBACf,MAAMC,YAAYH,IAAII,KAAK;gBAC3B,MAAMC,UAAUL,IAAIM,GAAG;gBAEvB,SAASC,UAAUC,KAAU;oBAC3B,IAAIN,YAAYM,SAAS,MAAM;wBAC7B,OAAOA;oBACT;oBACA,MAAMC,KAAKT,IAAIU,SAAS,CAAC;oBACzB,IAAI,OAAOD,OAAO,YAAY,CAACA,GAAGE,QAAQ,CAAC,cAAc;wBACvD,OAAOH;oBACT;oBACA,MAAMI,MACJ,OAAOJ,UAAU,WACbA,QACAK,OAAOC,QAAQ,CAACN,SACdA,MAAMO,QAAQ,KACdP,iBAAiBQ,aACfH,OAAOI,IAAI,CAACT,OAAOO,QAAQ,KAC3B;oBACV,2EAA2E;oBAC3E,IAAIH,OAAOA,IAAID,QAAQ,CAAC,6CAA6C;wBACnET,WAAW;wBACX,OAAOM;oBACT;oBACA,IAAII,OAAOA,IAAID,QAAQ,CAAC,YAAY;wBAClCT,WAAW;wBACX,OAAOU,IAAIM,OAAO,CAAC,WAAW,GAAGzB,WAAW,OAAO,CAAC;oBACtD;oBACA,OAAOe;gBACT;gBAEAR,IAAII,KAAK,GAAG,SAAqBI,KAAU,EAAEW,YAAkB,EAAEC,EAAQ;oBACvE,OAAOjB,UAAUkB,IAAI,CAAC,IAAI,EAAEd,UAAUC,QAAQW,cAAcC;gBAC9D;gBACApB,IAAIM,GAAG,GAAG,SAAqBE,KAAW,EAAEW,YAAkB,EAAEC,EAAQ;oBACtE,OAAOf,QAAQgB,IAAI,CAAC,IAAI,EAAEd,UAAUC,QAAQW,cAAcC;gBAC5D;gBACAnB;YACF;QACF;QACAqB,WAAUC,IAAI,EAAEC,EAAE,EAAEC,OAAO;YACzB,IAAIA,SAASC,KAAK;gBAChB;YACF;YACA,IAAIH,KAAKZ,QAAQ,CAAC,kBAAkB,CAACa,GAAGb,QAAQ,CAAC,uBAAuB;gBACtE,OAAOY,KAAKL,OAAO,CAAC,qBAAqB;YAC3C;QACF;IACF;AACF"}
@@ -0,0 +1,27 @@
1
+ import type { PluginOption } from 'vite';
2
+ /**
3
+ * Provides a working `react-dom/server` inside the RSC environment.
4
+ *
5
+ * Payload's version-diff converters (`@payloadcms/richtext-lexical`'s
6
+ * `field/Diff/converters/*` and `@payloadcms/ui`'s `Version/RenderFieldsToDiff`)
7
+ * call `renderToStaticMarkup` while rendering a Server Component. In the RSC
8
+ * environment Vite activates the `react-server` export condition, under which
9
+ * every `react-dom/server*` subpath resolves to `server.react-server.js` — a
10
+ * stub that throws `react-dom/server is not supported in React Server
11
+ * Components`. Force-resolving past the condition isn't enough either: the
12
+ * static renderer reads the *client* React internals
13
+ * (`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`), which
14
+ * the `react-server` build of `react` doesn't expose.
15
+ *
16
+ * So we pre-bundle a self-contained `react-dom/server` with client React
17
+ * inlined (esbuild, deliberately WITHOUT the `react-server` condition) and
18
+ * redirect `react-dom/server` to it in the RSC graph only. The bundle is fully
19
+ * self-contained, so the RSC environment's `react-server` condition can't
20
+ * reach into it. JSX elements created by the RSC-graph React stay renderable
21
+ * because React identifies elements via a process-global `Symbol.for(...)`.
22
+ *
23
+ * Delete this once `react-dom/server` (or an equivalent static renderer) is
24
+ * usable from the `react-server` condition without a separate bundle.
25
+ */
26
+ export declare function reactDomServerInRsc(): PluginOption;
27
+ //# sourceMappingURL=reactDomServerInRsc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactDomServerInRsc.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/reactDomServerInRsc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAQxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAyDlD"}
@@ -0,0 +1,90 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ const REACT_DOM_SERVER_RE = /^react-dom\/server(?:\.(?:edge|node|browser))?$/;
4
+ /**
5
+ * Provides a working `react-dom/server` inside the RSC environment.
6
+ *
7
+ * Payload's version-diff converters (`@payloadcms/richtext-lexical`'s
8
+ * `field/Diff/converters/*` and `@payloadcms/ui`'s `Version/RenderFieldsToDiff`)
9
+ * call `renderToStaticMarkup` while rendering a Server Component. In the RSC
10
+ * environment Vite activates the `react-server` export condition, under which
11
+ * every `react-dom/server*` subpath resolves to `server.react-server.js` — a
12
+ * stub that throws `react-dom/server is not supported in React Server
13
+ * Components`. Force-resolving past the condition isn't enough either: the
14
+ * static renderer reads the *client* React internals
15
+ * (`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`), which
16
+ * the `react-server` build of `react` doesn't expose.
17
+ *
18
+ * So we pre-bundle a self-contained `react-dom/server` with client React
19
+ * inlined (esbuild, deliberately WITHOUT the `react-server` condition) and
20
+ * redirect `react-dom/server` to it in the RSC graph only. The bundle is fully
21
+ * self-contained, so the RSC environment's `react-server` condition can't
22
+ * reach into it. JSX elements created by the RSC-graph React stay renderable
23
+ * because React identifies elements via a process-global `Symbol.for(...)`.
24
+ *
25
+ * Delete this once `react-dom/server` (or an equivalent static renderer) is
26
+ * usable from the `react-server` condition without a separate bundle.
27
+ */ export function reactDomServerInRsc() {
28
+ const RESOLVED_ID = '\0payload:react-dom-server-rsc';
29
+ let bundledCode;
30
+ const buildBundle = ()=>{
31
+ if (bundledCode !== undefined) {
32
+ return bundledCode;
33
+ }
34
+ // esbuild is always present as a Vite dependency. Typed loosely because it
35
+ // isn't a direct dependency of this package.
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ const esbuild = require('esbuild');
38
+ const result = esbuild.buildSync({
39
+ banner: {
40
+ // The bundled CJS React DOM server build does `require('util')` etc.
41
+ // esbuild's ESM output otherwise emits a stub that throws "Dynamic
42
+ // require of ... is not supported" inside Vite's module runner, so wire
43
+ // up a real `require` for Node built-ins.
44
+ js: "import { createRequire as __pl_cr } from 'node:module';const require = __pl_cr(import.meta.url);"
45
+ },
46
+ bundle: true,
47
+ // Resolve react/react-dom to their CLIENT builds — NOT the `react-server`
48
+ // condition the RSC environment would otherwise apply.
49
+ conditions: [
50
+ 'node',
51
+ 'import',
52
+ 'default'
53
+ ],
54
+ define: {
55
+ 'process.env.NODE_ENV': JSON.stringify('production')
56
+ },
57
+ format: 'esm',
58
+ platform: 'node',
59
+ stdin: {
60
+ contents: [
61
+ "import * as ReactDOMServer from 'react-dom/server'",
62
+ "export * from 'react-dom/server'",
63
+ 'export default ReactDOMServer'
64
+ ].join('\n'),
65
+ loader: 'js',
66
+ resolveDir: process.cwd()
67
+ },
68
+ write: false
69
+ });
70
+ const code = result.outputFiles[0].text;
71
+ bundledCode = code;
72
+ return code;
73
+ };
74
+ return {
75
+ name: 'payload:react-dom-server-in-rsc',
76
+ enforce: 'pre',
77
+ load (id) {
78
+ if (id === RESOLVED_ID) {
79
+ return buildBundle();
80
+ }
81
+ },
82
+ resolveId (id) {
83
+ if (this.environment?.name === 'rsc' && REACT_DOM_SERVER_RE.test(id)) {
84
+ return RESOLVED_ID;
85
+ }
86
+ }
87
+ };
88
+ }
89
+
90
+ //# sourceMappingURL=reactDomServerInRsc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/withPayload/workarounds/reactDomServerInRsc.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\nimport { createRequire } from 'node:module'\n\nconst require = createRequire(import.meta.url)\n\nconst REACT_DOM_SERVER_RE = /^react-dom\\/server(?:\\.(?:edge|node|browser))?$/\n\n/**\n * Provides a working `react-dom/server` inside the RSC environment.\n *\n * Payload's version-diff converters (`@payloadcms/richtext-lexical`'s\n * `field/Diff/converters/*` and `@payloadcms/ui`'s `Version/RenderFieldsToDiff`)\n * call `renderToStaticMarkup` while rendering a Server Component. In the RSC\n * environment Vite activates the `react-server` export condition, under which\n * every `react-dom/server*` subpath resolves to `server.react-server.js` — a\n * stub that throws `react-dom/server is not supported in React Server\n * Components`. Force-resolving past the condition isn't enough either: the\n * static renderer reads the *client* React internals\n * (`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`), which\n * the `react-server` build of `react` doesn't expose.\n *\n * So we pre-bundle a self-contained `react-dom/server` with client React\n * inlined (esbuild, deliberately WITHOUT the `react-server` condition) and\n * redirect `react-dom/server` to it in the RSC graph only. The bundle is fully\n * self-contained, so the RSC environment's `react-server` condition can't\n * reach into it. JSX elements created by the RSC-graph React stay renderable\n * because React identifies elements via a process-global `Symbol.for(...)`.\n *\n * Delete this once `react-dom/server` (or an equivalent static renderer) is\n * usable from the `react-server` condition without a separate bundle.\n */\nexport function reactDomServerInRsc(): PluginOption {\n const RESOLVED_ID = '\\0payload:react-dom-server-rsc'\n let bundledCode: string | undefined\n\n const buildBundle = (): string => {\n if (bundledCode !== undefined) {\n return bundledCode\n }\n // esbuild is always present as a Vite dependency. Typed loosely because it\n // isn't a direct dependency of this package.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const esbuild: any = require('esbuild')\n const result = esbuild.buildSync({\n banner: {\n // The bundled CJS React DOM server build does `require('util')` etc.\n // esbuild's ESM output otherwise emits a stub that throws \"Dynamic\n // require of ... is not supported\" inside Vite's module runner, so wire\n // up a real `require` for Node built-ins.\n js: \"import { createRequire as __pl_cr } from 'node:module';const require = __pl_cr(import.meta.url);\",\n },\n bundle: true,\n // Resolve react/react-dom to their CLIENT builds — NOT the `react-server`\n // condition the RSC environment would otherwise apply.\n conditions: ['node', 'import', 'default'],\n define: { 'process.env.NODE_ENV': JSON.stringify('production') },\n format: 'esm',\n platform: 'node',\n stdin: {\n contents: [\n \"import * as ReactDOMServer from 'react-dom/server'\",\n \"export * from 'react-dom/server'\",\n 'export default ReactDOMServer',\n ].join('\\n'),\n loader: 'js',\n resolveDir: process.cwd(),\n },\n write: false,\n })\n const code = result.outputFiles[0].text as string\n bundledCode = code\n return code\n }\n\n return {\n name: 'payload:react-dom-server-in-rsc',\n enforce: 'pre',\n load(id) {\n if (id === RESOLVED_ID) {\n return buildBundle()\n }\n },\n resolveId(id) {\n if ((this as any).environment?.name === 'rsc' && REACT_DOM_SERVER_RE.test(id)) {\n return RESOLVED_ID\n }\n },\n }\n}\n"],"names":["createRequire","require","url","REACT_DOM_SERVER_RE","reactDomServerInRsc","RESOLVED_ID","bundledCode","buildBundle","undefined","esbuild","result","buildSync","banner","js","bundle","conditions","define","JSON","stringify","format","platform","stdin","contents","join","loader","resolveDir","process","cwd","write","code","outputFiles","text","name","enforce","load","id","resolveId","environment","test"],"mappings":"AAEA,SAASA,aAAa,QAAQ,cAAa;AAE3C,MAAMC,UAAUD,cAAc,YAAYE,GAAG;AAE7C,MAAMC,sBAAsB;AAE5B;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC;IACd,MAAMC,cAAc;IACpB,IAAIC;IAEJ,MAAMC,cAAc;QAClB,IAAID,gBAAgBE,WAAW;YAC7B,OAAOF;QACT;QACA,2EAA2E;QAC3E,6CAA6C;QAC7C,8DAA8D;QAC9D,MAAMG,UAAeR,QAAQ;QAC7B,MAAMS,SAASD,QAAQE,SAAS,CAAC;YAC/BC,QAAQ;gBACN,qEAAqE;gBACrE,mEAAmE;gBACnE,wEAAwE;gBACxE,0CAA0C;gBAC1CC,IAAI;YACN;YACAC,QAAQ;YACR,0EAA0E;YAC1E,uDAAuD;YACvDC,YAAY;gBAAC;gBAAQ;gBAAU;aAAU;YACzCC,QAAQ;gBAAE,wBAAwBC,KAAKC,SAAS,CAAC;YAAc;YAC/DC,QAAQ;YACRC,UAAU;YACVC,OAAO;gBACLC,UAAU;oBACR;oBACA;oBACA;iBACD,CAACC,IAAI,CAAC;gBACPC,QAAQ;gBACRC,YAAYC,QAAQC,GAAG;YACzB;YACAC,OAAO;QACT;QACA,MAAMC,OAAOnB,OAAOoB,WAAW,CAAC,EAAE,CAACC,IAAI;QACvCzB,cAAcuB;QACd,OAAOA;IACT;IAEA,OAAO;QACLG,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAIA,OAAO9B,aAAa;gBACtB,OAAOE;YACT;QACF;QACA6B,WAAUD,EAAE;YACV,IAAI,AAAC,IAAI,CAASE,WAAW,EAAEL,SAAS,SAAS7B,oBAAoBmC,IAAI,CAACH,KAAK;gBAC7E,OAAO9B;YACT;QACF;IACF;AACF"}
@@ -0,0 +1,21 @@
1
+ import type { PluginOption } from 'vite';
2
+ /**
3
+ * Stops Vite (and the underlying Node ESM loader) from trying to load
4
+ * SCSS/CSS/LESS during SSR/RSC when the importer lives inside a built
5
+ * `dist/` directory or when the specifier is a bare package name.
6
+ *
7
+ * We do this two ways, because either layer can fail:
8
+ *
9
+ * 1. `resolveId` redirects style specifiers to a virtual empty module —
10
+ * handles cases where Vite asks us to resolve them.
11
+ * 2. `transform` strips top-level `import './x.css'` statements out of any
12
+ * JS/TS file living under `node_modules/.../dist/` for non-client envs.
13
+ * This is the bulletproof path for prod-packed `@payloadcms/ui` (and
14
+ * similar) dependencies that get pre-bundled by Vite's SSR/RSC dep
15
+ * optimizer (esbuild). Esbuild preserves `.css` import statements as-is,
16
+ * and Node's native ESM loader then crashes with
17
+ * `Unknown file extension ".css"`. Removing them at the source avoids
18
+ * that entirely.
19
+ */
20
+ export declare function ssrStripDistStyleImports(): PluginOption;
21
+ //# sourceMappingURL=stripDistStyleImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripDistStyleImports.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/stripDistStyleImports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAsDxC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,IAAI,YAAY,CAyEvD"}
@@ -0,0 +1,140 @@
1
+ const STYLE_EXTENSION_RE = /\.(?:s?css|less)$/i;
2
+ /**
3
+ * Static `import './foo.css'` (or .scss/.less) — top-level only.
4
+ * Captures the entire statement so we can replace it with an empty line.
5
+ *
6
+ * Matches:
7
+ * import './foo.css';
8
+ * import "../bar.scss"
9
+ * import './baz.less' ;
10
+ */ const STATIC_STYLE_IMPORT_RE = /^[ \t]*import\s+['"][^'"]+\.(?:s?css|less)['"]\s*(?:;[ \t]*)?$/gm;
11
+ /**
12
+ * Monorepo Payload package source, e.g. `…/packages/ui/src/…`. In the
13
+ * core-dev / test setup Payload packages resolve to their workspace `src`
14
+ * (not a published `dist`), so the `dist/` rule below doesn't cover them and
15
+ * their `.css` side-effect imports survive into the SSR/RSC graph.
16
+ */ const PAYLOAD_PKG_SRC_RE = /\/packages\/[^/]+\/src\//;
17
+ /**
18
+ * The version-diff component trees — matched in either published `dist/` or
19
+ * workspace `src/` form. The `.css` side-effect imports of these must be
20
+ * stripped in the RSC env (the rest of `@payloadcms/ui` must NOT be — see the
21
+ * note in `resolveId`/`transform` below), for two reasons rooted in the same
22
+ * `@vitejs/plugin-rsc` behaviour: it wraps every exported CSS-importing
23
+ * component with an async CSS-collector child
24
+ * (`__vite_rsc_wrap_css__` → `await import('virtual:vite-rsc/css?…')`).
25
+ *
26
+ * 1. Correctness: the diff converters render `CheckIcon` (`icons/*`) and `File`
27
+ * (`graphics/*`) through the SYNCHRONOUS `renderToStaticMarkup` (see
28
+ * `reactDomServerInRsc`). The async wrapper suspends, crashing that render
29
+ * with "A component suspended while responding to synchronous input" and
30
+ * taking down the entire field-diffs tree.
31
+ * 2. Performance: the diff view (`views/Version/*` — `RenderFieldsToDiff` and
32
+ * its per-field components, `DiffCollapser`, `SelectComparison`, the
33
+ * `Default` template — plus the `HTMLDiff`/`FieldDiffContainer`/
34
+ * `FieldDiffLabel` elements and lexical's `field/Diff/*`) renders dozens of
35
+ * these wrapped components in the Flight stream. Each async CSS import
36
+ * serializes a round-trip, ballooning the render from ~3s to ~25s and
37
+ * blowing past the e2e waits. Stripping them collapses it back to ~3s.
38
+ *
39
+ * Safe because every one of these components' styles also ship in the global
40
+ * `@payloadcms/ui/css/app.css` the admin imports, so dropping the per-module
41
+ * RSC collection here changes nothing visually (verified: diff + Nav stay
42
+ * styled). The admin `Nav` etc. are deliberately excluded — they rely on the
43
+ * RSC collection and a broad strip leaves them unstyled.
44
+ */ const DIFF_VIEW_COMPONENT_RE = /@payloadcms\/ui\/(?:dist|src)\/(?:icons|graphics|views\/Version|elements\/(?:HTMLDiff|FieldDiffContainer|FieldDiffLabel))\/|@payloadcms\/richtext-lexical\/(?:dist|src)\/field\/Diff\//;
45
+ /**
46
+ * Stops Vite (and the underlying Node ESM loader) from trying to load
47
+ * SCSS/CSS/LESS during SSR/RSC when the importer lives inside a built
48
+ * `dist/` directory or when the specifier is a bare package name.
49
+ *
50
+ * We do this two ways, because either layer can fail:
51
+ *
52
+ * 1. `resolveId` redirects style specifiers to a virtual empty module —
53
+ * handles cases where Vite asks us to resolve them.
54
+ * 2. `transform` strips top-level `import './x.css'` statements out of any
55
+ * JS/TS file living under `node_modules/.../dist/` for non-client envs.
56
+ * This is the bulletproof path for prod-packed `@payloadcms/ui` (and
57
+ * similar) dependencies that get pre-bundled by Vite's SSR/RSC dep
58
+ * optimizer (esbuild). Esbuild preserves `.css` import statements as-is,
59
+ * and Node's native ESM loader then crashes with
60
+ * `Unknown file extension ".css"`. Removing them at the source avoids
61
+ * that entirely.
62
+ */ export function ssrStripDistStyleImports() {
63
+ return {
64
+ name: 'payload:ssr-strip-dist-style-imports',
65
+ enforce: 'pre',
66
+ load (id) {
67
+ if (id === '\0ssr-empty-style') {
68
+ return '';
69
+ }
70
+ },
71
+ resolveId (id, importer, options) {
72
+ const envName = this.environment?.name;
73
+ const isServerEnv = options?.ssr || envName && envName !== 'client';
74
+ if (!isServerEnv) {
75
+ return;
76
+ }
77
+ // Do NOT strip in the RSC environment. Server components (e.g. the admin
78
+ // `Nav`, a non-'use client' component that `import './index.css'`) render
79
+ // in the RSC graph, and `@vitejs/plugin-rsc` must SEE their `.css` imports
80
+ // there to collect them as client stylesheets. Stripping them here means
81
+ // their CSS is never emitted and the admin renders unstyled (broken nav
82
+ // scroll/layout, etc.). The Node-side `.css` no-op is handled by
83
+ // the test dev server's asset loader and by Vite's CSS extraction (build), so the
84
+ // crash this plugin guards against does not require touching the RSC env.
85
+ if (envName === 'rsc') {
86
+ return;
87
+ }
88
+ if (!STYLE_EXTENSION_RE.test(id)) {
89
+ return;
90
+ }
91
+ if (importer && (/\/dist\//.test(importer) || PAYLOAD_PKG_SRC_RE.test(importer))) {
92
+ return '\0ssr-empty-style';
93
+ }
94
+ if (/^@?[a-z]/.test(id) && !id.startsWith('.') && !id.startsWith('/')) {
95
+ return '\0ssr-empty-style';
96
+ }
97
+ },
98
+ transform (code, id) {
99
+ const envName = this.environment?.name;
100
+ const isServerEnv = envName && envName !== 'client';
101
+ if (!isServerEnv) {
102
+ return;
103
+ }
104
+ // In the RSC env, only strip from the version-diff component trees (see
105
+ // `DIFF_VIEW_COMPONENT_RE`). Every other server component (the admin
106
+ // `Nav`, etc.) must keep its `.css` import so plugin-rsc can collect it —
107
+ // see the matching note in `resolveId` above.
108
+ if (envName === 'rsc' && !DIFF_VIEW_COMPONENT_RE.test(id)) {
109
+ return;
110
+ }
111
+ // Only touch Payload dependency files: published `node_modules/.../dist/`
112
+ // builds, or workspace `…/packages/<pkg>/src/…` sources in the core-dev /
113
+ // test setup. Don't strip from the consumer's own app source — devs may
114
+ // legitimately want SSR-rendered <link>s from their own CSS imports.
115
+ const isPayloadDistFile = /\/node_modules\//.test(id) && /\/dist\//.test(id);
116
+ const isPayloadSrcFile = PAYLOAD_PKG_SRC_RE.test(id);
117
+ if (!isPayloadDistFile && !isPayloadSrcFile) {
118
+ return;
119
+ }
120
+ // Allow a trailing query (`?v=…`, `?t=…`): Vite appends version/timestamp
121
+ // queries to module ids, especially in the RSC graph, so a strict `$`
122
+ // anchor would skip e.g. `icons/Check/index.js?v=83de8543`.
123
+ if (!/\.[mc]?[jt]sx?(?:$|\?)/.test(id)) {
124
+ return;
125
+ }
126
+ if (!STATIC_STYLE_IMPORT_RE.test(code)) {
127
+ STATIC_STYLE_IMPORT_RE.lastIndex = 0;
128
+ return;
129
+ }
130
+ STATIC_STYLE_IMPORT_RE.lastIndex = 0;
131
+ const stripped = code.replace(STATIC_STYLE_IMPORT_RE, '');
132
+ return {
133
+ code: stripped,
134
+ map: null
135
+ };
136
+ }
137
+ };
138
+ }
139
+
140
+ //# sourceMappingURL=stripDistStyleImports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/withPayload/workarounds/stripDistStyleImports.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\nconst STYLE_EXTENSION_RE = /\\.(?:s?css|less)$/i\n\n/**\n * Static `import './foo.css'` (or .scss/.less) — top-level only.\n * Captures the entire statement so we can replace it with an empty line.\n *\n * Matches:\n * import './foo.css';\n * import \"../bar.scss\"\n * import './baz.less' ;\n */\nconst STATIC_STYLE_IMPORT_RE = /^[ \\t]*import\\s+['\"][^'\"]+\\.(?:s?css|less)['\"]\\s*(?:;[ \\t]*)?$/gm\n\n/**\n * Monorepo Payload package source, e.g. `…/packages/ui/src/…`. In the\n * core-dev / test setup Payload packages resolve to their workspace `src`\n * (not a published `dist`), so the `dist/` rule below doesn't cover them and\n * their `.css` side-effect imports survive into the SSR/RSC graph.\n */\nconst PAYLOAD_PKG_SRC_RE = /\\/packages\\/[^/]+\\/src\\//\n\n/**\n * The version-diff component trees — matched in either published `dist/` or\n * workspace `src/` form. The `.css` side-effect imports of these must be\n * stripped in the RSC env (the rest of `@payloadcms/ui` must NOT be — see the\n * note in `resolveId`/`transform` below), for two reasons rooted in the same\n * `@vitejs/plugin-rsc` behaviour: it wraps every exported CSS-importing\n * component with an async CSS-collector child\n * (`__vite_rsc_wrap_css__` → `await import('virtual:vite-rsc/css?…')`).\n *\n * 1. Correctness: the diff converters render `CheckIcon` (`icons/*`) and `File`\n * (`graphics/*`) through the SYNCHRONOUS `renderToStaticMarkup` (see\n * `reactDomServerInRsc`). The async wrapper suspends, crashing that render\n * with \"A component suspended while responding to synchronous input\" and\n * taking down the entire field-diffs tree.\n * 2. Performance: the diff view (`views/Version/*` — `RenderFieldsToDiff` and\n * its per-field components, `DiffCollapser`, `SelectComparison`, the\n * `Default` template — plus the `HTMLDiff`/`FieldDiffContainer`/\n * `FieldDiffLabel` elements and lexical's `field/Diff/*`) renders dozens of\n * these wrapped components in the Flight stream. Each async CSS import\n * serializes a round-trip, ballooning the render from ~3s to ~25s and\n * blowing past the e2e waits. Stripping them collapses it back to ~3s.\n *\n * Safe because every one of these components' styles also ship in the global\n * `@payloadcms/ui/css/app.css` the admin imports, so dropping the per-module\n * RSC collection here changes nothing visually (verified: diff + Nav stay\n * styled). The admin `Nav` etc. are deliberately excluded — they rely on the\n * RSC collection and a broad strip leaves them unstyled.\n */\nconst DIFF_VIEW_COMPONENT_RE =\n /@payloadcms\\/ui\\/(?:dist|src)\\/(?:icons|graphics|views\\/Version|elements\\/(?:HTMLDiff|FieldDiffContainer|FieldDiffLabel))\\/|@payloadcms\\/richtext-lexical\\/(?:dist|src)\\/field\\/Diff\\//\n\n/**\n * Stops Vite (and the underlying Node ESM loader) from trying to load\n * SCSS/CSS/LESS during SSR/RSC when the importer lives inside a built\n * `dist/` directory or when the specifier is a bare package name.\n *\n * We do this two ways, because either layer can fail:\n *\n * 1. `resolveId` redirects style specifiers to a virtual empty module —\n * handles cases where Vite asks us to resolve them.\n * 2. `transform` strips top-level `import './x.css'` statements out of any\n * JS/TS file living under `node_modules/.../dist/` for non-client envs.\n * This is the bulletproof path for prod-packed `@payloadcms/ui` (and\n * similar) dependencies that get pre-bundled by Vite's SSR/RSC dep\n * optimizer (esbuild). Esbuild preserves `.css` import statements as-is,\n * and Node's native ESM loader then crashes with\n * `Unknown file extension \".css\"`. Removing them at the source avoids\n * that entirely.\n */\nexport function ssrStripDistStyleImports(): PluginOption {\n return {\n name: 'payload:ssr-strip-dist-style-imports',\n enforce: 'pre',\n load(id) {\n if (id === '\\0ssr-empty-style') {\n return ''\n }\n },\n resolveId(id, importer, options) {\n const envName = (this as any).environment?.name as string | undefined\n const isServerEnv = options?.ssr || (envName && envName !== 'client')\n if (!isServerEnv) {\n return\n }\n // Do NOT strip in the RSC environment. Server components (e.g. the admin\n // `Nav`, a non-'use client' component that `import './index.css'`) render\n // in the RSC graph, and `@vitejs/plugin-rsc` must SEE their `.css` imports\n // there to collect them as client stylesheets. Stripping them here means\n // their CSS is never emitted and the admin renders unstyled (broken nav\n // scroll/layout, etc.). The Node-side `.css` no-op is handled by\n // the test dev server's asset loader and by Vite's CSS extraction (build), so the\n // crash this plugin guards against does not require touching the RSC env.\n if (envName === 'rsc') {\n return\n }\n if (!STYLE_EXTENSION_RE.test(id)) {\n return\n }\n if (importer && (/\\/dist\\//.test(importer) || PAYLOAD_PKG_SRC_RE.test(importer))) {\n return '\\0ssr-empty-style'\n }\n if (/^@?[a-z]/.test(id) && !id.startsWith('.') && !id.startsWith('/')) {\n return '\\0ssr-empty-style'\n }\n },\n transform(code, id) {\n const envName = (this as any).environment?.name as string | undefined\n const isServerEnv = envName && envName !== 'client'\n if (!isServerEnv) {\n return\n }\n // In the RSC env, only strip from the version-diff component trees (see\n // `DIFF_VIEW_COMPONENT_RE`). Every other server component (the admin\n // `Nav`, etc.) must keep its `.css` import so plugin-rsc can collect it —\n // see the matching note in `resolveId` above.\n if (envName === 'rsc' && !DIFF_VIEW_COMPONENT_RE.test(id)) {\n return\n }\n // Only touch Payload dependency files: published `node_modules/.../dist/`\n // builds, or workspace `…/packages/<pkg>/src/…` sources in the core-dev /\n // test setup. Don't strip from the consumer's own app source — devs may\n // legitimately want SSR-rendered <link>s from their own CSS imports.\n const isPayloadDistFile = /\\/node_modules\\//.test(id) && /\\/dist\\//.test(id)\n const isPayloadSrcFile = PAYLOAD_PKG_SRC_RE.test(id)\n if (!isPayloadDistFile && !isPayloadSrcFile) {\n return\n }\n // Allow a trailing query (`?v=…`, `?t=…`): Vite appends version/timestamp\n // queries to module ids, especially in the RSC graph, so a strict `$`\n // anchor would skip e.g. `icons/Check/index.js?v=83de8543`.\n if (!/\\.[mc]?[jt]sx?(?:$|\\?)/.test(id)) {\n return\n }\n if (!STATIC_STYLE_IMPORT_RE.test(code)) {\n STATIC_STYLE_IMPORT_RE.lastIndex = 0\n return\n }\n STATIC_STYLE_IMPORT_RE.lastIndex = 0\n const stripped = code.replace(STATIC_STYLE_IMPORT_RE, '')\n return { code: stripped, map: null }\n },\n }\n}\n"],"names":["STYLE_EXTENSION_RE","STATIC_STYLE_IMPORT_RE","PAYLOAD_PKG_SRC_RE","DIFF_VIEW_COMPONENT_RE","ssrStripDistStyleImports","name","enforce","load","id","resolveId","importer","options","envName","environment","isServerEnv","ssr","test","startsWith","transform","code","isPayloadDistFile","isPayloadSrcFile","lastIndex","stripped","replace","map"],"mappings":"AAEA,MAAMA,qBAAqB;AAE3B;;;;;;;;CAQC,GACD,MAAMC,yBAAyB;AAE/B;;;;;CAKC,GACD,MAAMC,qBAAqB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GACD,MAAMC,yBACJ;AAEF;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC;IACd,OAAO;QACLC,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAIA,OAAO,qBAAqB;gBAC9B,OAAO;YACT;QACF;QACAC,WAAUD,EAAE,EAAEE,QAAQ,EAAEC,OAAO;YAC7B,MAAMC,UAAU,AAAC,IAAI,CAASC,WAAW,EAAER;YAC3C,MAAMS,cAAcH,SAASI,OAAQH,WAAWA,YAAY;YAC5D,IAAI,CAACE,aAAa;gBAChB;YACF;YACA,yEAAyE;YACzE,0EAA0E;YAC1E,2EAA2E;YAC3E,yEAAyE;YACzE,wEAAwE;YACxE,iEAAiE;YACjE,kFAAkF;YAClF,0EAA0E;YAC1E,IAAIF,YAAY,OAAO;gBACrB;YACF;YACA,IAAI,CAACZ,mBAAmBgB,IAAI,CAACR,KAAK;gBAChC;YACF;YACA,IAAIE,YAAa,CAAA,WAAWM,IAAI,CAACN,aAAaR,mBAAmBc,IAAI,CAACN,SAAQ,GAAI;gBAChF,OAAO;YACT;YACA,IAAI,WAAWM,IAAI,CAACR,OAAO,CAACA,GAAGS,UAAU,CAAC,QAAQ,CAACT,GAAGS,UAAU,CAAC,MAAM;gBACrE,OAAO;YACT;QACF;QACAC,WAAUC,IAAI,EAAEX,EAAE;YAChB,MAAMI,UAAU,AAAC,IAAI,CAASC,WAAW,EAAER;YAC3C,MAAMS,cAAcF,WAAWA,YAAY;YAC3C,IAAI,CAACE,aAAa;gBAChB;YACF;YACA,wEAAwE;YACxE,qEAAqE;YACrE,0EAA0E;YAC1E,8CAA8C;YAC9C,IAAIF,YAAY,SAAS,CAACT,uBAAuBa,IAAI,CAACR,KAAK;gBACzD;YACF;YACA,0EAA0E;YAC1E,0EAA0E;YAC1E,wEAAwE;YACxE,qEAAqE;YACrE,MAAMY,oBAAoB,mBAAmBJ,IAAI,CAACR,OAAO,WAAWQ,IAAI,CAACR;YACzE,MAAMa,mBAAmBnB,mBAAmBc,IAAI,CAACR;YACjD,IAAI,CAACY,qBAAqB,CAACC,kBAAkB;gBAC3C;YACF;YACA,0EAA0E;YAC1E,sEAAsE;YACtE,4DAA4D;YAC5D,IAAI,CAAC,yBAAyBL,IAAI,CAACR,KAAK;gBACtC;YACF;YACA,IAAI,CAACP,uBAAuBe,IAAI,CAACG,OAAO;gBACtClB,uBAAuBqB,SAAS,GAAG;gBACnC;YACF;YACArB,uBAAuBqB,SAAS,GAAG;YACnC,MAAMC,WAAWJ,KAAKK,OAAO,CAACvB,wBAAwB;YACtD,OAAO;gBAAEkB,MAAMI;gBAAUE,KAAK;YAAK;QACrC;IACF;AACF"}
@@ -0,0 +1,13 @@
1
+ import type { PluginOption } from 'vite';
2
+ /**
3
+ * Stubs `prettier` in the CLIENT bundle only.
4
+ *
5
+ * `payload`'s barrel transitively pulls `json-schema-to-typescript` → `prettier`
6
+ * (CommonJS) into the client graph. That path is type-gen only and never runs in
7
+ * the browser, but the bundler still drags in `prettier`'s `index.cjs`, which
8
+ * fails to parse as ESM and breaks the client build. SSR/RSC keep real prettier.
9
+ *
10
+ * Delete once `payload`'s barrel no longer reaches type-gen from the client graph.
11
+ */
12
+ export declare function stubPrettierInClient(): PluginOption;
13
+ //# sourceMappingURL=stubPrettierInClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stubPrettierInClient.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/stubPrettierInClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAqBnD"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Stubs `prettier` in the CLIENT bundle only.
3
+ *
4
+ * `payload`'s barrel transitively pulls `json-schema-to-typescript` → `prettier`
5
+ * (CommonJS) into the client graph. That path is type-gen only and never runs in
6
+ * the browser, but the bundler still drags in `prettier`'s `index.cjs`, which
7
+ * fails to parse as ESM and breaks the client build. SSR/RSC keep real prettier.
8
+ *
9
+ * Delete once `payload`'s barrel no longer reaches type-gen from the client graph.
10
+ */ export function stubPrettierInClient() {
11
+ const RESOLVED_ID = '\0payload:prettier-client-stub';
12
+ return {
13
+ name: 'payload:stub-prettier-in-client',
14
+ enforce: 'pre',
15
+ load (id) {
16
+ if (id === RESOLVED_ID) {
17
+ return 'export const format = (source) => source;\nexport default { format };';
18
+ }
19
+ },
20
+ resolveId (id, importer, options) {
21
+ if (options?.ssr) {
22
+ return;
23
+ }
24
+ // Only stub the type-gen import; leave a host's own client `prettier` alone.
25
+ if (id === 'prettier' && importer?.includes('json-schema-to-typescript')) {
26
+ return RESOLVED_ID;
27
+ }
28
+ }
29
+ };
30
+ }
31
+
32
+ //# sourceMappingURL=stubPrettierInClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/withPayload/workarounds/stubPrettierInClient.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Stubs `prettier` in the CLIENT bundle only.\n *\n * `payload`'s barrel transitively pulls `json-schema-to-typescript` → `prettier`\n * (CommonJS) into the client graph. That path is type-gen only and never runs in\n * the browser, but the bundler still drags in `prettier`'s `index.cjs`, which\n * fails to parse as ESM and breaks the client build. SSR/RSC keep real prettier.\n *\n * Delete once `payload`'s barrel no longer reaches type-gen from the client graph.\n */\nexport function stubPrettierInClient(): PluginOption {\n const RESOLVED_ID = '\\0payload:prettier-client-stub'\n\n return {\n name: 'payload:stub-prettier-in-client',\n enforce: 'pre',\n load(id) {\n if (id === RESOLVED_ID) {\n return 'export const format = (source) => source;\\nexport default { format };'\n }\n },\n resolveId(id, importer, options) {\n if (options?.ssr) {\n return\n }\n // Only stub the type-gen import; leave a host's own client `prettier` alone.\n if (id === 'prettier' && importer?.includes('json-schema-to-typescript')) {\n return RESOLVED_ID\n }\n },\n }\n}\n"],"names":["stubPrettierInClient","RESOLVED_ID","name","enforce","load","id","resolveId","importer","options","ssr","includes"],"mappings":"AAEA;;;;;;;;;CASC,GACD,OAAO,SAASA;IACd,MAAMC,cAAc;IAEpB,OAAO;QACLC,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAIA,OAAOJ,aAAa;gBACtB,OAAO;YACT;QACF;QACAK,WAAUD,EAAE,EAAEE,QAAQ,EAAEC,OAAO;YAC7B,IAAIA,SAASC,KAAK;gBAChB;YACF;YACA,6EAA6E;YAC7E,IAAIJ,OAAO,cAAcE,UAAUG,SAAS,8BAA8B;gBACxE,OAAOT;YACT;QACF;IACF;AACF"}