@payloadcms/tanstack-start 4.0.0-internal.811e0a4 → 4.0.0-internal.8ba6b5b

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.
@@ -1,13 +1,3 @@
1
- import { withPayload } from '../vite/index.js';
2
- export { withPayload } from '../vite/index.js';
3
- export type { WithPayloadOptions } from '../vite/index.js';
4
- /**
5
- * @deprecated Use `withPayload` instead. `payloadPlugin` is a backwards-compatible
6
- * alias and will be removed in a future release. Note that the React, RSC, and
7
- * TanStack Start plugins are now instantiated internally, so the `reactPlugin`,
8
- * `rscPlugin`, and `tanstackStart` options are no longer required.
9
- */
10
- export declare const payloadPlugin: typeof withPayload;
11
- /** @deprecated Use `WithPayloadOptions` instead. */
12
- export type { WithPayloadOptions as PayloadPluginOptions } from '../vite/index.js';
1
+ export { payloadReactOptions, payloadRscOptions, payloadTanstackStartOptions, withPayload, } from '../vite/index.js';
2
+ export type { PayloadPluginOptions, PayloadTanstackStartOptionsArgs, WithPayloadBuilder, WithPayloadBuilderContext, WithPayloadOptions, } from '../vite/index.js';
13
3
  //# sourceMappingURL=vite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/exports/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,aAAa,oBAAc,CAAA;AAExC,oDAAoD;AACpD,YAAY,EAAE,kBAAkB,IAAI,oBAAoB,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/exports/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,2BAA2B,EAC3B,WAAW,GACZ,MAAM,kBAAkB,CAAA;AACzB,YAAY,EACV,oBAAoB,EACpB,+BAA+B,EAC/B,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,kBAAkB,CAAA"}
@@ -1,10 +1,3 @@
1
- import { withPayload } from '../vite/index.js';
2
- export { withPayload } from '../vite/index.js';
3
- /**
4
- * @deprecated Use `withPayload` instead. `payloadPlugin` is a backwards-compatible
5
- * alias and will be removed in a future release. Note that the React, RSC, and
6
- * TanStack Start plugins are now instantiated internally, so the `reactPlugin`,
7
- * `rscPlugin`, and `tanstackStart` options are no longer required.
8
- */ export const payloadPlugin = withPayload;
1
+ export { payloadReactOptions, payloadRscOptions, payloadTanstackStartOptions, withPayload } from '../vite/index.js';
9
2
 
10
3
  //# sourceMappingURL=vite.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/vite.ts"],"sourcesContent":["import { withPayload } from '../vite/index.js'\n\nexport { withPayload } from '../vite/index.js'\nexport type { WithPayloadOptions } from '../vite/index.js'\n\n/**\n * @deprecated Use `withPayload` instead. `payloadPlugin` is a backwards-compatible\n * alias and will be removed in a future release. Note that the React, RSC, and\n * TanStack Start plugins are now instantiated internally, so the `reactPlugin`,\n * `rscPlugin`, and `tanstackStart` options are no longer required.\n */\nexport const payloadPlugin = withPayload\n\n/** @deprecated Use `WithPayloadOptions` instead. */\nexport type { WithPayloadOptions as PayloadPluginOptions } from '../vite/index.js'\n"],"names":["withPayload","payloadPlugin"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,SAASA,WAAW,QAAQ,mBAAkB;AAG9C;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgBD,YAAW"}
1
+ {"version":3,"sources":["../../src/exports/vite.ts"],"sourcesContent":["export {\n payloadReactOptions,\n payloadRscOptions,\n payloadTanstackStartOptions,\n withPayload,\n} from '../vite/index.js'\nexport type {\n PayloadPluginOptions,\n PayloadTanstackStartOptionsArgs,\n WithPayloadBuilder,\n WithPayloadBuilderContext,\n WithPayloadOptions,\n} from '../vite/index.js'\n"],"names":["payloadReactOptions","payloadRscOptions","payloadTanstackStartOptions","withPayload"],"mappings":"AAAA,SACEA,mBAAmB,EACnBC,iBAAiB,EACjBC,2BAA2B,EAC3BC,WAAW,QACN,mBAAkB"}
@@ -1,55 +1,97 @@
1
- import type { UserConfig, UserConfigFnObject } from 'vite';
1
+ import type { ConfigEnv, UserConfig, UserConfigFnObject } from 'vite';
2
+ import { tanstackStart } from '@tanstack/react-start/plugin/vite';
3
+ import viteReact from '@vitejs/plugin-react';
4
+ import rsc from '@vitejs/plugin-rsc';
2
5
  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
- */
6
+ /** Extra import-protection `ignoreImporters` patterns for the TanStack Start plugin. */
8
7
  additionalIgnoreImporters?: RegExp[];
8
+ /** Route id of Payload's admin layout, eager-loaded instead of code-split. Defaults to `'/_payload'`. */
9
+ adminRouteId?: string;
10
+ /** Extra globs exempted from the `.client.*` SSR denial (beyond the default node_modules exemption). */
11
+ clientDenialExcludeFiles?: string[];
9
12
  /** Path to the user's `payload.config.ts` (required) */
10
13
  payloadConfigPath: string;
11
14
  /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */
12
15
  routesDirectory?: string;
13
- /**
14
- * Silence Vite warnings about third-party dependency sourcemaps pointing to
15
- * missing source files — noise Payload consumers can't act on. Defaults to
16
- * `true`; set `false` to see them. Composes with a `vite.customLogger`.
17
- */
16
+ /** Silence Vite warnings about third-party dependency sourcemaps. Defaults to `true`. */
18
17
  silenceDependencyWarnings?: boolean;
19
18
  /** TanStack source directory. Defaults to `'src'` */
20
19
  srcDirectory?: string;
21
- /**
22
- * Extra Vite config merged on top of the Payload defaults via Vite's own
23
- * `mergeConfig`. Objects are deep-merged and arrays are appended, so this is
24
- * the single hook for everything a consumer used to reach through separate
25
- * options: extra `plugins`, `resolve.alias` entries, `optimizeDeps.include`,
26
- * `ssr.external`, `server`, `build`, and so on.
27
- *
28
- * @example
29
- * withPayload({
30
- * payloadConfigPath: './src/payload.config.ts',
31
- * vite: { server: { port: 4000 } },
32
- * })
33
- */
20
+ /** Extra Vite config deep-merged over the Payload defaults. Ignored in `build` mode. */
34
21
  vite?: UserConfig;
