@payloadcms/tanstack-start 4.0.0-internal.293e026 → 4.0.0-internal.45cfa3d

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 (130) 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/serverFunctionClient.d.ts +29 -0
  64. package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
  65. package/dist/utilities/serverFunctionClient.js +109 -0
  66. package/dist/utilities/serverFunctionClient.js.map +1 -0
  67. package/dist/vite/config/external.d.ts +26 -0
  68. package/dist/vite/config/external.d.ts.map +1 -0
  69. package/dist/vite/config/external.js +57 -0
  70. package/dist/vite/config/external.js.map +1 -0
  71. package/dist/vite/config/optimizeDeps.d.ts +25 -0
  72. package/dist/vite/config/optimizeDeps.d.ts.map +1 -0
  73. package/dist/vite/config/optimizeDeps.js +123 -0
  74. package/dist/vite/config/optimizeDeps.js.map +1 -0
  75. package/dist/vite/config/scss.d.ts +14 -0
  76. package/dist/vite/config/scss.d.ts.map +1 -0
  77. package/dist/vite/config/scss.js +28 -0
  78. package/dist/vite/config/scss.js.map +1 -0
  79. package/dist/vite/index.d.ts +55 -0
  80. package/dist/vite/index.d.ts.map +1 -0
  81. package/dist/vite/{plugin.js → index.js} +91 -46
  82. package/dist/vite/index.js.map +1 -0
  83. package/dist/vite/workarounds/clientModuleResolution.d.ts.map +1 -0
  84. package/dist/vite/workarounds/clientModuleResolution.js.map +1 -0
  85. package/dist/vite/workarounds/devTransforms.d.ts.map +1 -0
  86. package/dist/vite/workarounds/devTransforms.js.map +1 -0
  87. package/dist/vite/workarounds/reactDomServerInRsc.d.ts.map +1 -0
  88. package/dist/vite/workarounds/reactDomServerInRsc.js.map +1 -0
  89. package/dist/vite/workarounds/stripDistStyleImports.d.ts.map +1 -0
  90. package/dist/vite/{plugins → workarounds}/stripDistStyleImports.js +37 -4
  91. package/dist/vite/workarounds/stripDistStyleImports.js.map +1 -0
  92. package/dist/vite/workarounds/stubPrettierInClient.d.ts +21 -0
  93. package/dist/vite/workarounds/stubPrettierInClient.d.ts.map +1 -0
  94. package/dist/vite/workarounds/stubPrettierInClient.js +39 -0
  95. package/dist/vite/workarounds/stubPrettierInClient.js.map +1 -0
  96. package/dist/vite/workarounds/wrapCjsForClient.d.ts.map +1 -0
  97. package/dist/vite/workarounds/wrapCjsForClient.js.map +1 -0
  98. package/package.json +10 -12
  99. package/dist/@types/assets.d.js +0 -2
  100. package/dist/@types/assets.d.js.map +0 -1
  101. package/dist/auth/switchLanguage.d.ts +0 -6
  102. package/dist/auth/switchLanguage.d.ts.map +0 -1
  103. package/dist/auth/switchLanguage.js +0 -11
  104. package/dist/auth/switchLanguage.js.map +0 -1
  105. package/dist/vite/constants.d.ts +0 -37
  106. package/dist/vite/constants.d.ts.map +0 -1
  107. package/dist/vite/constants.js +0 -129
  108. package/dist/vite/constants.js.map +0 -1
  109. package/dist/vite/plugin.d.ts +0 -38
  110. package/dist/vite/plugin.d.ts.map +0 -1
  111. package/dist/vite/plugin.js.map +0 -1
  112. package/dist/vite/plugins/clientModuleResolution.d.ts.map +0 -1
  113. package/dist/vite/plugins/clientModuleResolution.js.map +0 -1
  114. package/dist/vite/plugins/devTransforms.d.ts.map +0 -1
  115. package/dist/vite/plugins/devTransforms.js.map +0 -1
  116. package/dist/vite/plugins/reactDomServerInRsc.d.ts.map +0 -1
  117. package/dist/vite/plugins/reactDomServerInRsc.js.map +0 -1
  118. package/dist/vite/plugins/stripDistStyleImports.d.ts.map +0 -1
  119. package/dist/vite/plugins/stripDistStyleImports.js.map +0 -1
  120. package/dist/vite/plugins/wrapCjsForClient.d.ts.map +0 -1
  121. package/dist/vite/plugins/wrapCjsForClient.js.map +0 -1
  122. /package/dist/vite/{plugins → workarounds}/clientModuleResolution.d.ts +0 -0
  123. /package/dist/vite/{plugins → workarounds}/clientModuleResolution.js +0 -0
  124. /package/dist/vite/{plugins → workarounds}/devTransforms.d.ts +0 -0
  125. /package/dist/vite/{plugins → workarounds}/devTransforms.js +0 -0
  126. /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.d.ts +0 -0
  127. /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.js +0 -0
  128. /package/dist/vite/{plugins → workarounds}/stripDistStyleImports.d.ts +0 -0
  129. /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.d.ts +0 -0
  130. /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.js +0 -0
