@payloadcms/tanstack-start 4.0.0-internal.a0ef1b8 → 4.0.0-internal.fa345ef

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 (127) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/elements/RouterAdapter/index.d.ts.map +1 -1
  3. package/dist/elements/RouterAdapter/index.js +38 -15
  4. package/dist/elements/RouterAdapter/index.js.map +1 -1
  5. package/dist/exports/client.d.ts +4 -0
  6. package/dist/exports/client.d.ts.map +1 -1
  7. package/dist/exports/client.js +4 -0
  8. package/dist/exports/client.js.map +1 -1
  9. package/dist/exports/layouts.d.ts +1 -0
  10. package/dist/exports/layouts.d.ts.map +1 -1
  11. package/dist/exports/layouts.js +1 -0
  12. package/dist/exports/layouts.js.map +1 -1
  13. package/dist/exports/server.d.ts +2 -1
  14. package/dist/exports/server.d.ts.map +1 -1
  15. package/dist/exports/server.js +2 -1
  16. package/dist/exports/server.js.map +1 -1
  17. package/dist/exports/vite.d.ts +12 -2
  18. package/dist/exports/vite.d.ts.map +1 -1
  19. package/dist/exports/vite.js +8 -1
  20. package/dist/exports/vite.js.map +1 -1
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
  26. package/dist/layouts/Root/getLayoutData.js +36 -0
  27. package/dist/layouts/Root/getLayoutData.js.map +1 -1
  28. package/dist/layouts/Root/index.d.ts +9 -2
  29. package/dist/layouts/Root/index.d.ts.map +1 -1
  30. package/dist/layouts/Root/index.js.map +1 -1
  31. package/dist/layouts/Root/withPayloadRoot.d.ts +65 -0
  32. package/dist/layouts/Root/withPayloadRoot.d.ts.map +1 -0
  33. package/dist/layouts/Root/withPayloadRoot.js +92 -0
  34. package/dist/layouts/Root/withPayloadRoot.js.map +1 -0
  35. package/dist/routes/adminRoutes.d.ts +111 -0
  36. package/dist/routes/adminRoutes.d.ts.map +1 -0
  37. package/dist/routes/adminRoutes.js +108 -0
  38. package/dist/routes/adminRoutes.js.map +1 -0
  39. package/dist/routes/apiRoute.d.ts +29 -0
  40. package/dist/routes/apiRoute.d.ts.map +1 -0
  41. package/dist/routes/apiRoute.js +38 -0
  42. package/dist/routes/apiRoute.js.map +1 -0
  43. package/dist/routes/layoutRoute.d.ts +26 -0
  44. package/dist/routes/layoutRoute.d.ts.map +1 -0
  45. package/dist/routes/layoutRoute.js +57 -0
  46. package/dist/routes/layoutRoute.js.map +1 -0
  47. package/dist/utilities/handleAPIRoute.d.ts +11 -0
  48. package/dist/utilities/handleAPIRoute.d.ts.map +1 -0
  49. package/dist/utilities/handleAPIRoute.js +17 -0
  50. package/dist/utilities/handleAPIRoute.js.map +1 -0
  51. package/dist/utilities/importMap.server.d.ts +4 -5
  52. package/dist/utilities/importMap.server.d.ts.map +1 -1
  53. package/dist/utilities/importMap.server.js +5 -6
  54. package/dist/utilities/importMap.server.js.map +1 -1
  55. package/dist/utilities/loadAdminPage.d.ts +54 -0
  56. package/dist/utilities/loadAdminPage.d.ts.map +1 -0
  57. package/dist/utilities/loadAdminPage.js +230 -0
  58. package/dist/utilities/loadAdminPage.js.map +1 -0
  59. package/dist/utilities/loadLayoutData.d.ts +15 -0
  60. package/dist/utilities/loadLayoutData.d.ts.map +1 -0
  61. package/dist/utilities/loadLayoutData.js +23 -0
  62. package/dist/utilities/loadLayoutData.js.map +1 -0
  63. package/dist/utilities/serializeForRsc.d.ts.map +1 -1
  64. package/dist/utilities/serializeForRsc.js +17 -0
  65. package/dist/utilities/serializeForRsc.js.map +1 -1
  66. package/dist/utilities/serverFunctionClient.d.ts +29 -0
  67. package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
  68. package/dist/utilities/serverFunctionClient.js +109 -0
  69. package/dist/utilities/serverFunctionClient.js.map +1 -0
  70. package/dist/vite/config/external.d.ts +26 -0
  71. package/dist/vite/config/external.d.ts.map +1 -0
  72. package/dist/vite/config/external.js +57 -0
  73. package/dist/vite/config/external.js.map +1 -0
  74. package/dist/vite/config/optimizeDeps.d.ts +25 -0
  75. package/dist/vite/config/optimizeDeps.d.ts.map +1 -0
  76. package/dist/vite/config/optimizeDeps.js +123 -0
  77. package/dist/vite/config/optimizeDeps.js.map +1 -0
  78. package/dist/vite/index.d.ts +49 -0
  79. package/dist/vite/index.d.ts.map +1 -0
  80. package/dist/vite/{plugin.js → index.js} +57 -47
  81. package/dist/vite/index.js.map +1 -0
  82. package/dist/vite/workarounds/clientModuleResolution.d.ts.map +1 -0
  83. package/dist/vite/workarounds/clientModuleResolution.js.map +1 -0
  84. package/dist/vite/workarounds/devTransforms.d.ts +19 -0
  85. package/dist/vite/workarounds/devTransforms.d.ts.map +1 -0
  86. package/dist/vite/{plugins → workarounds}/devTransforms.js +13 -2
  87. package/dist/vite/workarounds/devTransforms.js.map +1 -0
  88. package/dist/vite/workarounds/reactDomServerInRsc.d.ts.map +1 -0
  89. package/dist/vite/workarounds/reactDomServerInRsc.js.map +1 -0
  90. package/dist/vite/workarounds/stripDistStyleImports.d.ts.map +1 -0
  91. package/dist/vite/workarounds/stripDistStyleImports.js +140 -0
  92. package/dist/vite/workarounds/stripDistStyleImports.js.map +1 -0
  93. package/dist/vite/workarounds/wrapCjsForClient.d.ts.map +1 -0
  94. package/dist/vite/workarounds/wrapCjsForClient.js.map +1 -0
  95. package/package.json +10 -12
  96. package/dist/@types/assets.d.js +0 -2
  97. package/dist/@types/assets.d.js.map +0 -1
  98. package/dist/auth/switchLanguage.d.ts +0 -6
  99. package/dist/auth/switchLanguage.d.ts.map +0 -1
  100. package/dist/auth/switchLanguage.js +0 -11
  101. package/dist/auth/switchLanguage.js.map +0 -1
  102. package/dist/vite/constants.d.ts +0 -37
  103. package/dist/vite/constants.d.ts.map +0 -1
  104. package/dist/vite/constants.js +0 -129
  105. package/dist/vite/constants.js.map +0 -1
  106. package/dist/vite/plugin.d.ts +0 -38
  107. package/dist/vite/plugin.d.ts.map +0 -1
  108. package/dist/vite/plugin.js.map +0 -1
  109. package/dist/vite/plugins/clientModuleResolution.d.ts.map +0 -1
  110. package/dist/vite/plugins/clientModuleResolution.js.map +0 -1
  111. package/dist/vite/plugins/devTransforms.d.ts +0 -8
  112. package/dist/vite/plugins/devTransforms.d.ts.map +0 -1
  113. package/dist/vite/plugins/devTransforms.js.map +0 -1
  114. package/dist/vite/plugins/reactDomServerInRsc.d.ts.map +0 -1
  115. package/dist/vite/plugins/reactDomServerInRsc.js.map +0 -1
  116. package/dist/vite/plugins/stripDistStyleImports.d.ts.map +0 -1
  117. package/dist/vite/plugins/stripDistStyleImports.js +0 -89
  118. package/dist/vite/plugins/stripDistStyleImports.js.map +0 -1
  119. package/dist/vite/plugins/wrapCjsForClient.d.ts.map +0 -1
  120. package/dist/vite/plugins/wrapCjsForClient.js.map +0 -1
  121. /package/dist/vite/{plugins → workarounds}/clientModuleResolution.d.ts +0 -0
  122. /package/dist/vite/{plugins → workarounds}/clientModuleResolution.js +0 -0
  123. /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.d.ts +0 -0
  124. /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.js +0 -0
  125. /package/dist/vite/{plugins → workarounds}/stripDistStyleImports.d.ts +0 -0
  126. /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.d.ts +0 -0
  127. /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.js +0 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * SSR/RSC externalization config used by `withPayload`. Kept separate from the