35
22
  };
23
+ /** The options Payload's admin requires for each third-party plugin. */
24
+ export type PayloadPluginOptions = {
25
+ react: NonNullable<Parameters<typeof viteReact>[0]>;
26
+ rsc: NonNullable<Parameters<typeof rsc>[0]>;
27
+ tanstackStart: NonNullable<Parameters<typeof tanstackStart>[0]>;
28
+ };
29
+ export type WithPayloadBuilderContext = {
30
+ /** Payload's base Vite config; `plugins` holds Payload's workaround plugins only. */
31
+ config: UserConfig;
32
+ env: ConfigEnv;
33
+ /** Options to pass to the `viteReact`/`rsc`/`tanstackStart` factories you import. */
34
+ pluginOptions: PayloadPluginOptions;
35
+ };
36
+ /** Assembles the final Vite config from Payload's base config and plugin options. */
37
+ export type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserConfig;
36
38
  /**
37
- * Vite config helper for Payload + TanStack Start. The Vite-side counterpart to
38
- * `withPayload` for Next.js: it owns the whole Vite setup needed to run the
39
- * Payload admin — the RSC, React, and TanStack Start plugins plus a small set of
40
- * Payload-specific workarounds — so a consumer's `vite.config.ts` collapses to:
39
+ * Vite config helper for Payload + TanStack Start; the counterpart to Next.js'
40
+ * `withPayload`.
41
41
  *
42
- * ```ts
43
- * import { withPayload } from '@payloadcms/tanstack-start/vite'
42
+ * Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:
44
43
  *
45
- * export default withPayload({ payloadConfigPath: './src/payload.config.ts' })
44
+ * ```ts
45
+ * export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })
46
46
  * ```
47
47
  *
48
- * The React (`@vitejs/plugin-react`), RSC (`@vitejs/plugin-rsc`), and TanStack
49
- * Start plugins are instantiated internally with the settings the admin
50
- * requires — consumers no longer pass them in. Each remaining Payload
51
- * workaround lives in its own file under `./workarounds/` so it can be deleted
52
- * individually once the corresponding upstream fix lands.
48
+ * Guest mode — pass a `build` callback to instantiate them yourself (one copy of
49
+ * each; `@vitejs/plugin-rsc` is a hard singleton):
50
+ *
51
+ * ```ts
52
+ * export default withPayload(
53
+ * ({ config, pluginOptions }) => ({
54
+ * ...config,
55
+ * plugins: [
56
+ * ...config.plugins,
57
+ * rsc(pluginOptions.rsc),
58
+ * tanstackStart(pluginOptions.tanstackStart),
59
+ * viteReact(pluginOptions.react),
60
+ * ],
61
+ * }),
62
+ * { payloadConfigPath: './src/payload.config.ts' },
63
+ * )
64
+ * ```
65
+ */
66
+ export declare function withPayload(build: undefined | WithPayloadBuilder, options: WithPayloadOptions): UserConfigFnObject;
67
+ /** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */
68
+ export declare function payloadRscOptions(): NonNullable<Parameters<typeof rsc>[0]>;
69
+ /** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */
70
+ export declare function payloadReactOptions(): NonNullable<Parameters<typeof viteReact>[0]>;
71
+ export type PayloadTanstackStartOptionsArgs = {
72
+ /** Additional import-protection `ignoreImporters` patterns. */
73
+ additionalIgnoreImporters?: RegExp[];
74
+ /**
75
+ * Route id of Payload's admin layout route, eager-loaded (not code-split) so it
76
+ * hydrates on first paint. It and its children skip splitting; host routes keep
77
+ * TanStack's default. Defaults to `'/_payload'` (the `_payload.tsx` convention).
78
+ */
79
+ adminRouteId?: string;
80
+ /**
81
+ * Extra globs exempted from TanStack's `.client.*` SSR denial, on top of the
82
+ * default node_modules exemption. Needed only when Payload's own `.client.*`
83
+ * files resolve outside node_modules (e.g. the monorepo's `packages` sources).
84
+ */
85
+ clientDenialExcludeFiles?: string[];
86
+ /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'`. */
87
+ routesDirectory?: string;
88
+ /** TanStack source directory. Defaults to `'src'`. */
89
+ srcDirectory?: string;
90
+ };
91
+ /**
92
+ * The `tanstackStart` options Payload's admin requires (import-protection and
93
+ * code-splitting). TanStack Start is one-per-app, so a host that already runs it
94
+ * should merge these into its single `tanstackStart` call.
53
95
  */
54
- export declare function withPayload(options: WithPayloadOptions): UserConfigFnObject;
96
+ export declare function payloadTanstackStartOptions(args?: PayloadTanstackStartOptionsArgs): NonNullable<Parameters<typeof tanstackStart>[0]>;
55
97
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,UAAU,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAsDlE,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;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,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,CAiJ3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAwB,UAAU,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAI3F,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AACjE,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAC5C,OAAO,GAAG,MAAM,oBAAoB,CAAA;AA0DpC,MAA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AI,WAAW,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAE1E;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,IAAI,WAAW,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAElF;AAED,MAAM,MAAM,+BAA+B,GAAG;IAC5C,+DAA+D;IAC/D,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAA;IACpC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,wFAAwF;IACxF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,GAAE,+BAAoC,GACzC,WAAW,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAwClD"}
@@ -1,3 +1,5 @@
1
+ // Optional peers, not deps: `plugin-rsc` is a singleton, so bundling our own copy
2
+ // alongside the host's would load two instances and crash.
1
3
  import { tanstackStart } from '@tanstack/react-start/plugin/vite';
2
4
  import viteReact from '@vitejs/plugin-react';
3
5
  import rsc from '@vitejs/plugin-rsc';
@@ -41,26 +43,42 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
41
43
  };
42
44
  return logger;
43
45
  }