@@ -0,0 +1,54 @@
1
+ import type { ImportMap, SanitizedConfig } from 'payload';
2
+ import type { AdminPageMetadata } from './meta.js';
3
+ export type LoadAdminPageArgs = {
4
+ config: SanitizedConfig;
5
+ importMap: ImportMap;
6
+ search?: Record<string, string | string[]>;
7
+ splat?: string;
8
+ };
9
+ export type LoadAdminPageResult = {
10
+ _notFound: true;
11
+ routeKey?: string;
12
+ rscPayload?: React.ReactNode;
13
+ } | {
14
+ _redirect: string;
15
+ } | {
16
+ metadata: AdminPageMetadata;
17
+ /**
18
+ * Stable identity for this rendered route (the splat, i.e. the path
19
+ * after `/admin/`). The client keys the rendered subtree by this so the
20
+ * view remounts exactly when a new payload arrives. Keying by
21
+ * `location.pathname` instead races: the pathname updates before
22
+ * `useLoaderData()` during a transition, so the subtree would remount
23
+ * with the *previous* payload and then reconcile the fresh payload in
24
+ * place — leaving client providers (DocumentInfo, etc.) holding stale
25
+ * `useState` values from the prior document. Search params are excluded
26
+ * so search-only changes (e.g. list-view filtering) reconcile in place.
27
+ */
28
+ routeKey: string;
29
+ rscPayload: React.ReactNode;
30
+ };
31
+ /**
32
+ * Renders an admin page for TanStack Start and returns a serializable loader
33
+ * result. The framework adapter wraps this in a `createServerFn` that supplies
34
+ * the app's `config` and generated `importMap`.
35
+ *
36
+ * 1. Initializes the Payload request via the shared `renderRoot` orchestrator
37
+ * from `@payloadcms/ui`, passing a TanStack-bound `initReq`. The injected
38
+ * page-render `ServerAdapter` records navigation intent and throws the
39
+ * framework-agnostic error contract.
40
+ * 2. Pipes the resulting React server tree through `renderServerComponent`
41
+ * to produce a Flight payload the client consumes directly.
42
+ * 3. Resolves page metadata via the same shared `generatePageMetadata`
43
+ * Next.js uses, returning plain serializable strings for `head()`.
44
+ *
45
+ * Navigation surfaces two ways and both become a `_notFound` / `_redirect`
46
+ * sentinel the route loader re-throws as native TanStack nav:
47
+ * - thrown during `renderRoot` orchestration (e.g. the login redirect) → caught
48
+ * by the try/catch below;
49
+ * - thrown deep inside a streamed view component (e.g. `DocumentView` access
50
+ * denied, `LoginView` already-authenticated) → swallowed into the RSC stream,
51
+ * so it's read from the `nav` holder after `renderServerComponent` resolves.
52
+ */
53
+ export declare function loadAdminPage({ config, importMap, search, splat, }: LoadAdminPageArgs): Promise<LoadAdminPageResult>;
54
+ //# sourceMappingURL=loadAdminPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadAdminPage.d.ts","sourceRoot":"","sources":["../../src/utilities/loadAdminPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,eAAe,EAAE,MAAM,SAAS,CAAA;AAIrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAMlD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAA;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,GACpE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB;IACE,QAAQ,EAAE,iBAAiB,CAAA;IAC3B;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B,CAAA;AA0FL;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoJlD"}
@@ -0,0 +1,230 @@
1
+ import { renderServerComponent } from '@tanstack/react-start/rsc';
2
+ import { getRequestI18n } from './getRequestI18n.server.js';
3
+ import { initReq } from './initReq.server.js';
4
+ import { createPageRenderServerAdapter } from './serverAdapter.server.js';
5
+ const resolveTitle = (title)=>{
6
+ if (!title) {
7
+ return undefined;
8
+ }
9
+ if (typeof title === 'string') {
10
+ return title;
11
+ }
12
+ if ('absolute' in title) {
13
+ return title.absolute;
14
+ }
15
+ return title.default;
16
+ };
17
+ /**
18
+ * Flattens the framework-agnostic `MetaConfig` (Next.js `Metadata` shape) into
19
+ * the plain, serializable `AdminPageMetadata` the route loader ships to the
20
+ * client. The full `MetaConfig` carries a `URL` `metadataBase`, functions and
21
+ * other non-serializable values that seroval cannot cross the wire, so only the
22
+ * fields `getAdminMeta` renders are extracted.
23
+ */ const toAdminPageMetadata = (meta)=>{
24
+ const og = meta.openGraph;
25
+ const rawImages = og?.images;
26
+ const imagesArray = rawImages ? Array.isArray(rawImages) ? rawImages : [
27
+ rawImages
28
+ ] : [];
29
+ const images = imagesArray.map((image)=>typeof image === 'string' ? {
30
+ url: image
31
+ } : image?.url ? {
32
+ alt: image.alt,
33
+ height: image.height,
34
+ url: String(image.url),
35
+ width: image.width
36
+ } : undefined).filter(Boolean);
37
+ const rawIcons = meta.icons;
38
+ const iconList = Array.isArray(rawIcons) ? rawIcons : rawIcons && typeof rawIcons === 'object' && Array.isArray(rawIcons.icon) ? rawIcons.icon : [];
39
+ const icons = iconList.map((icon)=>typeof icon === 'string' ? {
40
+ rel: 'icon',
41
+ url: icon
42
+ } : icon?.url ? {
43
+ type: icon.type,
44
+ media: icon.media,
45
+ rel: icon.rel ?? 'icon',
46
+ sizes: icon.sizes,
47
+ url: String(icon.url)
48
+ } : undefined).filter(Boolean);
49
+ const keywords = meta.keywords;
50
+ return {
51
+ description: typeof meta.description === 'string' ? meta.description : undefined,
52
+ icons: icons?.length ? icons : undefined,
53
+ keywords: typeof keywords === 'string' ? keywords : Array.isArray(keywords) ? keywords.join(', ') : undefined,
54
+ openGraph: og ? {
55
+ description: typeof og.description === 'string' ? og.description : undefined,
56
+ images: images?.length ? images : undefined,
57
+ siteName: typeof og.siteName === 'string' ? og.siteName : undefined,
58
+ title: typeof og.title === 'string' ? og.title : undefined
59
+ } : undefined,
60
+ robots: typeof meta.robots === 'string' ? meta.robots : undefined,
61
+ title: resolveTitle(meta.title)
62
+ };
63
+ };
64
+ /**
65
+ * Renders an admin page for TanStack Start and returns a serializable loader
66
+ * result. The framework adapter wraps this in a `createServerFn` that supplies
67
+ * the app's `config` and generated `importMap`.
68
+ *
69
+ * 1. Initializes the Payload request via the shared `renderRoot` orchestrator
70
+ * from `@payloadcms/ui`, passing a TanStack-bound `initReq`. The injected
71
+ * page-render `ServerAdapter` records navigation intent and throws the
72
+ * framework-agnostic error contract.
73
+ * 2. Pipes the resulting React server tree through `renderServerComponent`
74
+ * to produce a Flight payload the client consumes directly.
75
+ * 3. Resolves page metadata via the same shared `generatePageMetadata`
76
+ * Next.js uses, returning plain serializable strings for `head()`.
77
+ *
78
+ * Navigation surfaces two ways and both become a `_notFound` / `_redirect`
79
+ * sentinel the route loader re-throws as native TanStack nav:
80
+ * - thrown during `renderRoot` orchestration (e.g. the login redirect) → caught
81
+ * by the try/catch below;
82
+ * - thrown deep inside a streamed view component (e.g. `DocumentView` access
83
+ * denied, `LoginView` already-authenticated) → swallowed into the RSC stream,
84
+ * so it's read from the `nav` holder after `renderServerComponent` resolves.
85
+ */ export async function loadAdminPage({ config, importMap, search, splat }) {
86
+ const { renderRoot } = await import('@payloadcms/ui/views/Root');
87
+ const { defaultAdminViews } = await import('@payloadcms/ui/views/Root/adminViews');
88
+ const { generatePageMetadata } = await import('@payloadcms/ui/views/Root/generatePageMetadata');
89
+ const splatSegments = splat ? splat.split('/').filter(Boolean) : [];
90
+ // Match Next's optional-catch-all behavior: the admin root (`/admin`) has no
91
+ // segments. Passing an empty array makes the shared `renderRoot` build
92
+ // `currentRoute` as `/admin/` (trailing slash), which no longer equals
93
+ // `adminRoute` and causes `handleAuthRedirect` to append `?redirect=/admin/`.
94
+ // Passing `undefined` yields `currentRoute = /admin`, so the unauthenticated
95
+ // redirect lands on a clean `/admin/login`.
96
+ const segments = splatSegments.length > 0 ? splatSegments : undefined;
97
+ const searchParams = search ?? {};
98
+ // Records navigation requested via `req.server.*` (including throws swallowed
99
+ // by RSC streaming deep inside view components). Read after the render.
100
+ const nav = {};
101
+ const pageServerAdapter = createPageRenderServerAdapter(nav);
102
+ // `renderRoot` calls `initReq` itself with its own overrides (query
103
+ // re-nesting, `urlSuffix`, `fallbackLocale`). Forward them, injecting the
104
+ // page-render `ServerAdapter` so `req.server.redirect()` / `.notFound()`
105
+ // is recorded + thrown rather than escaping as raw TanStack nav.
106
+ const boundInitReq = (args)=>initReq({
107
+ configPromise: args.configPromise,
108
+ importMap: args.importMap,
109
+ overrides: args.overrides,
110
+ serverAdapter: pageServerAdapter
111
+ });
112
+ const notFound = ()=>{
113
+ nav.type = 'notFound';
114
+ throw new Error('not-found');
115
+ };
116
+ const redirect = (url)=>{
117
+ nav.type = 'redirect';
118
+ nav.url = url;
119
+ throw new Error(`redirect:${url}`);
120
+ };
121
+ // Build the 404 result the route loader re-throws as TanStack `notFound()`.
122
+ //
123
+ // Throwing `notFound()` is the only way to set the SSR document status to 404
124
+ // (it's read from `router.stores.statusCode`, set by a not-found match — NOT
125
+ // from `setResponseStatus`, which only affects the RSC RPC response). But the
126
+ // matching `notFoundComponent` is a client component with no access to the
127
+ // Payload `req`, so it can't build the admin chrome on its own. To match Next
128
+ // (whose not-found route renders the full admin layout — nav sidebar, etc. —
129
+ // around the NotFound body, see `renderNotFoundPage`), we render that same
130
+ // shared `renderNotFoundPage` tree here, server-side, and ship its Flight
131
+ // payload through the `notFound()` error so the client renders it verbatim.
132
+ // For users without admin access `renderNotFoundPage` returns the bare
133
+ // `NotFoundClient`, preserving the access-denied behavior.
134
+ const renderNotFound = async ()=>{
135
+ const { renderNotFoundPage } = await import('@payloadcms/ui/views/NotFound/page');
136
+ const notFoundNode = await renderNotFoundPage({
137
+ config: Promise.resolve(config),
138
+ importMap,
139
+ initReq: (args)=>initReq({
140
+ configPromise: args.configPromise,
141
+ importMap: args.importMap,
142
+ overrides: args.overrides
143
+ }),
144
+ params: Promise.resolve({
145
+ segments: splatSegments
146
+ }),
147
+ searchParams: Promise.resolve(searchParams)
148
+ });
149
+ const rscPayload = await renderServerComponent(notFoundNode);
150
+ return {
151
+ _notFound: true,
152
+ routeKey: splat ?? '',
153
+ rscPayload
154
+ };
155
+ };
156
+ try {
157
+ const node = await renderRoot({
158
+ adminViews: defaultAdminViews,
159
+ config: Promise.resolve(config),
160
+ importMap,
161
+ initReq: boundInitReq,
162
+ notFound,
163
+ // `segments` is intentionally `undefined` for the admin root (`/admin`),
164
+ // matching Next's optional catch-all; `renderRoot` handles it at runtime.
165
+ params: Promise.resolve({
166
+ segments
167
+ }),
168
+ redirect,
169
+ searchParams: Promise.resolve(searchParams)
170
+ });
171
+ const rscPayload = await renderServerComponent(node);
172
+ // The server-function (client-nav RPC) path returns the flight stream unread —
173
+ // unlike the router/SSR path, which awaits a decode that drives the render to
174
+ // completion. So streamed side effects (e.g. DocumentView's autosave-create
175
+ // `server.redirect()`) haven't run yet and `nav` is empty. Buffer the stream to
176
+ // completion to force the render (populating `nav`), then hand the client a fresh
177
+ // replayable stream from that buffer.
178
+ if (!nav.type) {
179
+ const wrapper = rscPayload[Symbol.for('tanstack.rsc.stream')];
180
+ if (typeof wrapper?.createReplayStream === 'function') {
181
+ const buffer = await new Response(wrapper.createReplayStream()).arrayBuffer();
182
+ wrapper.createReplayStream = ()=>new Response(buffer).body;
183
+ }
184
+ }
185
+ // Navigation thrown deep inside a streamed view component (e.g. access
186
+ // denied → notFound, already-authenticated → redirect) is swallowed into
187
+ // the RSC stream and never rejects the render. Honor it from the holder,
188
+ // discarding the (broken) payload from the aborted render.
189
+ if (nav.type === 'redirect' && nav.url) {
190
+ return {
191
+ _redirect: nav.url
192
+ };
193
+ }
194
+ if (nav.type === 'notFound') {
195
+ return await renderNotFound();
196
+ }
197
+ // Resolve metadata through the same shared generator Next.js uses. Only
198
+ // plain strings cross the wire (the full `MetaConfig` carries a `URL`
199
+ // `metadataBase` and icons that seroval cannot serialize).
200
+ const i18n = await getRequestI18n({
201
+ config
202
+ });
203
+ const meta = await generatePageMetadata({
204
+ adminViews: defaultAdminViews,
205
+ config,
206
+ i18n,
207
+ params: {
208
+ segments
209
+ }
210
+ });
211
+ return {
212
+ metadata: toAdminPageMetadata(meta),
213
+ routeKey: splat ?? '',
214
+ rscPayload
215
+ };
216
+ } catch (err) {
217
+ const message = err instanceof Error ? err.message : String(err);
218
+ if (nav.type === 'notFound' || message === 'not-found') {
219
+ return await renderNotFound();
220
+ }
221
+ if (nav.type === 'redirect' || message.startsWith('redirect:')) {
222
+ return {
223
+ _redirect: nav.url ?? message.slice('redirect:'.length)
224
+ };
225
+ }
226
+ throw err;
227
+ }
228
+ }
229
+
230
+ //# sourceMappingURL=loadAdminPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/loadAdminPage.tsx"],"sourcesContent":["import type { ImportMap, MetaConfig, SanitizedConfig } from 'payload'\n\nimport { renderServerComponent } from '@tanstack/react-start/rsc'\n\nimport type { AdminPageMetadata } from './meta.js'\n\nimport { getRequestI18n } from './getRequestI18n.server.js'\nimport { initReq } from './initReq.server.js'\nimport { createPageRenderServerAdapter } from './serverAdapter.server.js'\n\nexport type LoadAdminPageArgs = {\n config: SanitizedConfig\n importMap: ImportMap\n search?: Record<string, string | string[]>\n splat?: string\n}\n\nexport type LoadAdminPageResult =\n | { _notFound: true; routeKey?: string; rscPayload?: React.ReactNode }\n | { _redirect: string }\n | {\n metadata: AdminPageMetadata\n /**\n * Stable identity for this rendered route (the splat, i.e. the path\n * after `/admin/`). The client keys the rendered subtree by this so the\n * view remounts exactly when a new payload arrives. Keying by\n * `location.pathname` instead races: the pathname updates before\n * `useLoaderData()` during a transition, so the subtree would remount\n * with the *previous* payload and then reconcile the fresh payload in\n * place — leaving client providers (DocumentInfo, etc.) holding stale\n * `useState` values from the prior document. Search params are excluded\n * so search-only changes (e.g. list-view filtering) reconcile in place.\n */\n routeKey: string\n rscPayload: React.ReactNode\n }\n\nconst resolveTitle = (title: MetaConfig['title']): string | undefined => {\n if (!title) {\n return undefined\n }\n if (typeof title === 'string') {\n return title\n }\n if ('absolute' in title) {\n return title.absolute\n }\n return title.default\n}\n\n/**\n * Flattens the framework-agnostic `MetaConfig` (Next.js `Metadata` shape) into\n * the plain, serializable `AdminPageMetadata` the route loader ships to the\n * client. The full `MetaConfig` carries a `URL` `metadataBase`, functions and\n * other non-serializable values that seroval cannot cross the wire, so only the\n * fields `getAdminMeta` renders are extracted.\n */\nconst toAdminPageMetadata = (meta: MetaConfig): AdminPageMetadata => {\n const og = meta.openGraph as\n | {\n description?: unknown\n images?: unknown\n siteName?: unknown\n title?: unknown\n }\n | undefined\n\n const rawImages = og?.images\n const imagesArray = rawImages ? (Array.isArray(rawImages) ? rawImages : [rawImages]) : []\n const images = imagesArray\n .map((image: any) =>\n typeof image === 'string'\n ? { url: image }\n : image?.url\n ? { alt: image.alt, height: image.height, url: String(image.url), width: image.width }\n : undefined,\n )\n .filter(Boolean) as NonNullable<AdminPageMetadata['openGraph']>['images']\n\n const rawIcons = meta.icons as any\n const iconList = Array.isArray(rawIcons)\n ? rawIcons\n : rawIcons && typeof rawIcons === 'object' && Array.isArray(rawIcons.icon)\n ? rawIcons.icon\n : []\n const icons = iconList\n .map((icon: any) =>\n typeof icon === 'string'\n ? { rel: 'icon', url: icon }\n : icon?.url\n ? {\n type: icon.type,\n media: icon.media,\n rel: icon.rel ?? 'icon',\n sizes: icon.sizes,\n url: String(icon.url),\n }\n : undefined,\n )\n .filter(Boolean) as AdminPageMetadata['icons']\n\n const keywords = meta.keywords\n\n return {\n description: typeof meta.description === 'string' ? meta.description : undefined,\n icons: icons?.length ? icons : undefined,\n keywords:\n typeof keywords === 'string'\n ? keywords\n : Array.isArray(keywords)\n ? keywords.join(', ')\n : undefined,\n openGraph: og\n ? {\n description: typeof og.description === 'string' ? og.description : undefined,\n images: images?.length ? images : undefined,\n siteName: typeof og.siteName === 'string' ? og.siteName : undefined,\n title: typeof og.title === 'string' ? og.title : undefined,\n }\n : undefined,\n robots: typeof meta.robots === 'string' ? meta.robots : undefined,\n title: resolveTitle(meta.title),\n }\n}\n\n/**\n * Renders an admin page for TanStack Start and returns a serializable loader\n * result. The framework adapter wraps this in a `createServerFn` that supplies\n * the app's `config` and generated `importMap`.\n *\n * 1. Initializes the Payload request via the shared `renderRoot` orchestrator\n * from `@payloadcms/ui`, passing a TanStack-bound `initReq`. The injected\n * page-render `ServerAdapter` records navigation intent and throws the\n * framework-agnostic error contract.\n * 2. Pipes the resulting React server tree through `renderServerComponent`\n * to produce a Flight payload the client consumes directly.\n * 3. Resolves page metadata via the same shared `generatePageMetadata`\n * Next.js uses, returning plain serializable strings for `head()`.\n *\n * Navigation surfaces two ways and both become a `_notFound` / `_redirect`\n * sentinel the route loader re-throws as native TanStack nav:\n * - thrown during `renderRoot` orchestration (e.g. the login redirect) → caught\n * by the try/catch below;\n * - thrown deep inside a streamed view component (e.g. `DocumentView` access\n * denied, `LoginView` already-authenticated) → swallowed into the RSC stream,\n * so it's read from the `nav` holder after `renderServerComponent` resolves.\n */\nexport async function loadAdminPage({\n config,\n importMap,\n search,\n splat,\n}: LoadAdminPageArgs): Promise<LoadAdminPageResult> {\n const { renderRoot } = await import('@payloadcms/ui/views/Root')\n const { defaultAdminViews } = await import('@payloadcms/ui/views/Root/adminViews')\n const { generatePageMetadata } = await import('@payloadcms/ui/views/Root/generatePageMetadata')\n\n const splatSegments = splat ? splat.split('/').filter(Boolean) : []\n // Match Next's optional-catch-all behavior: the admin root (`/admin`) has no\n // segments. Passing an empty array makes the shared `renderRoot` build\n // `currentRoute` as `/admin/` (trailing slash), which no longer equals\n // `adminRoute` and causes `handleAuthRedirect` to append `?redirect=/admin/`.\n // Passing `undefined` yields `currentRoute = /admin`, so the unauthenticated\n // redirect lands on a clean `/admin/login`.\n const segments = splatSegments.length > 0 ? splatSegments : undefined\n const searchParams = search ?? {}\n\n // Records navigation requested via `req.server.*` (including throws swallowed\n // by RSC streaming deep inside view components). Read after the render.\n const nav: { type?: 'notFound' | 'redirect'; url?: string } = {}\n const pageServerAdapter = createPageRenderServerAdapter(nav)\n\n // `renderRoot` calls `initReq` itself with its own overrides (query\n // re-nesting, `urlSuffix`, `fallbackLocale`). Forward them, injecting the\n // page-render `ServerAdapter` so `req.server.redirect()` / `.notFound()`\n // is recorded + thrown rather than escaping as raw TanStack nav.\n const boundInitReq: Parameters<typeof renderRoot>[0]['initReq'] = (args) =>\n initReq({\n configPromise: args.configPromise,\n importMap: args.importMap,\n overrides: args.overrides,\n serverAdapter: pageServerAdapter,\n })\n\n const notFound = (): never => {\n nav.type = 'notFound'\n throw new Error('not-found')\n }\n const redirect = (url: string): never => {\n nav.type = 'redirect'\n nav.url = url\n throw new Error(`redirect:${url}`)\n }\n\n // Build the 404 result the route loader re-throws as TanStack `notFound()`.\n //\n // Throwing `notFound()` is the only way to set the SSR document status to 404\n // (it's read from `router.stores.statusCode`, set by a not-found match — NOT\n // from `setResponseStatus`, which only affects the RSC RPC response). But the\n // matching `notFoundComponent` is a client component with no access to the\n // Payload `req`, so it can't build the admin chrome on its own. To match Next\n // (whose not-found route renders the full admin layout — nav sidebar, etc. —\n // around the NotFound body, see `renderNotFoundPage`), we render that same\n // shared `renderNotFoundPage` tree here, server-side, and ship its Flight\n // payload through the `notFound()` error so the client renders it verbatim.\n // For users without admin access `renderNotFoundPage` returns the bare\n // `NotFoundClient`, preserving the access-denied behavior.\n const renderNotFound = async (): Promise<LoadAdminPageResult> => {\n const { renderNotFoundPage } = await import('@payloadcms/ui/views/NotFound/page')\n\n const notFoundNode = await renderNotFoundPage({\n config: Promise.resolve(config),\n importMap,\n initReq: (args) =>\n initReq({\n configPromise: args.configPromise,\n importMap: args.importMap,\n overrides: args.overrides,\n }),\n params: Promise.resolve({ segments: splatSegments }),\n searchParams: Promise.resolve(searchParams),\n })\n\n const rscPayload = await renderServerComponent(notFoundNode as React.ReactElement)\n\n return { _notFound: true, routeKey: splat ?? '', rscPayload }\n }\n\n try {\n const node = await renderRoot({\n adminViews: defaultAdminViews,\n config: Promise.resolve(config),\n importMap,\n initReq: boundInitReq,\n notFound,\n // `segments` is intentionally `undefined` for the admin root (`/admin`),\n // matching Next's optional catch-all; `renderRoot` handles it at runtime.\n params: Promise.resolve({ segments }) as Parameters<typeof renderRoot>[0]['params'],\n redirect,\n searchParams: Promise.resolve(searchParams),\n })\n\n const rscPayload = await renderServerComponent(node as React.ReactElement)\n\n // The server-function (client-nav RPC) path returns the flight stream unread —\n // unlike the router/SSR path, which awaits a decode that drives the render to\n // completion. So streamed side effects (e.g. DocumentView's autosave-create\n // `server.redirect()`) haven't run yet and `nav` is empty. Buffer the stream to\n // completion to force the render (populating `nav`), then hand the client a fresh\n // replayable stream from that buffer.\n if (!nav.type) {\n const wrapper = (\n rscPayload as unknown as Record<\n symbol,\n { createReplayStream?: () => ReadableStream<Uint8Array> } | undefined\n >\n )[Symbol.for('tanstack.rsc.stream')]\n if (typeof wrapper?.createReplayStream === 'function') {\n const buffer = await new Response(wrapper.createReplayStream()).arrayBuffer()\n wrapper.createReplayStream = () => new Response(buffer).body as ReadableStream<Uint8Array>\n }\n }\n\n // Navigation thrown deep inside a streamed view component (e.g. access\n // denied → notFound, already-authenticated → redirect) is swallowed into\n // the RSC stream and never rejects the render. Honor it from the holder,\n // discarding the (broken) payload from the aborted render.\n if (nav.type === 'redirect' && nav.url) {\n return { _redirect: nav.url }\n }\n if (nav.type === 'notFound') {\n return await renderNotFound()\n }\n\n // Resolve metadata through the same shared generator Next.js uses. Only\n // plain strings cross the wire (the full `MetaConfig` carries a `URL`\n // `metadataBase` and icons that seroval cannot serialize).\n const i18n = await getRequestI18n({ config })\n const meta = await generatePageMetadata({\n adminViews: defaultAdminViews as Parameters<typeof generatePageMetadata>[0]['adminViews'],\n config,\n i18n,\n params: { segments },\n })\n\n return {\n metadata: toAdminPageMetadata(meta),\n routeKey: splat ?? '',\n rscPayload,\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n if (nav.type === 'notFound' || message === 'not-found') {\n return await renderNotFound()\n }\n if (nav.type === 'redirect' || message.startsWith('redirect:')) {\n return { _redirect: nav.url ?? message.slice('redirect:'.length) }\n }\n throw err\n }\n}\n"],"names":["renderServerComponent","getRequestI18n","initReq","createPageRenderServerAdapter","resolveTitle","title","undefined","absolute","default","toAdminPageMetadata","meta","og","openGraph","rawImages","images","imagesArray","Array","isArray","map","image","url","alt","height","String","width","filter","Boolean","rawIcons","icons","iconList","icon","rel","type","media","sizes","keywords","description","length","join","siteName","robots","loadAdminPage","config","importMap","search","splat","renderRoot","defaultAdminViews","generatePageMetadata","splatSegments","split","segments","searchParams","nav","pageServerAdapter","boundInitReq","args","configPromise","overrides","serverAdapter","notFound","Error","redirect","renderNotFound","renderNotFoundPage","notFoundNode","Promise","resolve","params","rscPayload","_notFound","routeKey","node","adminViews","wrapper","Symbol","for","createReplayStream","buffer","Response","arrayBuffer","body","_redirect","i18n","metadata","err","message","startsWith","slice"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,4BAA2B;AAIjE,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,OAAO,QAAQ,sBAAqB;AAC7C,SAASC,6BAA6B,QAAQ,4BAA2B;AA6BzE,MAAMC,eAAe,CAACC;IACpB,IAAI,CAACA,OAAO;QACV,OAAOC;IACT;IACA,IAAI,OAAOD,UAAU,UAAU;QAC7B,OAAOA;IACT;IACA,IAAI,cAAcA,OAAO;QACvB,OAAOA,MAAME,QAAQ;IACvB;IACA,OAAOF,MAAMG,OAAO;AACtB;AAEA;;;;;;CAMC,GACD,MAAMC,sBAAsB,CAACC;IAC3B,MAAMC,KAAKD,KAAKE,SAAS;IASzB,MAAMC,YAAYF,IAAIG;IACtB,MAAMC,cAAcF,YAAaG,MAAMC,OAAO,CAACJ,aAAaA,YAAY;QAACA;KAAU,GAAI,EAAE;IACzF,MAAMC,SAASC,YACZG,GAAG,CAAC,CAACC,QACJ,OAAOA,UAAU,WACb;YAAEC,KAAKD;QAAM,IACbA,OAAOC,MACL;YAAEC,KAAKF,MA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AAQG,IAAI;YAC9D;QACF;QAEA,uEAAuE;QACvE,yEAAyE;QACzE,yEAAyE;QACzE,2DAA2D;QAC3D,IAAI5B,IAAIrB,IAAI,KAAK,cAAcqB,IAAIjC,GAAG,EAAE;YACtC,OAAO;gBAAE8D,WAAW7B,IAAIjC,GAAG;YAAC;QAC9B;QACA,IAAIiC,IAAIrB,IAAI,KAAK,YAAY;YAC3B,OAAO,MAAM+B;QACf;QAEA,wEAAwE;QACxE,sEAAsE;QACtE,2DAA2D;QAC3D,MAAMoB,OAAO,MAAMlF,eAAe;YAAEyC;QAAO;QAC3C,MAAMhC,OAAO,MAAMsC,qBAAqB;YACtCyB,YAAY1B;YACZL;YACAyC;YACAf,QAAQ;gBAAEjB;YAAS;QACrB;QAEA,OAAO;YACLiC,UAAU3E,oBAAoBC;YAC9B6D,UAAU1B,SAAS;YACnBwB;QACF;IACF,EAAE,OAAOgB,KAAK;QACZ,MAAMC,UAAUD,eAAexB,QAAQwB,IAAIC,OAAO,GAAG/D,OAAO8D;QAC5D,IAAIhC,IAAIrB,IAAI,KAAK,cAAcsD,YAAY,aAAa;YACtD,OAAO,MAAMvB;QACf;QACA,IAAIV,IAAIrB,IAAI,KAAK,cAAcsD,QAAQC,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAEL,WAAW7B,IAAIjC,GAAG,IAAIkE,QAAQE,KAAK,CAAC,YAAYnD,MAAM;YAAE;QACnE;QACA,MAAMgD;IACR;AACF"}
@@ -0,0 +1,15 @@
1
+ import type { ImportMap, SanitizedConfig } from 'payload';
2
+ /**
3
+ * Resolves the admin layout data for TanStack Start and returns a serializable
4
+ * payload for the `/_payload` route loader. The framework adapter wraps this in
5
+ * a `createServerFn` that supplies the app's `config` and generated `importMap`.
6
+ *
7
+ * `toSerializable` strips React elements, so the custom-providers element tree
8
+ * (`config.admin.components.providers`) is rendered to an RSC payload separately
9
+ * and re-attached.
10
+ */
11
+ export declare function loadLayoutData({ config, importMap, }: {
12
+ config: SanitizedConfig;
13
+ importMap: ImportMap;
14
+ }): Promise<Record<string, unknown>>;
15
+ //# sourceMappingURL=loadLayoutData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadLayoutData.d.ts","sourceRoot":"","sources":["../../src/utilities/loadLayoutData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,EACnC,MAAM,EACN,SAAS,GACV,EAAE;IACD,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,SAAS,CAAA;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAOnC"}
@@ -0,0 +1,23 @@
1
+ import { renderServerComponent } from '@tanstack/react-start/rsc';
2
+ import { getLayoutData } from '../layouts/Root/getLayoutData.js';
3
+ import { toSerializable } from './toSerializable.js';
4
+ /**
5
+ * Resolves the admin layout data for TanStack Start and returns a serializable
6
+ * payload for the `/_payload` route loader. The framework adapter wraps this in
7
+ * a `createServerFn` that supplies the app's `config` and generated `importMap`.
8
+ *
9
+ * `toSerializable` strips React elements, so the custom-providers element tree
10
+ * (`config.admin.components.providers`) is rendered to an RSC payload separately
11
+ * and re-attached.
12
+ */ export async function loadLayoutData({ config, importMap }) {
13
+ const { providers, ...data } = await getLayoutData({
14
+ configPromise: config,
15
+ importMap
16
+ });
17
+ return {
18
+ ...toSerializable(data),
19
+ providers: providers ? await renderServerComponent(providers) : undefined
20
+ };
21
+ }
22
+
23
+ //# sourceMappingURL=loadLayoutData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/loadLayoutData.ts"],"sourcesContent":["import type { ImportMap, SanitizedConfig } from 'payload'\n\nimport { renderServerComponent } from '@tanstack/react-start/rsc'\n\nimport { getLayoutData } from '../layouts/Root/getLayoutData.js'\nimport { toSerializable } from './toSerializable.js'\n\n/**\n * Resolves the admin layout data for TanStack Start and returns a serializable\n * payload for the `/_payload` route loader. The framework adapter wraps this in\n * a `createServerFn` that supplies the app's `config` and generated `importMap`.\n *\n * `toSerializable` strips React elements, so the custom-providers element tree\n * (`config.admin.components.providers`) is rendered to an RSC payload separately\n * and re-attached.\n */\nexport async function loadLayoutData({\n config,\n importMap,\n}: {\n config: SanitizedConfig\n importMap: ImportMap\n}): Promise<Record<string, unknown>> {\n const { providers, ...data } = await getLayoutData({ configPromise: config, importMap })\n\n return {\n ...(toSerializable(data) as Record<string, unknown>),\n providers: providers ? await renderServerComponent(providers as any) : undefined,\n }\n}\n"],"names":["renderServerComponent","getLayoutData","toSerializable","loadLayoutData","config","importMap","providers","data","configPromise","undefined"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,4BAA2B;AAEjE,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD;;;;;;;;CAQC,GACD,OAAO,eAAeC,eAAe,EACnCC,MAAM,EACNC,SAAS,EAIV;IACC,MAAM,EAAEC,SAAS,EAAE,GAAGC,MAAM,GAAG,MAAMN,cAAc;QAAEO,eAAeJ;QAAQC;IAAU;IAEtF,OAAO;QACL,GAAIH,eAAeK,KAAK;QACxBD,WAAWA,YAAY,MAAMN,sBAAsBM,aAAoBG;IACzE;AACF"}
@@ -0,0 +1,29 @@
1
+ import type { ServerFunctionClient, ServerFunctionClientArgs } from 'payload';
2
+ /**
3
+ * Builds the client-side `ServerFunctionClient` wired into
4
+ * `RootProvider.serverFunction`, given the app's `createServerFn`-based
5
+ * dispatcher (`runServerFn`).
6
+ *
7
+ * Strips functions / symbols / RegExps / React elements from the args before
8
+ * dispatching: the previous `fetch + JSON.stringify` pipeline silently dropped
9
+ * those, but TanStack Start's seroval-based wire format errors instead. We
10
+ * mirror the relaxed behaviour so existing callers (e.g. `getFormState` in
11
+ * `ServerFunctionsProvider`) that may pass the live form state — which can
12
+ * carry stray functions — keep working without each call site sanitising.
13
+ *
14
+ * Delegates to `runServerFn`, so the response (including any RSC handles for
15
+ * server-rendered custom components) is decoded by TanStack Start back into
16
+ * renderable React nodes on the client.
17
+ */
18
+ export declare function createServerFunctionClient({ runServerFn, }: {
19
+ runServerFn: (input: {
20
+ data: ServerFunctionClientArgs;
21
+ }) => Promise<unknown>;
22
+ }): ServerFunctionClient;
23
+ /**
24
+ * Recursively removes values TanStack Start's seroval wire format cannot
25
+ * serialize (functions, symbols, RegExps, React elements, cyclic refs) and
26
+ * normalizes `Date` subclasses to plain `Date`.
27
+ */
28
+ export declare function stripUnserializable(value: unknown, cache?: WeakMap<object, unknown>, ancestors?: WeakSet<object>): unknown;
29
+ //# sourceMappingURL=serverFunctionClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverFunctionClient.d.ts","sourceRoot":"","sources":["../../src/utilities/serverFunctionClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAE7E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,wBAAwB,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC7E,GAAG,oBAAoB,CAKvB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAiB,EAC/C,SAAS,GAAE,OAAO,CAAC,MAAM,CAAiB,GACzC,OAAO,CA4FT"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Builds the client-side `ServerFunctionClient` wired into
3
+ * `RootProvider.serverFunction`, given the app's `createServerFn`-based
4
+ * dispatcher (`runServerFn`).
5
+ *
6
+ * Strips functions / symbols / RegExps / React elements from the args before
7
+ * dispatching: the previous `fetch + JSON.stringify` pipeline silently dropped
8
+ * those, but TanStack Start's seroval-based wire format errors instead. We
9
+ * mirror the relaxed behaviour so existing callers (e.g. `getFormState` in
10
+ * `ServerFunctionsProvider`) that may pass the live form state — which can
11
+ * carry stray functions — keep working without each call site sanitising.
12
+ *
13
+ * Delegates to `runServerFn`, so the response (including any RSC handles for
14
+ * server-rendered custom components) is decoded by TanStack Start back into
15
+ * renderable React nodes on the client.
16
+ */ export function createServerFunctionClient({ runServerFn }) {
17
+ return async (args)=>{
18
+ const safeArgs = stripUnserializable(args);
19
+ return await runServerFn({
20
+ data: safeArgs
21
+ });
22
+ };
23
+ }
24
+ /**
25
+ * Recursively removes values TanStack Start's seroval wire format cannot
26
+ * serialize (functions, symbols, RegExps, React elements, cyclic refs) and
27
+ * normalizes `Date` subclasses to plain `Date`.
28
+ */ export function stripUnserializable(value, cache = new WeakMap(), ancestors = new WeakSet()) {
29
+ if (value === null || value === undefined) {
30
+ return value;
31
+ }
32
+ const t = typeof value;
33
+ if (t === 'function' || t === 'symbol') {
34
+ return undefined;
35
+ }
36
+ if (t !== 'object') {
37
+ return value;
38
+ }
39
+ const obj = value;
40
+ if (typeof obj.$$typeof === 'symbol') {
41
+ return undefined;
42
+ }
43
+ if (ancestors.has(obj)) {
44
+ return undefined;
45
+ }
46
+ if (cache.has(obj)) {
47
+ return cache.get(obj);
48
+ }
49
+ if (obj instanceof Date) {
50
+ // Normalize to a plain `Date`. Subclasses (e.g. `@date-fns/tz`'s `TZDate`,
51
+ // used by the schedule-publish drawer) are `instanceof Date` but have a
52
+ // different `constructor`, which TanStack Start's seroval serializer
53
+ // rejects with "The value [object Date] ... cannot be parsed/serialized".
54
+ return new Date(obj.getTime());
55
+ }
56
+ if (obj instanceof RegExp) {
57
+ return undefined;
58
+ }
59
+ ancestors.add(obj);
60
+ if (obj instanceof Map) {
61
+ const cleaned = new Map();
62
+ cache.set(obj, cleaned);
63
+ for (const [k, v] of obj){
64
+ const cv = stripUnserializable(v, cache, ancestors);
65
+ if (cv !== undefined) {
66
+ cleaned.set(k, cv);
67
+ }
68
+ }
69
+ ancestors.delete(obj);
70
+ return cleaned;
71
+ }
72
+ if (obj instanceof Set) {
73
+ const cleaned = new Set();
74
+ cache.set(obj, cleaned);
75
+ for (const v of obj){
76
+ const cv = stripUnserializable(v, cache, ancestors);
77
+ if (cv !== undefined) {
78
+ cleaned.add(cv);
79
+ }
80
+ }
81
+ ancestors.delete(obj);
82
+ return cleaned;
83
+ }
84
+ if (Array.isArray(obj)) {
85
+ const arr = [];
86
+ cache.set(obj, arr);
87
+ for (const item of obj){
88
+ arr.push(stripUnserializable(item, cache, ancestors));
89
+ }
90
+ ancestors.delete(obj);
91
+ return arr;
92
+ }
93
+ if (ArrayBuffer.isView(obj)) {
94
+ ancestors.delete(obj);
95
+ return obj;
96
+ }
97
+ const result = {};
98
+ cache.set(obj, result);
99
+ for (const key of Object.keys(obj)){
100
+ const v = stripUnserializable(obj[key], cache, ancestors);
101
+ if (v !== undefined) {
102
+ result[key] = v;
103
+ }
104
+ }
105
+ ancestors.delete(obj);
106
+ return result;
107
+ }
108
+
109
+ //# sourceMappingURL=serverFunctionClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/serverFunctionClient.ts"],"sourcesContent":["import type { ServerFunctionClient, ServerFunctionClientArgs } from 'payload'\n\n/**\n * Builds the client-side `ServerFunctionClient` wired into\n * `RootProvider.serverFunction`, given the app's `createServerFn`-based\n * dispatcher (`runServerFn`).\n *\n * Strips functions / symbols / RegExps / React elements from the args before\n * dispatching: the previous `fetch + JSON.stringify` pipeline silently dropped\n * those, but TanStack Start's seroval-based wire format errors instead. We\n * mirror the relaxed behaviour so existing callers (e.g. `getFormState` in\n * `ServerFunctionsProvider`) that may pass the live form state — which can\n * carry stray functions — keep working without each call site sanitising.\n *\n * Delegates to `runServerFn`, so the response (including any RSC handles for\n * server-rendered custom components) is decoded by TanStack Start back into\n * renderable React nodes on the client.\n */\nexport function createServerFunctionClient({\n runServerFn,\n}: {\n runServerFn: (input: { data: ServerFunctionClientArgs }) => Promise<unknown>\n}): ServerFunctionClient {\n return (async (args: ServerFunctionClientArgs) => {\n const safeArgs = stripUnserializable(args) as ServerFunctionClientArgs\n return await runServerFn({ data: safeArgs })\n }) as ServerFunctionClient\n}\n\n/**\n * Recursively removes values TanStack Start's seroval wire format cannot\n * serialize (functions, symbols, RegExps, React elements, cyclic refs) and\n * normalizes `Date` subclasses to plain `Date`.\n */\nexport function stripUnserializable(\n value: unknown,\n cache: WeakMap<object, unknown> = new WeakMap(),\n ancestors: WeakSet<object> = new WeakSet(),\n): unknown {\n if (value === null || value === undefined) {\n return value\n }\n\n const t = typeof value\n if (t === 'function' || t === 'symbol') {\n return undefined\n }\n if (t !== 'object') {\n return value\n }\n\n const obj = value as Record<string, unknown>\n\n if (typeof obj.$$typeof === 'symbol') {\n return undefined\n }\n\n if (ancestors.has(obj)) {\n return undefined\n }\n\n if (cache.has(obj)) {\n return cache.get(obj)\n }\n\n if (obj instanceof Date) {\n // Normalize to a plain `Date`. Subclasses (e.g. `@date-fns/tz`'s `TZDate`,\n // used by the schedule-publish drawer) are `instanceof Date` but have a\n // different `constructor`, which TanStack Start's seroval serializer\n // rejects with \"The value [object Date] ... cannot be parsed/serialized\".\n return new Date(obj.getTime())\n }\n\n if (obj instanceof RegExp) {\n return undefined\n }\n\n ancestors.add(obj)\n\n if (obj instanceof Map) {\n const cleaned = new Map()\n cache.set(obj, cleaned)\n for (const [k, v] of obj) {\n const cv = stripUnserializable(v, cache, ancestors)\n if (cv !== undefined) {\n cleaned.set(k, cv)\n }\n }\n ancestors.delete(obj)\n return cleaned\n }\n\n if (obj instanceof Set) {\n const cleaned = new Set()\n cache.set(obj, cleaned)\n for (const v of obj) {\n const cv = stripUnserializable(v, cache, ancestors)\n if (cv !== undefined) {\n cleaned.add(cv)\n }\n }\n ancestors.delete(obj)\n return cleaned\n }\n\n if (Array.isArray(obj)) {\n const arr: unknown[] = []\n cache.set(obj, arr)\n for (const item of obj) {\n arr.push(stripUnserializable(item, cache, ancestors))\n }\n ancestors.delete(obj)\n return arr\n }\n\n if (ArrayBuffer.isView(obj)) {\n ancestors.delete(obj)\n return obj\n }\n\n const result: Record<string, unknown> = {}\n cache.set(obj, result)\n for (const key of Object.keys(obj)) {\n const v = stripUnserializable(obj[key], cache, ancestors)\n if (v !== undefined) {\n result[key] = v\n }\n }\n ancestors.delete(obj)\n return result\n}\n"],"names":["createServerFunctionClient","runServerFn","args","safeArgs","stripUnserializable","data","value","cache","WeakMap","ancestors","WeakSet","undefined","t","obj","$$typeof","has","get","Date","getTime","RegExp","add","Map","cleaned","set","k","v","cv","delete","Set","Array","isArray","arr","item","push","ArrayBuffer","isView","result","key","Object","keys"],"mappings":"AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASA,2BAA2B,EACzCC,WAAW,EAGZ;IACC,OAAQ,OAAOC;QACb,MAAMC,WAAWC,oBAAoBF;QACrC,OAAO,MAAMD,YAAY;YAAEI,MAAMF;QAAS;IAC5C;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASC,oBACdE,KAAc,EACdC,QAAkC,IAAIC,SAAS,EAC/CC,YAA6B,IAAIC,SAAS;IAE1C,IAAIJ,UAAU,QAAQA,UAAUK,WAAW;QACzC,OAAOL;IACT;IAEA,MAAMM,IAAI,OAAON;IACjB,IAAIM,MAAM,cAAcA,MAAM,UAAU;QACtC,OAAOD;IACT;IACA,IAAIC,MAAM,UAAU;QAClB,OAAON;IACT;IAEA,MAAMO,MAAMP;IAEZ,IAAI,OAAOO,IAAIC,QAAQ,KAAK,UAAU;QACpC,OAAOH;IACT;IAEA,IAAIF,UAAUM,GAAG,CAACF,MAAM;QACtB,OAAOF;IACT;IAEA,IAAIJ,MAAMQ,GAAG,CAACF,MAAM;QAClB,OAAON,MAAMS,GAAG,CAACH;IACnB;IAEA,IAAIA,eAAeI,MAAM;QACvB,2EAA2E;QAC3E,wEAAwE;QACxE,qEAAqE;QACrE,0EAA0E;QAC1E,OAA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AMd,WAAW;YACnByB,MAAM,CAACC,IAAI,GAAGZ;QAChB;IACF;IACAhB,UAAUkB,MAAM,CAACd;IACjB,OAAOuB;AACT"}
@@ -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"}