3
+ * client optimizer config (`./optimizeDeps.ts`) so each concern stays small.
4
+ */
5
+ /**
6
+ * Server-only packages (Node-only or only ever used by the server bundle).
7
+ * These are the Vite equivalent of Next.js's `serverExternalPackages`.
8
+ */
9
+ export declare const ssrExternalPackages: string[];
10
+ /**
11
+ * Payload packages whose source must be processed by Vite even on the server
12
+ * (because they are workspace `.ts` files in dev). Server-only adapters
13
+ * (`@payloadcms/db-*`, `@payloadcms/email-*`, `@payloadcms/next`, etc.) are
14
+ * intentionally not included — those should stay external on the SSR side.
15
+ *
16
+ * The same set is applied to BOTH the `ssr` and `rsc` environments. Plugins and
17
+ * storage adapters must be included in RSC too: they register custom
18
+ * providers/components (e.g. `plugin-multi-tenant`'s `'use client'`
19
+ * `TenantSelectionProvider`) that render in the RSC graph via
20
+ * `RenderServerComponent`. If the package stayed external to RSC, `plugin-rsc`
21
+ * would never transform its `'use client'` modules into client references, so
22
+ * the component would execute server-side and crash on the first hook
23
+ * (`Cannot read properties of null (reading 'useState')`).
24
+ */
25
+ export declare const payloadNoExternalPatterns: Array<RegExp | string>;
26
+ //# sourceMappingURL=external.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../../src/vite/config/external.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,EA0BvC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO5D,CAAA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * SSR/RSC externalization config used by `withPayload`. Kept separate from the
3
+ * client optimizer config (`./optimizeDeps.ts`) so each concern stays small.
4
+ */ /**
5
+ * Server-only packages (Node-only or only ever used by the server bundle).
6
+ * These are the Vite equivalent of Next.js's `serverExternalPackages`.
7
+ */ export const ssrExternalPackages = [
8
+ 'ajv',
9
+ 'fast-uri',
10
+ 'drizzle-kit',
11
+ 'drizzle-kit/api',
12
+ 'drizzle-orm',
13
+ 'sharp',
14
+ 'libsql',
15
+ 'require-in-the-middle',
16
+ 'json-schema-to-typescript',
17
+ 'pino',
18
+ 'pino-pretty',
19
+ 'graphql',
20
+ 'mongodb',
21
+ 'mongoose',
22
+ 'better-sqlite3',
23
+ 'pg',
24
+ 'pg-native',
25
+ 'nodemailer',
26
+ 'aws4',
27
+ 'pluralize',
28
+ 'console-table-printer',
29
+ '@azure/storage-blob',
30
+ '@aws-sdk/client-s3',
31
+ '@aws-sdk/s3-request-presigner',
32
+ '@google-cloud/storage'
33
+ ];
34
+ /**
35
+ * Payload packages whose source must be processed by Vite even on the server
36
+ * (because they are workspace `.ts` files in dev). Server-only adapters
37
+ * (`@payloadcms/db-*`, `@payloadcms/email-*`, `@payloadcms/next`, etc.) are
38
+ * intentionally not included — those should stay external on the SSR side.
39
+ *
40
+ * The same set is applied to BOTH the `ssr` and `rsc` environments. Plugins and
41
+ * storage adapters must be included in RSC too: they register custom
42
+ * providers/components (e.g. `plugin-multi-tenant`'s `'use client'`
43
+ * `TenantSelectionProvider`) that render in the RSC graph via
44
+ * `RenderServerComponent`. If the package stayed external to RSC, `plugin-rsc`
45
+ * would never transform its `'use client'` modules into client references, so
46
+ * the component would execute server-side and crash on the first hook
47
+ * (`Cannot read properties of null (reading 'useState')`).
48
+ */ export const payloadNoExternalPatterns = [
49
+ '@payloadcms/ui',
50
+ '@payloadcms/translations',
51
+ '@payloadcms/tanstack-start',
52
+ /^@payloadcms\/richtext-lexical/,
53
+ /^@payloadcms\/plugin-/,
54
+ /^@payloadcms\/storage-/
55
+ ];
56
+
57
+ //# sourceMappingURL=external.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/vite/config/external.ts"],"sourcesContent":["/**\n * SSR/RSC externalization config used by `withPayload`. Kept separate from the\n * client optimizer config (`./optimizeDeps.ts`) so each concern stays small.\n */\n\n/**\n * Server-only packages (Node-only or only ever used by the server bundle).\n * These are the Vite equivalent of Next.js's `serverExternalPackages`.\n */\nexport const ssrExternalPackages: string[] = [\n 'ajv',\n 'fast-uri',\n 'drizzle-kit',\n 'drizzle-kit/api',\n 'drizzle-orm',\n 'sharp',\n 'libsql',\n 'require-in-the-middle',\n 'json-schema-to-typescript',\n 'pino',\n 'pino-pretty',\n 'graphql',\n 'mongodb',\n 'mongoose',\n 'better-sqlite3',\n 'pg',\n 'pg-native',\n 'nodemailer',\n 'aws4',\n 'pluralize',\n 'console-table-printer',\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Payload packages whose source must be processed by Vite even on the server\n * (because they are workspace `.ts` files in dev). Server-only adapters\n * (`@payloadcms/db-*`, `@payloadcms/email-*`, `@payloadcms/next`, etc.) are\n * intentionally not included — those should stay external on the SSR side.\n *\n * The same set is applied to BOTH the `ssr` and `rsc` environments. Plugins and\n * storage adapters must be included in RSC too: they register custom\n * providers/components (e.g. `plugin-multi-tenant`'s `'use client'`\n * `TenantSelectionProvider`) that render in the RSC graph via\n * `RenderServerComponent`. If the package stayed external to RSC, `plugin-rsc`\n * would never transform its `'use client'` modules into client references, so\n * the component would execute server-side and crash on the first hook\n * (`Cannot read properties of null (reading 'useState')`).\n */\nexport const payloadNoExternalPatterns: Array<RegExp | string> = [\n '@payloadcms/ui',\n '@payloadcms/translations',\n '@payloadcms/tanstack-start',\n /^@payloadcms\\/richtext-lexical/,\n /^@payloadcms\\/plugin-/,\n /^@payloadcms\\/storage-/,\n]\n"],"names":["ssrExternalPackages","payloadNoExternalPatterns"],"mappings":"AAAA;;;CAGC,GAED;;;CAGC,GACD,OAAO,MAAMA,sBAAgC;IAC3C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,4BAAoD;IAC/D;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Client dep-optimizer config used by `withPayload`. Kept separate from the
3
+ * SSR/RSC externalization config (`./external.ts`) so each concern stays small.
4
+ */
5
+ /**
6
+ * Packages we know contain Node-only code or top-level side effects requiring
7
+ * Node APIs. Excluding them from the client optimizer prevents Vite from
8
+ * walking into their main entries and trying to bundle server-only imports
9
+ * for the browser.
10
+ */
11
+ export declare const optimizeDepsExcludeDefaults: string[];
12
+ /**
13
+ * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be
14
+ * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick
15
+ * these up because their parent packages are in `optimizeDeps.exclude`, so we
16
+ * list them explicitly using the `parent > child` syntax.
17
+ *
18
+ * Each entry below fixes a specific late-discovery re-optimization: without it,
19
+ * Vite discovers the dep *after* its initial crawl, forcing a full dep
20
+ * re-optimization mid-session that 404s in-flight `.vite/deps/*` chunks and
21
+ * remounts the admin (dropping client state). This is why the list can't simply
22
+ * be deleted — it is the "complete first pass" for the admin's dep graph.
23
+ */
24
+ export declare const optimizeDepsIncludeDefaults: string[];
25
+ //# sourceMappingURL=optimizeDeps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optimizeDeps.d.ts","sourceRoot":"","sources":["../../../src/vite/config/optimizeDeps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAsB/C,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EA8E/C,CAAA"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Client dep-optimizer config used by `withPayload`. Kept separate from the
3
+ * SSR/RSC externalization config (`./external.ts`) so each concern stays small.
4
+ */ /**
5
+ * Packages we know contain Node-only code or top-level side effects requiring
6
+ * Node APIs. Excluding them from the client optimizer prevents Vite from
7
+ * walking into their main entries and trying to bundle server-only imports
8
+ * for the browser.
9
+ */ export const optimizeDepsExcludeDefaults = [
10
+ 'sharp',
11
+ '@payloadcms/ui',
12
+ '@payloadcms/tanstack-start',
13
+ 'payload',
14
+ 'pino',
15
+ 'pino-pretty',
16
+ 'busboy',
17
+ 'get-tsconfig',
18
+ 'ws',
19
+ 'croner',
20
+ 'prompts',
21
+ 'file-type',
22
+ // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite
23
+ // sometimes walks these from the main package entry while scanning
24
+ // workspace deps, and the browser sub-bundles do not expose the
25
+ // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev
26
+ // server with a `MISSING_EXPORT` error before any test runs.
27
+ '@azure/storage-blob',
28
+ '@aws-sdk/client-s3',
29
+ '@aws-sdk/s3-request-presigner',
30
+ '@google-cloud/storage'
31
+ ];
32
+ /**
33
+ * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be
34
+ * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick
35
+ * these up because their parent packages are in `optimizeDeps.exclude`, so we
36
+ * list them explicitly using the `parent > child` syntax.
37
+ *
38
+ * Each entry below fixes a specific late-discovery re-optimization: without it,
39
+ * Vite discovers the dep *after* its initial crawl, forcing a full dep
40
+ * re-optimization mid-session that 404s in-flight `.vite/deps/*` chunks and
41
+ * remounts the admin (dropping client state). This is why the list can't simply
42
+ * be deleted — it is the "complete first pass" for the admin's dep graph.
43
+ */ export const optimizeDepsIncludeDefaults = [
44
+ '@payloadcms/ui > sonner',
45
+ '@payloadcms/ui > @faceless-ui/modal',
46
+ '@payloadcms/ui > @faceless-ui/window-info',
47
+ '@payloadcms/ui > @faceless-ui/scroll-info',
48
+ '@payloadcms/ui > @dnd-kit/core',
49
+ '@payloadcms/ui > @dnd-kit/sortable',
50
+ '@payloadcms/ui > @dnd-kit/utilities',
51
+ '@payloadcms/ui > react-datepicker',
52
+ '@payloadcms/ui > react-select',
53
+ '@payloadcms/ui > react-select/creatable',
54
+ '@payloadcms/ui > react-image-crop',
55
+ '@payloadcms/ui > @monaco-editor/react',
56
+ '@payloadcms/ui > date-fns',
57
+ '@payloadcms/ui > date-fns/transpose',
58
+ '@payloadcms/ui > @date-fns/tz/date/mini',
59
+ '@payloadcms/ui > uuid',
60
+ '@payloadcms/ui > use-context-selector',
61
+ '@payloadcms/ui > bson-objectid',
62
+ '@payloadcms/ui > dequal',
63
+ '@payloadcms/ui > object-to-formdata',
64
+ '@payloadcms/ui > md5',
65
+ 'payload > deepmerge',
66
+ 'payload > pluralize',
67
+ // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of
68
+ // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated
69
+ // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where
70
+ // it isn't hoisted to the top level. Path it through `react-dom` so the
71
+ // optimizer resolves the exact copy the runtime loads.
72
+ 'react-dom > scheduler',
73
+ // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the
74
+ // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.
75
+ // Because its parent is excluded, the optimizer never crawls in to discover
76
+ // this entry, so Vite serves `react/compiler-runtime` raw. That file is
77
+ // CommonJS (`module.exports = require(...)`), so the named `c` export can't be
78
+ // statically extracted and every client component throws "does not provide an
79
+ // export named 'c'". Pre-bundling it lets esbuild synthesize the named export.
80
+ 'react/compiler-runtime',
81
+ // Transitive deps that Vite otherwise discovers *after* the initial crawl
82
+ // (react-select pulls in @floating-ui at runtime; react-is is reached via
83
+ // react-transition-group/prop-types; the default date-fns locale is loaded
84
+ // through a dynamic `date-fns/locale/${key}` import). A late discovery forces
85
+ // a full dep re-optimization mid-session, which 404s every in-flight
86
+ // `.vite/deps/*` chunk ("Pre-transform error: file does not exist in the
87
+ // optimize deps directory") and breaks the admin UI in CI cold starts.
88
+ // Pre-bundling them keeps the first optimization pass complete.
89
+ '@payloadcms/ui > react-select > @floating-ui/dom',
90
+ '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',
91
+ '@payloadcms/ui > react-select > prop-types > react-is',
92
+ '@payloadcms/ui > date-fns/locale/en-US',
93
+ // Further late discoveries observed re-optimizing mid-run in CI cold starts
94
+ // (see CI logs: "✨ new dependencies optimized: @dnd-kit/modifiers / ajv /
95
+ // dequal/lite"). The modular dashboard pulls in `@dnd-kit/modifiers` on first
96
+ // render; form-state diffing reaches `dequal/lite` (a distinct entry point
97
+ // from the already-listed `dequal`); client-side field validation reaches
98
+ // `ajv` *through `payload`* — it is `ssrExternal` server-side but still
99
+ // bundled into the client, and must be pathed via `payload` so the optimizer
100
+ // pre-bundles the exact copy the runtime loads.
101
+ '@payloadcms/ui > @dnd-kit/modifiers',
102
+ '@payloadcms/ui > dequal/lite',
103
+ 'payload > ajv',
104
+ // The storage client-upload suites (esp. vercel-blob) crawl part of the
105
+ // `payload` server runtime into the client bundle and discover these late,
106
+ // triggering several "optimized dependencies changed. reloading" waves that
107
+ // reload the page mid-test (the bulk-upload drawer's Create New button /
108
+ // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the
109
+ // whole observed set so the first pass is complete.
110
+ 'payload > undici',
111
+ 'payload > jose',
112
+ 'payload > dataloader',
113
+ 'payload > path-to-regexp',
114
+ 'payload > console-table-printer',
115
+ 'payload > ci-info',
116
+ 'payload > image-size',
117
+ 'payload > image-size/fromFile',
118
+ 'payload > ipaddr.js',
119
+ 'payload > range-parser',
120
+ 'payload > sanitize-filename'
121
+ ];
122
+
123
+ //# sourceMappingURL=optimizeDeps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/vite/config/optimizeDeps.ts"],"sourcesContent":["/**\n * Client dep-optimizer config used by `withPayload`. Kept separate from the\n * SSR/RSC externalization config (`./external.ts`) so each concern stays small.\n */\n\n/**\n * Packages we know contain Node-only code or top-level side effects requiring\n * Node APIs. Excluding them from the client optimizer prevents Vite from\n * walking into their main entries and trying to bundle server-only imports\n * for the browser.\n */\nexport const optimizeDepsExcludeDefaults: string[] = [\n 'sharp',\n '@payloadcms/ui',\n '@payloadcms/tanstack-start',\n 'payload',\n 'pino',\n 'pino-pretty',\n 'busboy',\n 'get-tsconfig',\n 'ws',\n 'croner',\n 'prompts',\n 'file-type',\n // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite\n // sometimes walks these from the main package entry while scanning\n // workspace deps, and the browser sub-bundles do not expose the\n // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev\n // server with a `MISSING_EXPORT` error before any test runs.\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be\n * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick\n * these up because their parent packages are in `optimizeDeps.exclude`, so we\n * list them explicitly using the `parent > child` syntax.\n *\n * Each entry below fixes a specific late-discovery re-optimization: without it,\n * Vite discovers the dep *after* its initial crawl, forcing a full dep\n * re-optimization mid-session that 404s in-flight `.vite/deps/*` chunks and\n * remounts the admin (dropping client state). This is why the list can't simply\n * be deleted — it is the \"complete first pass\" for the admin's dep graph.\n */\nexport const optimizeDepsIncludeDefaults: string[] = [\n '@payloadcms/ui > sonner',\n '@payloadcms/ui > @faceless-ui/modal',\n '@payloadcms/ui > @faceless-ui/window-info',\n '@payloadcms/ui > @faceless-ui/scroll-info',\n '@payloadcms/ui > @dnd-kit/core',\n '@payloadcms/ui > @dnd-kit/sortable',\n '@payloadcms/ui > @dnd-kit/utilities',\n '@payloadcms/ui > react-datepicker',\n '@payloadcms/ui > react-select',\n '@payloadcms/ui > react-select/creatable',\n '@payloadcms/ui > react-image-crop',\n '@payloadcms/ui > @monaco-editor/react',\n '@payloadcms/ui > date-fns',\n '@payloadcms/ui > date-fns/transpose',\n '@payloadcms/ui > @date-fns/tz/date/mini',\n '@payloadcms/ui > uuid',\n '@payloadcms/ui > use-context-selector',\n '@payloadcms/ui > bson-objectid',\n '@payloadcms/ui > dequal',\n '@payloadcms/ui > object-to-formdata',\n '@payloadcms/ui > md5',\n 'payload > deepmerge',\n 'payload > pluralize',\n // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of\n // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated\n // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where\n // it isn't hoisted to the top level. Path it through `react-dom` so the\n // optimizer resolves the exact copy the runtime loads.\n 'react-dom > scheduler',\n // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the\n // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.\n // Because its parent is excluded, the optimizer never crawls in to discover\n // this entry, so Vite serves `react/compiler-runtime` raw. That file is\n // CommonJS (`module.exports = require(...)`), so the named `c` export can't be\n // statically extracted and every client component throws \"does not provide an\n // export named 'c'\". Pre-bundling it lets esbuild synthesize the named export.\n 'react/compiler-runtime',\n // Transitive deps that Vite otherwise discovers *after* the initial crawl\n // (react-select pulls in @floating-ui at runtime; react-is is reached via\n // react-transition-group/prop-types; the default date-fns locale is loaded\n // through a dynamic `date-fns/locale/${key}` import). A late discovery forces\n // a full dep re-optimization mid-session, which 404s every in-flight\n // `.vite/deps/*` chunk (\"Pre-transform error: file does not exist in the\n // optimize deps directory\") and breaks the admin UI in CI cold starts.\n // Pre-bundling them keeps the first optimization pass complete.\n '@payloadcms/ui > react-select > @floating-ui/dom',\n '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',\n '@payloadcms/ui > react-select > prop-types > react-is',\n '@payloadcms/ui > date-fns/locale/en-US',\n // Further late discoveries observed re-optimizing mid-run in CI cold starts\n // (see CI logs: \"✨ new dependencies optimized: @dnd-kit/modifiers / ajv /\n // dequal/lite\"). The modular dashboard pulls in `@dnd-kit/modifiers` on first\n // render; form-state diffing reaches `dequal/lite` (a distinct entry point\n // from the already-listed `dequal`); client-side field validation reaches\n // `ajv` *through `payload`* — it is `ssrExternal` server-side but still\n // bundled into the client, and must be pathed via `payload` so the optimizer\n // pre-bundles the exact copy the runtime loads.\n '@payloadcms/ui > @dnd-kit/modifiers',\n '@payloadcms/ui > dequal/lite',\n 'payload > ajv',\n // The storage client-upload suites (esp. vercel-blob) crawl part of the\n // `payload` server runtime into the client bundle and discover these late,\n // triggering several \"optimized dependencies changed. reloading\" waves that\n // reload the page mid-test (the bulk-upload drawer's Create New button /\n // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the\n // whole observed set so the first pass is complete.\n 'payload > undici',\n 'payload > jose',\n 'payload > dataloader',\n 'payload > path-to-regexp',\n 'payload > console-table-printer',\n 'payload > ci-info',\n 'payload > image-size',\n 'payload > image-size/fromFile',\n 'payload > ipaddr.js',\n 'payload > range-parser',\n 'payload > sanitize-filename',\n]\n"],"names":["optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults"],"mappings":"AAAA;;;CAGC,GAED;;;;;CAKC,GACD,OAAO,MAAMA,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kEAAkE;IAClE,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,6DAA6D;IAC7D;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,6EAA6E;IAC7E,+EAA+E;IAC/E,8EAA8E;IAC9E,wEAAwE;IACxE,uDAAuD;IACvD;IACA,8EAA8E;IAC9E,0EAA0E;IAC1E,4EAA4E;IAC5E,wEAAwE;IACxE,+EAA+E;IAC/E,8EAA8E;IAC9E,+EAA+E;IAC/E;IACA,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,qEAAqE;IACrE,yEAAyE;IACzE,uEAAuE;IACvE,gEAAgE;IAChE;IACA;IACA;IACA;IACA,4EAA4E;IAC5E,0EAA0E;IAC1E,8EAA8E;IAC9E,2EAA2E;IAC3E,0EAA0E;IAC1E,wEAAwE;IACxE,6EAA6E;IAC7E,gDAAgD;IAChD;IACA;IACA;IACA,wEAAwE;IACxE,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,oDAAoD;IACpD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
@@ -0,0 +1,49 @@
1
+ import type { UserConfig, UserConfigFnObject } from 'vite';
2
+ export type WithPayloadOptions = {
3
+ /**
4
+ * Additional import-protection `ignoreImporters` patterns. This is a
5
+ * Payload-specific knob on the TanStack Start plugin, so it cannot be
6
+ * expressed through `vite` — pass it here.
7
+ */
8
+ additionalIgnoreImporters?: RegExp[];
9
+ /** Path to the user's `payload.config.ts` (required) */
10
+ payloadConfigPath: string;
11
+ /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */
12
+ routesDirectory?: string;
13
+ /** TanStack source directory. Defaults to `'src'` */
14
+ srcDirectory?: string;
15
+ /**
16
+ * Extra Vite config merged on top of the Payload defaults via Vite's own
17
+ * `mergeConfig`. Objects are deep-merged and arrays are appended, so this is
18
+ * the single hook for everything a consumer used to reach through separate
19
+ * options: extra `plugins`, `resolve.alias` entries, `optimizeDeps.include`,
20
+ * `ssr.external`, `server`, `build`, and so on.
21
+ *
22
+ * @example
23
+ * withPayload({
24
+ * payloadConfigPath: './src/payload.config.ts',
25
+ * vite: { server: { port: 4000 } },
26
+ * })
27
+ */
28
+ vite?: UserConfig;
29
+ };
30
+ /**
31
+ * Vite config helper for Payload + TanStack Start. The Vite-side counterpart to
32
+ * `withPayload` for Next.js: it owns the whole Vite setup needed to run the
33
+ * Payload admin — the RSC, React, and TanStack Start plugins plus a small set of
34
+ * Payload-specific workarounds — so a consumer's `vite.config.ts` collapses to:
35
+ *
36
+ * ```ts
37
+ * import { withPayload } from '@payloadcms/tanstack-start/vite'
38
+ *
39
+ * export default withPayload({ payloadConfigPath: './src/payload.config.ts' })
40
+ * ```
41
+ *
42
+ * The React (`@vitejs/plugin-react`), RSC (`@vitejs/plugin-rsc`), and TanStack
43
+ * Start plugins are instantiated internally with the settings the admin
44
+ * requires — consumers no longer pass them in. Each remaining Payload
45
+ * workaround lives in its own file under `./workarounds/` so it can be deleted
46
+ * individually once the corresponding upstream fix lands.
47
+ */
48
+ export declare function withPayload(options: WithPayloadOptions): UserConfigFnObject;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAqB1D,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAA;IACpC,wDAAwD;IACxD,iBAAiB,EAAE,MAAM,CAAA;IACzB,uFAAuF;IACvF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,CA+H3E"}
@@ -1,22 +1,37 @@
1
+ import { tanstackStart } from '@tanstack/react-start/plugin/vite';
2
+ import viteReact from '@vitejs/plugin-react';
3
+ import rsc from '@vitejs/plugin-rsc';
1
4
  import path from 'node:path';