46
+ /** Applies dependency-warning suppression to a config in place when enabled. */ function applyDependencyWarningSuppression(config, enabled) {
47
+ if (enabled) {
48
+ config.customLogger = withQuietedDependencyWarnings(config.customLogger);
49
+ }
50
+ return config;
51
+ }
44
52
  /**
45
- * Vite config helper for Payload + TanStack Start. The Vite-side counterpart to
46
- * `withPayload` for Next.js: it owns the whole Vite setup needed to run the
47
- * Payload admin — the RSC, React, and TanStack Start plugins plus a small set of
48
- * Payload-specific workarounds — so a consumer's `vite.config.ts` collapses to:
53
+ * Vite config helper for Payload + TanStack Start; the counterpart to Next.js'
54
+ * `withPayload`.
49
55
  *
50
- * ```ts
51
- * import { withPayload } from '@payloadcms/tanstack-start/vite'
56
+ * Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:
52
57
  *
53
- * export default withPayload({ payloadConfigPath: './src/payload.config.ts' })
58
+ * ```ts
59
+ * export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })
54
60
  * ```
55
61
  *
56
- * The React (`@vitejs/plugin-react`), RSC (`@vitejs/plugin-rsc`), and TanStack
57
- * Start plugins are instantiated internally with the settings the admin
58
- * requires — consumers no longer pass them in. Each remaining Payload
59
- * workaround lives in its own file under `./workarounds/` so it can be deleted
60
- * individually once the corresponding upstream fix lands.
61
- */ export function withPayload(options) {
62
- const { additionalIgnoreImporters = [], payloadConfigPath, routesDirectory = 'app', silenceDependencyWarnings = true, srcDirectory = 'src', vite } = options;
63
- return (_env)=>{
62
+ * Guest mode — pass a `build` callback to instantiate them yourself (one copy of
63
+ * each; `@vitejs/plugin-rsc` is a hard singleton):
64
+ *
65
+ * ```ts
66
+ * export default withPayload(
67
+ * ({ config, pluginOptions }) => ({
68
+ * ...config,
69
+ * plugins: [
70
+ * ...config.plugins,
71
+ * rsc(pluginOptions.rsc),
72
+ * tanstackStart(pluginOptions.tanstackStart),
73
+ * viteReact(pluginOptions.react),
74
+ * ],
75
+ * }),
76
+ * { payloadConfigPath: './src/payload.config.ts' },
77
+ * )
78
+ * ```
79
+ */ export function withPayload(build, options) {
80
+ const { additionalIgnoreImporters = [], adminRouteId, clientDenialExcludeFiles = [], payloadConfigPath, routesDirectory = 'app', silenceDependencyWarnings = true, srcDirectory = 'src', vite } = options;
81
+ return (env)=>{
64
82
  const base = {
65
83
  build: {
66
84
  cssMinify: 'esbuild'
@@ -105,100 +123,16 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
105
123
  exclude: optimizeDepsExcludeDefaults,
106
124
  include: optimizeDepsIncludeDefaults
107
125
  },
126
+ // Payload's internal workaround plugins only. The RSC, TanStack Start, and
127
+ // React plugins are appended below (default form) or by the consumer's
128
+ // `build` callback (guest form).
108
129
  plugins: [
109
130
  clientModuleResolution(),
110
131
  wrapCjsForClient(),
111
132
  ssrStripDistStyleImports(),
112
133
  reactDomServerInRsc(),
113
134
  stubPrettierInClient(),
114
- payloadDevTransforms(),
115
- rsc({
116
- serverHandler: false
117
- }),
118
- tanstackStart({
119
- importProtection: {
120
- client: {
121
- excludeFiles: [],
122
- specifiers: serverOnlyClientSpecifiers
123
- },
124
- ignoreImporters: [
125
- ...defaultImportProtectionIgnoreImporters,
126
- ...additionalIgnoreImporters
127
- ],
128
- include: [
129
- '**/*'
130
- ],
131
- mockAccess: 'warn',
132
- onViolation: onImportProtectionViolation,
133
- // Disable TanStack Start's default `**/*.client.*` file-based denial in
134
- // the SSR environment. Payload uses the `.client.tsx` filename suffix
135
- // for React Client Components (with a `'use client'` directive) that
136
- // MUST be server-rendered to HTML during SSR. The default rule would
137
- // otherwise replace those files with an `import-protection mock` Proxy
138
- // during SSR, which crashes React (TypeError: Cannot convert object to
139
- // primitive value) the moment React tries to format a warning that
140
- // mentions one of these components.
141
- server: {
142
- files: []
143
- }
144
- },
145
- // Disable TanStack Router's automatic per-route code-splitting.
146
- //
147
- // With splitting enabled each route's `component` is fetched lazily
148
- // via `?tsr-split=component` after the initial SSR HTML is streamed.
149
- // Until that lazy chunk lands the rendered admin tree has no client
150
- // React attached, so any button clicks (e.g. the
151
- // `#toggle-list-filters` chevron in `<ListControls />`) hit a static
152
- // DOM, the click is dropped, and once the chunk finally loads the
153
- // component re-mounts with its initial `useState` instead of the
154
- // toggled value. That single behaviour was the root cause of the
155
- // "page renders but nothing is interactive" tanstack-start E2E
156
- // failures (`#list-controls-where`, `[data-lexical-editor]`, etc.) -
157
- // playwright traces show "Download the React DevTools" landing
158
- // *after* the playwright click, confirming late hydration.
159
- //
160
- // We pass BOTH knobs because `tanstackStart`'s schema silently
161
- // strips the user-supplied `autoCodeSplitting` (its `tsrConfig`
162
- // does `configSchema.omit({ autoCodeSplitting: true, target: true
163
- // })`) and then leaves the value `undefined` — which is fine for
164
- // the conditional inside `unpluginRouterComposedFactory`, but the
165
- // TanStack Start vite plugin *unconditionally* installs the router
166
- // code-splitter via `tanStackRouterCodeSplitter(...)` regardless.
167
- // The only knob that survives all of that and is honoured by the
168
- // splitter is `router.codeSplittingOptions.defaultBehavior` — set
169
- // to an empty array, the splitter still walks each `createFileRoute`
170
- // file but produces no virtual `?tsr-split=...` modules, so every
171
- // route component ships in the initial bundle and hydration starts
172
- // immediately on first paint. We keep `autoCodeSplitting: false` as
173
- // a belt-and-braces signal in case the start plugin ever stops
174
- // dropping it.
175
- //
176
- // Eager-loading routes ships a slightly larger initial bundle but
177
- // makes the admin actually interactive on first paint.
178
- router: {
179
- autoCodeSplitting: false,
180
- codeSplittingOptions: {
181
- defaultBehavior: []
182
- },
183
- // Exclude generated importMap files and colocated server-function
184
- // modules (`*.functions.ts`). Admin form saves are dispatched via
185
- // `runPayloadServerFn` (a TanStack Start `createServerFn`) rather than
186
- // a hand-rolled route, so there is no longer an `api.server-function.ts`
187
- // to special-case here. The `*.functions.ts` shims live next to the
188
- // routes that use them (e.g. `app/_payload/*.functions.ts`); they
189
- // define `createServerFn`s, not routes, so they must not be scanned.
190
- routeFileIgnorePattern: 'importMap\\.(?:js|server\\.ts)$|\\.functions\\.',
191
- routesDirectory
192
- },
193
- rsc: {
194
- enabled: true
195
- },
196
- srcDirectory
197
- }),
198
- viteReact({
199
- exclude: [],
200
- include: /\.[jt]sx?$/
201
- })
135
+ payloadDevTransforms()
202
136
  ],
203
137
  resolve: {
204
138
  alias: [
@@ -230,11 +164,95 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
230
164
  noExternal: payloadNoExternalPatterns
231
165
  }
232
166
  };
233
- const merged = vite ? mergeConfig(base, vite) : base;
234
- if (silenceDependencyWarnings) {
235
- merged.customLogger = withQuietedDependencyWarnings(merged.customLogger);
167
+ const pluginOptions = {
168
+ react: payloadReactOptions(),
169
+ rsc: payloadRscOptions(),
170
+ tanstackStart: payloadTanstackStartOptions({
171
+ additionalIgnoreImporters,
172
+ adminRouteId,
173
+ clientDenialExcludeFiles,
174
+ routesDirectory,
175
+ srcDirectory
176
+ })
177
+ };
178
+ if (build) {
179
+ return applyDependencyWarningSuppression(build({
180
+ config: base,
181
+ env,
182
+ pluginOptions
183
+ }), silenceDependencyWarnings);
236
184
  }
237
- return merged;
185
+ base.plugins = [
186
+ ...base.plugins,
187
+ rsc(pluginOptions.rsc),
188
+ tanstackStart(pluginOptions.tanstackStart),
189
+ viteReact(pluginOptions.react)
190
+ ];
191
+ const merged = vite ? mergeConfig(base, vite) : base;
192
+ return applyDependencyWarningSuppression(merged, silenceDependencyWarnings);
193
+ };
194
+ }
195
+ /** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */ export function payloadRscOptions() {
196
+ return {
197
+ serverHandler: false
198
+ };
199
+ }
200
+ /** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */ export function payloadReactOptions() {
201
+ return {
202
+ exclude: [],
203
+ include: /\.[jt]sx?$/
204
+ };
205
+ }
206
+ /**
207
+ * The `tanstackStart` options Payload's admin requires (import-protection and
208
+ * code-splitting). TanStack Start is one-per-app, so a host that already runs it
209
+ * should merge these into its single `tanstackStart` call.
210
+ */ export function payloadTanstackStartOptions(args = {}) {
211
+ const { additionalIgnoreImporters = [], adminRouteId = '/_payload', clientDenialExcludeFiles = [], routesDirectory = 'app', srcDirectory = 'src' } = args;
212
+ return {
213
+ importProtection: {
214
+ client: {
215
+ excludeFiles: [],
216
+ specifiers: serverOnlyClientSpecifiers
217
+ },
218
+ ignoreImporters: [
219
+ ...defaultImportProtectionIgnoreImporters,
220
+ ...additionalIgnoreImporters
221
+ ],
222
+ include: [
223
+ '**/*'
224
+ ],
225
+ mockAccess: 'warn',
226
+ onViolation: onImportProtectionViolation,
227
+ // Payload's `.client.*` components are React Client Components that must be
228
+ // server-rendered during SSR; TanStack's default `**/*.client.*` server
229
+ // denial would mock and crash them. All such files live in `@payloadcms/*`
230
+ // packages, so keep the denial (host `.client.*` files still get it) and
231
+ // just exempt Payload's — `node_modules` covers published installs.
232
+ server: {
233
+ excludeFiles: [
234
+ '**/node_modules/**',
235
+ ...clientDenialExcludeFiles
236
+ ]
237
+ }
238
+ },
239
+ router: {
240
+ codeSplittingOptions: {
241
+ // Eager-load only Payload's admin routes so they hydrate on first paint —
242
+ // a split admin renders but isn't interactive until its lazy `?tsr-split=`
243
+ // chunk lands. Returning `[]` disables splitting for a route; `undefined`
244
+ // lets host routes keep TanStack's default per-route splitting.
245
+ splitBehavior: ({ routeId })=>routeId === adminRouteId || routeId.startsWith(`${adminRouteId}/`) ? [] : undefined
246
+ },
247
+ // Ignore generated importMap files and colocated `*.functions.ts` modules
248
+ // (they define `createServerFn`s, not routes).
249
+ routeFileIgnorePattern: 'importMap\\.(?:js|server\\.ts)$|\\.functions\\.',
250
+ routesDirectory
251
+ },
252
+ rsc: {
253
+ enabled: true
254
+ },
255
+ srcDirectory
238
256
  };
239
257
  }
240
258
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { Logger, 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 { createLogger, mergeConfig } from 'vite'\n\nimport { payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js'\nimport { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js'\nimport { payloadScssImporters } from './config/scss.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 { stubPrettierInClient } from './workarounds/stubPrettierInClient.js'\nimport { wrapCjsForClient } from './workarounds/wrapCjsForClient.js'\n\n/**\n * Vite dependency warnings Payload consumers can't act on: third-party packages\n * ship sourcemaps whose original sources aren't published, so Vite warns on\n * every one. Suppressed by default (see `silenceDependencyWarnings`).\n */\nconst suppressibleWarningPatterns = ['points to missing source files', 'Sourcemap for']\n\n/**\n * Wraps a Vite logger so warnings matching {@link suppressibleWarningPatterns}\n * are dropped. Mutates and returns the given logger (or a fresh default one).\n */\nfunction withQuietedDependencyWarnings(existing?: Logger): Logger {\n const logger = existing ?? createLogger()\n const shouldSuppress = (msg: unknown): boolean =>\n typeof msg === 'string' && suppressibleWarningPatterns.some((pattern) => msg.includes(pattern))\n\n const baseWarn = logger.warn.bind(logger)\n const baseWarnOnce = logger.warnOnce.bind(logger)\n logger.warn = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarn(msg, options)\n }\n }\n logger.warnOnce = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarnOnce(msg, options)\n }\n }\n return logger\n}\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 /**\n * Silence Vite warnings about third-party dependency sourcemaps pointing to\n * missing source files — noise Payload consumers can't act on. Defaults to\n * `true`; set `false` to see them. Composes with a `vite.customLogger`.\n */\n silenceDependencyWarnings?: boolean\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 silenceDependencyWarnings = true,\n srcDirectory = 'src',\n vite,\n } = options\n\n return (_env) => {\n const base: UserConfig = {\n build: {\n cssMinify: 'esbuild',\n },\n css: {\n preprocessorOptions: {\n scss: {\n importers: payloadScssImporters,\n silenceDeprecations: ['import', 'global-builtin'],\n } as any,\n },\n },\n define: {\n global: 'globalThis',\n },\n environments: {\n rsc: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n ssr: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n } as any,\n optimizeDeps: {\n exclude: optimizeDepsExcludeDefaults,\n include: optimizeDepsIncludeDefaults,\n },\n plugins: [\n clientModuleResolution(),\n wrapCjsForClient(),\n ssrStripDistStyleImports(),\n reactDomServerInRsc(),\n stubPrettierInClient(),\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 const merged = vite ? mergeConfig(base, vite) : base\n\n if (silenceDependencyWarnings) {\n merged.customLogger = withQuietedDependencyWarnings(merged.customLogger)\n }\n\n return merged\n }\n}\n"],"names":["tanstackStart","viteReact","rsc","path","createLogger","mergeConfig","payloadNoExternalPatterns","ssrExternalPackages","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","payloadScssImporters","defaultImportProtectionIgnoreImporters","onImportProtectionViolation","serverOnlyClientSpecifiers","clientModuleResolution","payloadDevTransforms","reactDomServerInRsc","ssrStripDistStyleImports","stubPrettierInClient","wrapCjsForClient","suppressibleWarningPatterns","withQuietedDependencyWarnings","existing","logger","shouldSuppress","msg","some","pattern","includes","baseWarn","warn","bind","baseWarnOnce","warnOnce","options","withPayload","additionalIgnoreImporters","payloadConfigPath","routesDirectory","silenceDependencyWarnings","srcDirectory","vite","_env","base","build","cssMinify","css","preprocessorOptions","scss","importers","silenceDeprecations","define","global","environments","rollupOptions","external","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","merged","customLogger"],"mappings":"AAEA,SAASA,aAAa,QAAQ,oCAAmC;AACjE,OAAOC,eAAe,uBAAsB;AAC5C,OAAOC,SAAS,qBAAoB;AACpC,OAAOC,UAAU,YAAW;AAC5B,SAASC,YAAY,EAAEC,WAAW,QAAQ,OAAM;AAEhD,SAASC,yBAAyB,EAAEC,mBAAmB,QAAQ,uBAAsB;AACrF,SAASC,2BAA2B,EAAEC,2BAA2B,QAAQ,2BAA0B;AACnG,SAASC,oBAAoB,QAAQ,mBAAkB;AACvD,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,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,gBAAgB,QAAQ,oCAAmC;AAEpE;;;;CAIC,GACD,MAAMC,8BAA8B;IAAC;IAAkC;CAAgB;AAEvF;;;CAGC,GACD,SAASC,8BAA8BC,QAAiB;IACtD,MAAMC,SAASD,YAAYlB;IAC3B,MAAMoB,iBAAiB,CAACC,MACtB,OAAOA,QAAQ,YAAY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;wBAAEC,MAAM;wBAAmBC,aAAa9E,KAAKqD,OAAO,CAACnB;oBAAmB;iBAAE;gBAClF6C,QAAQ;oBACN;oBACA;oBACA;oBACA;oBACA;iBACD;gBACDC,YAAY;oBAAC;oBAAQ;oBAAO;oBAAQ;oBAAO;oBAAQ;oBAAQ;iBAAQ;gBACnEC,eAAe;YACjB;YACA1B,KAAK;gBACHH,UAAUhD;gBACVkD,YAAYnD;YACd;QACF;QAEA,MAAM+E,SAAS5C,OAAOpC,YAAYsC,MAAMF,QAAQE;QAEhD,IAAIJ,2BAA2B;YAC7B8C,OAAOC,YAAY,GAAGjE,8BAA8BgE,OAAOC,YAAY;QACzE;QAEA,OAAOD;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { ConfigEnv, Logger, PluginOption, UserConfig, UserConfigFnObject } from 'vite'\n\n// Optional peers, not deps: `plugin-rsc` is a singleton, so bundling our own copy\n// alongside the host's would load two instances and crash.\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 { createLogger, mergeConfig } from 'vite'\n\nimport { payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js'\nimport { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js'\nimport { payloadScssImporters } from './config/scss.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 { stubPrettierInClient } from './workarounds/stubPrettierInClient.js'\nimport { wrapCjsForClient } from './workarounds/wrapCjsForClient.js'\n\n/**\n * Vite dependency warnings Payload consumers can't act on: third-party packages\n * ship sourcemaps whose original sources aren't published, so Vite warns on\n * every one. Suppressed by default (see `silenceDependencyWarnings`).\n */\nconst suppressibleWarningPatterns = ['points to missing source files', 'Sourcemap for']\n\n/**\n * Wraps a Vite logger so warnings matching {@link suppressibleWarningPatterns}\n * are dropped. Mutates and returns the given logger (or a fresh default one).\n */\nfunction withQuietedDependencyWarnings(existing?: Logger): Logger {\n const logger = existing ?? createLogger()\n const shouldSuppress = (msg: unknown): boolean =>\n typeof msg === 'string' && suppressibleWarningPatterns.some((pattern) => msg.includes(pattern))\n\n const baseWarn = logger.warn.bind(logger)\n const baseWarnOnce = logger.warnOnce.bind(logger)\n logger.warn = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarn(msg, options)\n }\n }\n logger.warnOnce = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarnOnce(msg, options)\n }\n }\n return logger\n}\n\n/** Applies dependency-warning suppression to a config in place when enabled. */\nfunction applyDependencyWarningSuppression(config: UserConfig, enabled: boolean): UserConfig {\n if (enabled) {\n config.customLogger = withQuietedDependencyWarnings(config.customLogger)\n }\n return config\n}\n\nexport type WithPayloadOptions = {\n /** Extra import-protection `ignoreImporters` patterns for the TanStack Start plugin. */\n additionalIgnoreImporters?: RegExp[]\n /** Route id of Payload's admin layout, eager-loaded instead of code-split. Defaults to `'/_payload'`. */\n adminRouteId?: string\n /** Extra globs exempted from the `.client.*` SSR denial (beyond the default node_modules exemption). */\n clientDenialExcludeFiles?: string[]\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 /** Silence Vite warnings about third-party dependency sourcemaps. Defaults to `true`. */\n silenceDependencyWarnings?: boolean\n /** TanStack source directory. Defaults to `'src'` */\n srcDirectory?: string\n /** Extra Vite config deep-merged over the Payload defaults. Ignored in `build` mode. */\n vite?: UserConfig\n}\n\n/** The options Payload's admin requires for each third-party plugin. */\nexport type PayloadPluginOptions = {\n react: NonNullable<Parameters<typeof viteReact>[0]>\n rsc: NonNullable<Parameters<typeof rsc>[0]>\n tanstackStart: NonNullable<Parameters<typeof tanstackStart>[0]>\n}\n\nexport type WithPayloadBuilderContext = {\n /** Payload's base Vite config; `plugins` holds Payload's workaround plugins only. */\n config: UserConfig\n env: ConfigEnv\n /** Options to pass to the `viteReact`/`rsc`/`tanstackStart` factories you import. */\n pluginOptions: PayloadPluginOptions\n}\n\n/** Assembles the final Vite config from Payload's base config and plugin options. */\nexport type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserConfig\n\n/**\n * Vite config helper for Payload + TanStack Start; the counterpart to Next.js'\n * `withPayload`.\n *\n * Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:\n *\n * ```ts\n * export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })\n * ```\n *\n * Guest mode — pass a `build` callback to instantiate them yourself (one copy of\n * each; `@vitejs/plugin-rsc` is a hard singleton):\n *\n * ```ts\n * export default withPayload(\n * ({ config, pluginOptions }) => ({\n * ...config,\n * plugins: [\n * ...config.plugins,\n * rsc(pluginOptions.rsc),\n * tanstackStart(pluginOptions.tanstackStart),\n * viteReact(pluginOptions.react),\n * ],\n * }),\n * { payloadConfigPath: './src/payload.config.ts' },\n * )\n * ```\n */\nexport function withPayload(\n build: undefined | WithPayloadBuilder,\n options: WithPayloadOptions,\n): UserConfigFnObject {\n const {\n additionalIgnoreImporters = [],\n adminRouteId,\n clientDenialExcludeFiles = [],\n payloadConfigPath,\n routesDirectory = 'app',\n silenceDependencyWarnings = true,\n srcDirectory = 'src',\n vite,\n } = options\n\n return (env) => {\n const base: UserConfig = {\n build: {\n cssMinify: 'esbuild',\n },\n css: {\n preprocessorOptions: {\n scss: {\n importers: payloadScssImporters,\n silenceDeprecations: ['import', 'global-builtin'],\n } as any,\n },\n },\n define: {\n global: 'globalThis',\n },\n environments: {\n rsc: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n ssr: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n } as any,\n optimizeDeps: {\n exclude: optimizeDepsExcludeDefaults,\n include: optimizeDepsIncludeDefaults,\n },\n // Payload's internal workaround plugins only. The RSC, TanStack Start, and\n // React plugins are appended below (default form) or by the consumer's\n // `build` callback (guest form).\n plugins: [\n clientModuleResolution(),\n wrapCjsForClient(),\n ssrStripDistStyleImports(),\n reactDomServerInRsc(),\n stubPrettierInClient(),\n payloadDevTransforms(),\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 const pluginOptions: PayloadPluginOptions = {\n react: payloadReactOptions(),\n rsc: payloadRscOptions(),\n tanstackStart: payloadTanstackStartOptions({\n additionalIgnoreImporters,\n adminRouteId,\n clientDenialExcludeFiles,\n routesDirectory,\n srcDirectory,\n }),\n }\n\n if (build) {\n return applyDependencyWarningSuppression(\n build({ config: base, env, pluginOptions }),\n silenceDependencyWarnings,\n )\n }\n\n base.plugins = [\n ...(base.plugins as PluginOption[]),\n rsc(pluginOptions.rsc),\n tanstackStart(pluginOptions.tanstackStart),\n viteReact(pluginOptions.react),\n ]\n\n const merged = vite ? mergeConfig(base, vite) : base\n\n return applyDependencyWarningSuppression(merged, silenceDependencyWarnings)\n }\n}\n\n/** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */\nexport function payloadRscOptions(): NonNullable<Parameters<typeof rsc>[0]> {\n return { serverHandler: false }\n}\n\n/** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */\nexport function payloadReactOptions(): NonNullable<Parameters<typeof viteReact>[0]> {\n return { exclude: [], include: /\\.[jt]sx?$/ }\n}\n\nexport type PayloadTanstackStartOptionsArgs = {\n /** Additional import-protection `ignoreImporters` patterns. */\n additionalIgnoreImporters?: RegExp[]\n /**\n * Route id of Payload's admin layout route, eager-loaded (not code-split) so it\n * hydrates on first paint. It and its children skip splitting; host routes keep\n * TanStack's default. Defaults to `'/_payload'` (the `_payload.tsx` convention).\n */\n adminRouteId?: string\n /**\n * Extra globs exempted from TanStack's `.client.*` SSR denial, on top of the\n * default node_modules exemption. Needed only when Payload's own `.client.*`\n * files resolve outside node_modules (e.g. the monorepo's `packages` sources).\n */\n clientDenialExcludeFiles?: 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\n/**\n * The `tanstackStart` options Payload's admin requires (import-protection and\n * code-splitting). TanStack Start is one-per-app, so a host that already runs it\n * should merge these into its single `tanstackStart` call.\n */\nexport function payloadTanstackStartOptions(\n args: PayloadTanstackStartOptionsArgs = {},\n): NonNullable<Parameters<typeof tanstackStart>[0]> {\n const {\n additionalIgnoreImporters = [],\n adminRouteId = '/_payload',\n clientDenialExcludeFiles = [],\n routesDirectory = 'app',\n srcDirectory = 'src',\n } = args\n\n return {\n importProtection: {\n client: { excludeFiles: [], specifiers: serverOnlyClientSpecifiers },\n ignoreImporters: [...defaultImportProtectionIgnoreImporters, ...additionalIgnoreImporters],\n include: ['**/*'],\n mockAccess: 'warn',\n onViolation: onImportProtectionViolation,\n // Payload's `.client.*` components are React Client Components that must be\n // server-rendered during SSR; TanStack's default `**/*.client.*` server\n // denial would mock and crash them. All such files live in `@payloadcms/*`\n // packages, so keep the denial (host `.client.*` files still get it) and\n // just exempt Payload's — `node_modules` covers published installs.\n server: { excludeFiles: ['**/node_modules/**', ...clientDenialExcludeFiles] },\n },\n router: {\n codeSplittingOptions: {\n // Eager-load only Payload's admin routes so they hydrate on first paint —\n // a split admin renders but isn't interactive until its lazy `?tsr-split=`\n // chunk lands. Returning `[]` disables splitting for a route; `undefined`\n // lets host routes keep TanStack's default per-route splitting.\n splitBehavior: ({ routeId }: { routeId: string }) =>\n routeId === adminRouteId || routeId.startsWith(`${adminRouteId}/`) ? [] : undefined,\n },\n // Ignore generated importMap files and colocated `*.functions.ts` modules\n // (they define `createServerFn`s, not routes).\n routeFileIgnorePattern: 'importMap\\\\.(?:js|server\\\\.ts)$|\\\\.functions\\\\.',\n routesDirectory,\n } as any,\n rsc: { enabled: true },\n srcDirectory,\n }\n}\n"],"names":["tanstackStart","viteReact","rsc","path","createLogger","mergeConfig","payloadNoExternalPatterns","ssrExternalPackages","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","payloadScssImporters","defaultImportProtectionIgnoreImporters","onImportProtectionViolation","serverOnlyClientSpecifiers","clientModuleResolution","payloadDevTransforms","reactDomServerInRsc","ssrStripDistStyleImports","stubPrettierInClient","wrapCjsForClient","suppressibleWarningPatterns","withQuietedDependencyWarnings","existing","logger","shouldSuppress","msg","some","pattern","includes","baseWarn","warn","bind","baseWarnOnce","warnOnce","options","applyDependencyWarningSuppression","config","enabled","customLogger","withPayload","build","additionalIgnoreImporters","adminRouteId","clientDenialExcludeFiles","payloadConfigPath","routesDirectory","silenceDependencyWarnings","srcDirectory","vite","env","base","cssMinify","css","preprocessorOptions","scss","importers","silenceDeprecations","define","global","environments","rollupOptions","external","resolve","noExternal","ssr","optimizeDeps","exclude","include","plugins","alias","find","replacement","dedupe","extensions","tsconfigPaths","pluginOptions","react","payloadReactOptions","payloadRscOptions","payloadTanstackStartOptions","merged","serverHandler","args","importProtection","client","excludeFiles","specifiers","ignoreImporters","mockAccess","onViolation","server","router","codeSplittingOptions","splitBehavior","routeId","startsWith","undefined","routeFileIgnorePattern"],"mappings":"AAEA,kFAAkF;AAClF,2DAA2D;AAC3D,SAASA,aAAa,QAAQ,oCAAmC;AACjE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,2EAA2E;gBAC3E,0EAA0E;gBAC1E,gEAAgE;gBAChEC,eAAe,CAAC,EAAEC,OAAO,EAAuB,GAC9CA,YAAYpD,gBAAgBoD,QAAQC,UAAU,CAAC,GAAGrD,aAAa,CAAC,CAAC,IAAI,EAAE,GAAGsD;YAC9E;YACA,0EAA0E;YAC1E,+CAA+C;YAC/CC,wBAAwB;YACxBpD;QACF;QACA3C,KAAK;YAAEmC,SAAS;QAAK;QACrBU;IACF;AACF"}
@@ -1 +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"}
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,CAgEnD"}
@@ -38,6 +38,11 @@ window.__vite_plugin_react_preamble_installed__ = true
38
38
  return chunk;
39
39
  }
40
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
+ }
41
46
  if (str && str.includes('</head>')) {
42
47
  injected = true;
43
48
  return str.replace('</head>', `${devScripts}</head>`);
@@ -1 +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"}
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 // 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"}
@@ -2,20 +2,12 @@ import type { PluginOption } from 'vite';
2
2
  /**
3
3
  * Stubs `prettier` in the CLIENT bundle only.
4
4
  *
5
- * `payload`'s barrel transitively pulls `configToJSONSchema` →
6
- * `json-schema-to-typescript` → `prettier` (CommonJS) into the client module
7
- * graph through re-export side effects. That path is type-generation only
8
- * (`payload generate:types`) and never runs in the browser, but the bundler
9
- * still drags `prettier`'s `index.cjs` in — where it fails to parse as ESM and
10
- * breaks the client build.
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.
11
9
  *
12
- * We redirect `prettier` to a no-op `format` stub in the client environment
13
- * only. SSR/RSC keep the real `prettier` (there `json-schema-to-typescript`
14
- * stays external and resolves it from `node_modules`), and the `prettier` CLI /
15
- * `payload generate:types` are unaffected.
16
- *
17
- * Delete this once `payload`'s barrel no longer reaches the type-gen path from
18
- * the client-reachable export graph.
10
+ * Delete once `payload`'s barrel no longer reaches type-gen from the client graph.
19
11
  */
20
12
  export declare function stubPrettierInClient(): PluginOption;
21
13
  //# sourceMappingURL=stubPrettierInClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stubPrettierInClient.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/stubPrettierInClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAoBnD"}
1
+ {"version":3,"file":"stubPrettierInClient.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/stubPrettierInClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAqBnD"}
@@ -1,20 +1,12 @@
1
1
  /**
2
2
  * Stubs `prettier` in the CLIENT bundle only.
3
3
  *
4
- * `payload`'s barrel transitively pulls `configToJSONSchema` →
5
- * `json-schema-to-typescript` → `prettier` (CommonJS) into the client module
6
- * graph through re-export side effects. That path is type-generation only
7
- * (`payload generate:types`) and never runs in the browser, but the bundler
8
- * still drags `prettier`'s `index.cjs` in — where it fails to parse as ESM and
9
- * breaks the client build.
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.
10
8
  *
11
- * We redirect `prettier` to a no-op `format` stub in the client environment
12
- * only. SSR/RSC keep the real `prettier` (there `json-schema-to-typescript`
13
- * stays external and resolves it from `node_modules`), and the `prettier` CLI /
14
- * `payload generate:types` are unaffected.
15
- *
16
- * Delete this once `payload`'s barrel no longer reaches the type-gen path from
17
- * the client-reachable export graph.
9
+ * Delete once `payload`'s barrel no longer reaches type-gen from the client graph.
18
10
  */ export function stubPrettierInClient() {
19
11
  const RESOLVED_ID = '\0payload:prettier-client-stub';
20
12
  return {
@@ -25,11 +17,12 @@
25
17
  return 'export const format = (source) => source;\nexport default { format };';
26
18
  }
27
19
  },
28
- resolveId (id, _importer, options) {
20
+ resolveId (id, importer, options) {
29
21
  if (options?.ssr) {
30
22
  return;
31
23
  }
32
- if (id === 'prettier') {
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')) {
33
26
  return RESOLVED_ID;
34
27
  }
35
28
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/vite/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 `configToJSONSchema` →\n * `json-schema-to-typescript` → `prettier` (CommonJS) into the client module\n * graph through re-export side effects. That path is type-generation only\n * (`payload generate:types`) and never runs in the browser, but the bundler\n * still drags `prettier`'s `index.cjs` in where it fails to parse as ESM and\n * breaks the client build.\n *\n * We redirect `prettier` to a no-op `format` stub in the client environment\n * only. SSR/RSC keep the real `prettier` (there `json-schema-to-typescript`\n * stays external and resolves it from `node_modules`), and the `prettier` CLI /\n * `payload generate:types` are unaffected.\n *\n * Delete this once `payload`'s barrel no longer reaches the type-gen path from\n * the client-reachable export 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 if (id === 'prettier') {\n return RESOLVED_ID\n }\n },\n }\n}\n"],"names":["stubPrettierInClient","RESOLVED_ID","name","enforce","load","id","resolveId","_importer","options","ssr"],"mappings":"AAEA;;;;;;;;;;;;;;;;;CAiBC,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,SAAS,EAAEC,OAAO;YAC9B,IAAIA,SAASC,KAAK;gBAChB;YACF;YACA,IAAIJ,OAAO,YAAY;gBACrB,OAAOJ;YACT;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/vite/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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/tanstack-start",
3
- "version": "4.0.0-internal.811e0a4",
3
+ "version": "4.0.0-internal.8ba6b5b",
4
4
  "description": "TanStack Start framework adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -57,32 +57,39 @@
57
57
  "dist"
58
58
  ],
59
59
  "dependencies": {
60
- "@vitejs/plugin-react": "^6.0.0",
61
- "@vitejs/plugin-rsc": "^0.5.21",
62
60
  "qs-esm": "^7.0.2",
63
- "@payloadcms/translations": "4.0.0-internal.811e0a4",
64
- "@payloadcms/ui": "4.0.0-internal.811e0a4"
61
+ "@payloadcms/translations": "4.0.0-internal.8ba6b5b",
62
+ "@payloadcms/ui": "4.0.0-internal.8ba6b5b"
65
63
  },
66
64
  "devDependencies": {
67
65
  "@tanstack/react-router": "^1.120.0",
68
66
  "@tanstack/react-start": "^1.168.26",
69
67
  "@types/react": "^19.0.0",
70
68
  "@types/react-dom": "^19.0.0",
69
+ "@vitejs/plugin-react": "^6.0.0",
71
70
  "@vitejs/plugin-rsc": "^0.5.21",
72
71
  "react": "^19.0.0",
73
72
  "react-dom": "^19.0.0",
74
73
  "vite": ">=8.0.0",
75
- "payload": "4.0.0-internal.811e0a4"
74
+ "payload": "4.0.0-internal.8ba6b5b"
76
75
  },
77
76
  "peerDependencies": {
78
77
  "@tanstack/react-router": "^1.120.0",
79
78
  "@tanstack/react-start": "^1.168.26",
79
+ "@vitejs/plugin-react": "^6.0.0",
80
+ "@vitejs/plugin-rsc": "^0.5.21",
80
81
  "react": "^19.0.0",
81
82
  "react-dom": "^19.0.0",
82
83
  "vite": ">=8.0.0",
83
- "payload": "4.0.0-internal.811e0a4"
84
+ "payload": "4.0.0-internal.8ba6b5b"
84
85
  },
85
86
  "peerDependenciesMeta": {
87
+ "@vitejs/plugin-react": {
88
+ "optional": true
89
+ },
90
+ "@vitejs/plugin-rsc": {
91
+ "optional": true
92
+ },
86
93
  "vite": {
87
94
  "optional": true
88
95
  }