2
- import { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults, payloadNoExternalPatterns, payloadRscNoExternalPatterns, ssrExternalPackages } from './constants.js';
5
+ import { mergeConfig } from 'vite';
6
+ import { payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js';
7
+ import { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js';
3
8
  import { defaultImportProtectionIgnoreImporters, onImportProtectionViolation, serverOnlyClientSpecifiers } from './importProtection.js';
4
- import { clientModuleResolution } from './plugins/clientModuleResolution.js';
5
- import { payloadDevTransforms } from './plugins/devTransforms.js';
6
- import { reactDomServerInRsc } from './plugins/reactDomServerInRsc.js';
7
- import { ssrStripDistStyleImports } from './plugins/stripDistStyleImports.js';
8
- import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
9
+ import { clientModuleResolution } from './workarounds/clientModuleResolution.js';
10
+ import { payloadDevTransforms } from './workarounds/devTransforms.js';
11
+ import { reactDomServerInRsc } from './workarounds/reactDomServerInRsc.js';
12
+ import { ssrStripDistStyleImports } from './workarounds/stripDistStyleImports.js';
13
+ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
9
14
  /**
10
- * Vite plugin for Payload + TanStack Start. The Vite-side counterpart to
11
- * `withPayload` for Next.js: it configures the Vite environment so the Payload
12
- * admin can run, then composes the TanStack Start plugin with two small
13
- * Payload-specific workarounds (dev HMR injection, SSR style stripping). Each
14
- * remaining workaround lives in its own file under `./plugins/` so it can be
15
- * deleted individually once the corresponding upstream fix lands.
16
- */ export function payloadPlugin(options) {
17
- const { additionalAliases = [], additionalIgnoreImporters = [], additionalOptimizeDepsInclude = [], additionalSsrExternal = [], payloadConfigPath, plugins: extraPlugins = [], reactPlugin, routesDirectory = 'app', rscPlugin, srcDirectory = 'src', tanstackStart } = options;
18
- process.env.PAYLOAD_FRAMEWORK_RSC_ENABLED = 'true';
19
- return (_env)=>({
15
+ * Vite config helper for Payload + TanStack Start. The Vite-side counterpart to
16
+ * `withPayload` for Next.js: it owns the whole Vite setup needed to run the
17
+ * Payload admin the RSC, React, and TanStack Start plugins plus a small set of
18
+ * Payload-specific workarounds so a consumer's `vite.config.ts` collapses to:
19
+ *
20
+ * ```ts
21
+ * import { withPayload } from '@payloadcms/tanstack-start/vite'
22
+ *
23
+ * export default withPayload({ payloadConfigPath: './src/payload.config.ts' })
24
+ * ```
25
+ *
26
+ * The React (`@vitejs/plugin-react`), RSC (`@vitejs/plugin-rsc`), and TanStack
27
+ * Start plugins are instantiated internally with the settings the admin
28
+ * requires — consumers no longer pass them in. Each remaining Payload
29
+ * workaround lives in its own file under `./workarounds/` so it can be deleted
30
+ * individually once the corresponding upstream fix lands.
31
+ */ export function withPayload(options) {
32
+ const { additionalIgnoreImporters = [], payloadConfigPath, routesDirectory = 'app', srcDirectory = 'src', vite } = options;
33
+ return (_env)=>{
34
+ const base = {
20
35
  css: {
21
36
  preprocessorOptions: {
22
37
  scss: {
@@ -28,13 +43,12 @@ import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
28
43
  }
29
44
  },
30
45
  define: {
31
- global: 'globalThis',
32
- 'process.env.PAYLOAD_FRAMEWORK_RSC_ENABLED': JSON.stringify('true')
46
+ global: 'globalThis'
33
47
  },
34
48
  environments: {
35
49
  rsc: {
36
50
  resolve: {
37
- noExternal: payloadRscNoExternalPatterns
51
+ noExternal: payloadNoExternalPatterns
38
52
  }
39
53
  },
40
54
  ssr: {
@@ -45,10 +59,7 @@ import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
45
59
  },
46
60
  optimizeDeps: {
47
61
  exclude: optimizeDepsExcludeDefaults,
48
- include: [
49
- ...optimizeDepsIncludeDefaults,
50
- ...additionalOptimizeDepsInclude
51
- ]
62
+ include: optimizeDepsIncludeDefaults
52
63
  },
53
64
  plugins: [
54
65
  clientModuleResolution(),
@@ -56,7 +67,9 @@ import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
56
67
  ssrStripDistStyleImports(),
57
68
  reactDomServerInRsc(),
58
69
  payloadDevTransforms(),
59
- rscPlugin,
70
+ rsc({
71
+ serverHandler: false
72
+ }),
60
73
  tanstackStart({
61
74
  importProtection: {
62
75
  client: {
@@ -122,11 +135,14 @@ import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
122
135
  codeSplittingOptions: {
123
136
  defaultBehavior: []
124
137
  },
125
- // Exclude only generated importMap files. Admin form saves are
126
- // dispatched via `runPayloadServerFn` (a TanStack Start
127
- // `createServerFn`) rather than a hand-rolled route, so there is
128
- // no longer an `api.server-function.ts` to special-case here.
129
- routeFileIgnorePattern: 'importMap\\.(?:js|server\\.ts)$',
138
+ // Exclude generated importMap files and colocated server-function
139
+ // modules (`*.functions.ts`). Admin form saves are dispatched via
140
+ // `runPayloadServerFn` (a TanStack Start `createServerFn`) rather than
141
+ // a hand-rolled route, so there is no longer an `api.server-function.ts`
142
+ // to special-case here. The `*.functions.ts` shims live next to the
143
+ // routes that use them (e.g. `app/_payload/*.functions.ts`); they
144
+ // define `createServerFn`s, not routes, so they must not be scanned.
145
+ routeFileIgnorePattern: 'importMap\\.(?:js|server\\.ts)$|\\.functions\\.',
130
146
  routesDirectory
131
147
  },
132
148
  rsc: {
@@ -134,22 +150,24 @@ import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
134
150
  },
135
151
  srcDirectory
136
152
  }),
137
- reactPlugin,
138
- ...extraPlugins
153
+ viteReact({
154
+ exclude: [],
155
+ include: /\.[jt]sx?$/
156
+ })
139
157
  ],
140
158
  resolve: {
141
159
  alias: [
142
160
  {
143
161
  find: '@payload-config',
144
162
  replacement: path.resolve(payloadConfigPath)
145
- },
146
- ...additionalAliases
163
+ }
147
164
  ],
148
165
  dedupe: [
149
166
  'react',
150
167
  'react-dom',
151
168
  'scheduler',
152
- '@payloadcms/ui'
169
+ '@payloadcms/ui',
170
+ '@payloadcms/richtext-lexical'
153
171
  ],
154
172
  extensions: [
155
173
  '.mjs',
@@ -162,21 +180,13 @@ import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
162
180
  ],
163
181
  tsconfigPaths: true
164
182
  },
165
- server: {
166
- warmup: {
167
- clientFiles: [
168
- './src/importMap.js'
169
- ]
170
- }
171
- },
172
183
  ssr: {
173
- external: [
174
- ...ssrExternalPackages,
175
- ...additionalSsrExternal
176
- ],
184
+ external: ssrExternalPackages,
177
185
  noExternal: payloadNoExternalPatterns
178
186
  }
179
- });
187
+ };
188
+ return vite ? mergeConfig(base, vite) : base;
189
+ };
180
190
  }
181
191
 
182
- //# sourceMappingURL=plugin.js.map
192
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { UserConfig, UserConfigFnObject } from 'vite'\n\nimport { tanstackStart } from '@tanstack/react-start/plugin/vite'\nimport viteReact from '@vitejs/plugin-react'\nimport rsc from '@vitejs/plugin-rsc'\nimport path from 'node:path'\nimport { mergeConfig } from 'vite'\n\nimport { payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js'\nimport { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js'\nimport {\n defaultImportProtectionIgnoreImporters,\n onImportProtectionViolation,\n serverOnlyClientSpecifiers,\n} from './importProtection.js'\nimport { clientModuleResolution } from './workarounds/clientModuleResolution.js'\nimport { payloadDevTransforms } from './workarounds/devTransforms.js'\nimport { reactDomServerInRsc } from './workarounds/reactDomServerInRsc.js'\nimport { ssrStripDistStyleImports } from './workarounds/stripDistStyleImports.js'\nimport { wrapCjsForClient } from './workarounds/wrapCjsForClient.js'\n\nexport type WithPayloadOptions = {\n /**\n * Additional import-protection `ignoreImporters` patterns. This is a\n * Payload-specific knob on the TanStack Start plugin, so it cannot be\n * expressed through `vite` — pass it here.\n */\n additionalIgnoreImporters?: RegExp[]\n /** Path to the user's `payload.config.ts` (required) */\n payloadConfigPath: string\n /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */\n routesDirectory?: string\n /** TanStack source directory. Defaults to `'src'` */\n srcDirectory?: string\n /**\n * Extra Vite config merged on top of the Payload defaults via Vite's own\n * `mergeConfig`. Objects are deep-merged and arrays are appended, so this is\n * the single hook for everything a consumer used to reach through separate\n * options: extra `plugins`, `resolve.alias` entries, `optimizeDeps.include`,\n * `ssr.external`, `server`, `build`, and so on.\n *\n * @example\n * withPayload({\n * payloadConfigPath: './src/payload.config.ts',\n * vite: { server: { port: 4000 } },\n * })\n */\n vite?: UserConfig\n}\n\n/**\n * Vite config helper for Payload + TanStack Start. The Vite-side counterpart to\n * `withPayload` for Next.js: it owns the whole Vite setup needed to run the\n * Payload admin — the RSC, React, and TanStack Start plugins plus a small set of\n * Payload-specific workarounds — so a consumer's `vite.config.ts` collapses to:\n *\n * ```ts\n * import { withPayload } from '@payloadcms/tanstack-start/vite'\n *\n * export default withPayload({ payloadConfigPath: './src/payload.config.ts' })\n * ```\n *\n * The React (`@vitejs/plugin-react`), RSC (`@vitejs/plugin-rsc`), and TanStack\n * Start plugins are instantiated internally with the settings the admin\n * requires — consumers no longer pass them in. Each remaining Payload\n * workaround lives in its own file under `./workarounds/` so it can be deleted\n * individually once the corresponding upstream fix lands.\n */\nexport function withPayload(options: WithPayloadOptions): UserConfigFnObject {\n const {\n additionalIgnoreImporters = [],\n payloadConfigPath,\n routesDirectory = 'app',\n srcDirectory = 'src',\n vite,\n } = options\n\n return (_env) => {\n const base: UserConfig = {\n css: {\n preprocessorOptions: {\n scss: {\n silenceDeprecations: ['import', 'global-builtin'],\n } as any,\n },\n },\n define: {\n global: 'globalThis',\n },\n environments: {\n rsc: { resolve: { noExternal: payloadNoExternalPatterns } },\n ssr: { resolve: { noExternal: payloadNoExternalPatterns } },\n } as any,\n optimizeDeps: {\n exclude: optimizeDepsExcludeDefaults,\n include: optimizeDepsIncludeDefaults,\n },\n plugins: [\n clientModuleResolution(),\n wrapCjsForClient(),\n ssrStripDistStyleImports(),\n reactDomServerInRsc(),\n payloadDevTransforms(),\n rsc({ serverHandler: false }),\n tanstackStart({\n importProtection: {\n client: { excludeFiles: [], specifiers: serverOnlyClientSpecifiers },\n ignoreImporters: [\n ...defaultImportProtectionIgnoreImporters,\n ...additionalIgnoreImporters,\n ],\n include: ['**/*'],\n mockAccess: 'warn',\n onViolation: onImportProtectionViolation,\n // Disable TanStack Start's default `**/*.client.*` file-based denial in\n // the SSR environment. Payload uses the `.client.tsx` filename suffix\n // for React Client Components (with a `'use client'` directive) that\n // MUST be server-rendered to HTML during SSR. The default rule would\n // otherwise replace those files with an `import-protection mock` Proxy\n // during SSR, which crashes React (TypeError: Cannot convert object to\n // primitive value) the moment React tries to format a warning that\n // mentions one of these components.\n server: { files: [] },\n },\n // Disable TanStack Router's automatic per-route code-splitting.\n //\n // With splitting enabled each route's `component` is fetched lazily\n // via `?tsr-split=component` after the initial SSR HTML is streamed.\n // Until that lazy chunk lands the rendered admin tree has no client\n // React attached, so any button clicks (e.g. the\n // `#toggle-list-filters` chevron in `<ListControls />`) hit a static\n // DOM, the click is dropped, and once the chunk finally loads the\n // component re-mounts with its initial `useState` instead of the\n // toggled value. That single behaviour was the root cause of the\n // \"page renders but nothing is interactive\" tanstack-start E2E\n // failures (`#list-controls-where`, `[data-lexical-editor]`, etc.) -\n // playwright traces show \"Download the React DevTools\" landing\n // *after* the playwright click, confirming late hydration.\n //\n // We pass BOTH knobs because `tanstackStart`'s schema silently\n // strips the user-supplied `autoCodeSplitting` (its `tsrConfig`\n // does `configSchema.omit({ autoCodeSplitting: true, target: true\n // })`) and then leaves the value `undefined` — which is fine for\n // the conditional inside `unpluginRouterComposedFactory`, but the\n // TanStack Start vite plugin *unconditionally* installs the router\n // code-splitter via `tanStackRouterCodeSplitter(...)` regardless.\n // The only knob that survives all of that and is honoured by the\n // splitter is `router.codeSplittingOptions.defaultBehavior` — set\n // to an empty array, the splitter still walks each `createFileRoute`\n // file but produces no virtual `?tsr-split=...` modules, so every\n // route component ships in the initial bundle and hydration starts\n // immediately on first paint. We keep `autoCodeSplitting: false` as\n // a belt-and-braces signal in case the start plugin ever stops\n // dropping it.\n //\n // Eager-loading routes ships a slightly larger initial bundle but\n // makes the admin actually interactive on first paint.\n router: {\n autoCodeSplitting: false,\n codeSplittingOptions: { defaultBehavior: [] },\n // Exclude generated importMap files and colocated server-function\n // modules (`*.functions.ts`). Admin form saves are dispatched via\n // `runPayloadServerFn` (a TanStack Start `createServerFn`) rather than\n // a hand-rolled route, so there is no longer an `api.server-function.ts`\n // to special-case here. The `*.functions.ts` shims live next to the\n // routes that use them (e.g. `app/_payload/*.functions.ts`); they\n // define `createServerFn`s, not routes, so they must not be scanned.\n routeFileIgnorePattern: 'importMap\\\\.(?:js|server\\\\.ts)$|\\\\.functions\\\\.',\n routesDirectory,\n } as any,\n rsc: { enabled: true },\n srcDirectory,\n }),\n viteReact({ exclude: [], include: /\\.[jt]sx?$/ }),\n ],\n resolve: {\n alias: [{ find: '@payload-config', replacement: path.resolve(payloadConfigPath) }],\n dedupe: [\n 'react',\n 'react-dom',\n 'scheduler',\n '@payloadcms/ui',\n '@payloadcms/richtext-lexical',\n ],\n extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],\n tsconfigPaths: true,\n } as any,\n ssr: {\n external: ssrExternalPackages,\n noExternal: payloadNoExternalPatterns,\n },\n }\n\n return vite ? mergeConfig(base, vite) : base\n }\n}\n"],"names":["tanstackStart","viteReact","rsc","path","mergeConfig","payloadNoExternalPatterns","ssrExternalPackages","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","defaultImportProtectionIgnoreImporters","onImportProtectionViolation","serverOnlyClientSpecifiers","clientModuleResolution","payloadDevTransforms","reactDomServerInRsc","ssrStripDistStyleImports","wrapCjsForClient","withPayload","options","additionalIgnoreImporters","payloadConfigPath","routesDirectory","srcDirectory","vite","_env","base","css","preprocessorOptions","scss","silenceDeprecations","define","global","environments","resolve","noExternal","ssr","optimizeDeps","exclude","include","plugins","serverHandler","importProtection","client","excludeFiles","specifiers","ignoreImporters","mockAccess","onViolation","server","files","router","autoCodeSplitting","codeSplittingOptions","defaultBehavior","routeFileIgnorePattern","enabled","alias","find","replacement","dedupe","extensions","tsconfigPaths","external"],"mappings":"AAEA,SAASA,aAAa,QAAQ,oCAAmC;AACjE,OAAOC,eAAe,uBAAsB;AAC5C,OAAOC,SAAS,qBAAoB;AACpC,OAAOC,UAAU,YAAW;AAC5B,SAASC,WAAW,QAAQ,OAAM;AAElC,SAASC,yBAAyB,EAAEC,mBAAmB,QAAQ,uBAAsB;AACrF,SAASC,2BAA2B,EAAEC,2BAA2B,QAAQ,2BAA0B;AACnG,SACEC,sCAAsC,EACtCC,2BAA2B,EAC3BC,0BAA0B,QACrB,wBAAuB;AAC9B,SAASC,sBAAsB,QAAQ,0CAAyC;AAChF,SAASC,oBAAoB,QAAQ,iCAAgC;AACrE,SAASC,mBAAmB,QAAQ,uCAAsC;AAC1E,SAASC,wBAAwB,QAAQ,yCAAwC;AACjF,SAASC,gBAAgB,QAAQ,oCAAmC;AA+BpE;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC,YAAYC,OAA2B;IACrD,MAAM,EACJC,4BAA4B,EAAE,EAC9BC,iBAAiB,EACjBC,kBAAkB,KAAK,EACvBC,eAAe,KAAK,EACpBC,IAAI,EACL,GAAGL;IAEJ,OAAO,CAACM;QACN,MAAMC,OAAmB;YACvBC,KAAK;gBACHC,qBAAqB;oBACnBC,MAAM;wBACJC,qBAAqB;4BAAC;4BAAU;yBAAiB;oBACnD;gBACF;YACF;YACAC,QAAQ;gBACNC,QAAQ;YACV;YACAC,cAAc;gBACZ9B,KAAK;oBAAE+B,SAAS;wBAAEC,YAAY7B;oBAA0B;gBAAE;gBAC1D8B,KAAK;oBAAEF,SAAS;wBAAEC,YAAY7B;oBAA0B;gBAAE;YAC5D;YACA+B,cAAc;gBACZC,SAAS9B;gBACT+B,SAAS9B;YACX;YACA+B,SAAS;gBACP3B;gBACAI;gBACAD;gBACAD;gBACAD;gBACAX,IAAI;oBAAEsC,eAAe;gBAAM;gBAC3BxC,cAAc;oBACZyC,kBAAkB;wBAChBC,QAAQ;4BAAEC,cAAc,EAAE;4BAAEC,YAAYjC;wBAA2B;wBACnEkC,iBAAiB;+BACZpC;+BACAU;yBACJ;wBACDmB,SAAS;4BAAC;yBAAO;wBACjBQ,YAAY;wBACZC,aAAarC;wBACb,wEAAwE;wBACxE,sEAAsE;wBACtE,qEAAqE;wBACrE,qEAAqE;wBACrE,uEAAuE;wBACvE,uEAAuE;wBACvE,mEAAmE;wBACnE,oCAAoC;wBACpCsC,QAAQ;4BAAEC,OAAO,EAAE;wBAAC;oBACtB;oBACA,gEAAgE;oBAChE,EAAE;oBACF,oEAAoE;oBACpE,qEAAqE;oBACrE,oEAAoE;oBACpE,iDAAiD;oBACjD,qEAAqE;oBACrE,kEAAkE;oBAClE,iEAAiE;oBACjE,iEAAiE;oBACjE,+DAA+D;oBAC/D,qEAAqE;oBACrE,+DAA+D;oBAC/D,2DAA2D;oBAC3D,EAAE;oBACF,+DAA+D;oBAC/D,gEAAgE;oBAChE,kEAAkE;oBAClE,iEAAiE;oBACjE,kEAAkE;oBAClE,mEAAmE;oBACnE,kEAAkE;oBAClE,iEAAiE;oBACjE,kEAAkE;oBAClE,qEAAqE;oBACrE,kEAAkE;oBAClE,mEAAmE;oBACnE,oEAAoE;oBACpE,+DAA+D;oBAC/D,eAAe;oBACf,EAAE;oBACF,kEAAkE;oBAClE,uDAAuD;oBACvDC,QAAQ;wBACNC,mBAAmB;wBACnBC,sBAAsB;4BAAEC,iBAAiB,EAAE;wBAAC;wBAC5C,kEAAkE;wBAClE,kEAAkE;wBAClE,uEAAuE;wBACvE,yEAAyE;wBACzE,oEAAoE;wBACpE,kEAAkE;wBAClE,qEAAqE;wBACrEC,wBAAwB;wBACxBjC;oBACF;oBACAnB,KAAK;wBAAEqD,SAAS;oBAAK;oBACrBjC;gBACF;gBACArB,UAAU;oBAAEoC,SAAS,EAAE;oBAAEC,SAAS;gBAAa;aAChD;YACDL,SAAS;gBACPuB,OAAO;oBAAC;wBAAEC,MAAM;wBAAmBC,aAAavD,KAAK8B,OAAO,CAACb;oBAAmB;iBAAE;gBAClFuC,QAAQ;oBACN;oBACA;oBACA;oBACA;oBACA;iBACD;gBACDC,YAAY;oBAAC;oBAAQ;oBAAO;oBAAQ;oBAAO;oBAAQ;oBAAQ;iBAAQ;gBACnEC,eAAe;YACjB;YACA1B,KAAK;gBACH2B,UAAUxD;gBACV4B,YAAY7B;YACd;QACF;QAEA,OAAOkB,OAAOnB,YAAYqB,MAAMF,QAAQE;IAC1C;AACF"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientModuleResolution.d.ts","sourceRoot":"","sources":["../../../src/vite/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 @@
1
+ {"version":3,"sources":["../../../src/vite/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/vite/workarounds/devTransforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CA2DnD"}
@@ -2,6 +2,17 @@
2
2
  * Dev-time transforms:
3
3
  * - Replaces `process.cwd()` with `"/"` in client code (non-SSR, non-prebundled)
4
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.
5
16
  */ export function payloadDevTransforms() {
6
17
  const devScripts = `<script type="module" src="/@vite/client"></script>
7
18
  <script type="module">
@@ -27,9 +38,9 @@ window.__vite_plugin_react_preamble_installed__ = true
27
38
  return chunk;
28
39
  }
29
40
  const str = typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : chunk instanceof Uint8Array ? Buffer.from(chunk).toString() : null;
30
- if (str && str.includes('<head>')) {
41
+ if (str && str.includes('</head>')) {
31
42
  injected = true;
32
- return str.replace('<head>', `<head>${devScripts}`);
43
+ return str.replace('</head>', `${devScripts}</head>`);
33
44
  }
34
45
  return chunk;
35
46
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/vite/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 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,IAAIH,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 @@
1
+ {"version":3,"file":"reactDomServerInRsc.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/reactDomServerInRsc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAQxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAyDlD"}