@payloadcms/tanstack-start 4.0.0-internal.293e026 → 4.0.0-internal.4804abd

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 (75) hide show
  1. package/dist/elements/RouterAdapter/index.d.ts.map +1 -1
  2. package/dist/elements/RouterAdapter/index.js +38 -15
  3. package/dist/elements/RouterAdapter/index.js.map +1 -1
  4. package/dist/exports/client.d.ts +4 -0
  5. package/dist/exports/client.d.ts.map +1 -1
  6. package/dist/exports/client.js +4 -0
  7. package/dist/exports/client.js.map +1 -1
  8. package/dist/exports/layouts.d.ts +1 -0
  9. package/dist/exports/layouts.d.ts.map +1 -1
  10. package/dist/exports/layouts.js +1 -0
  11. package/dist/exports/layouts.js.map +1 -1
  12. package/dist/exports/server.d.ts +2 -1
  13. package/dist/exports/server.d.ts.map +1 -1
  14. package/dist/exports/server.js +2 -1
  15. package/dist/exports/server.js.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
  21. package/dist/layouts/Root/getLayoutData.js +36 -0
  22. package/dist/layouts/Root/getLayoutData.js.map +1 -1
  23. package/dist/layouts/Root/index.d.ts +7 -0
  24. package/dist/layouts/Root/index.d.ts.map +1 -1
  25. package/dist/layouts/Root/index.js.map +1 -1
  26. package/dist/layouts/Root/withPayloadRoot.d.ts +65 -0
  27. package/dist/layouts/Root/withPayloadRoot.d.ts.map +1 -0
  28. package/dist/layouts/Root/withPayloadRoot.js +92 -0
  29. package/dist/layouts/Root/withPayloadRoot.js.map +1 -0
  30. package/dist/routes/adminRoutes.d.ts +105 -0
  31. package/dist/routes/adminRoutes.d.ts.map +1 -0
  32. package/dist/routes/adminRoutes.js +97 -0
  33. package/dist/routes/adminRoutes.js.map +1 -0
  34. package/dist/routes/apiRoute.d.ts +29 -0
  35. package/dist/routes/apiRoute.d.ts.map +1 -0
  36. package/dist/routes/apiRoute.js +38 -0
  37. package/dist/routes/apiRoute.js.map +1 -0
  38. package/dist/routes/layoutRoute.d.ts +23 -0
  39. package/dist/routes/layoutRoute.d.ts.map +1 -0
  40. package/dist/routes/layoutRoute.js +51 -0
  41. package/dist/routes/layoutRoute.js.map +1 -0
  42. package/dist/utilities/handleAPIRoute.d.ts +11 -0
  43. package/dist/utilities/handleAPIRoute.d.ts.map +1 -0
  44. package/dist/utilities/handleAPIRoute.js +17 -0
  45. package/dist/utilities/handleAPIRoute.js.map +1 -0
  46. package/dist/utilities/importMap.server.d.ts +4 -5
  47. package/dist/utilities/importMap.server.d.ts.map +1 -1
  48. package/dist/utilities/importMap.server.js +5 -6
  49. package/dist/utilities/importMap.server.js.map +1 -1
  50. package/dist/utilities/loadAdminPage.d.ts +54 -0
  51. package/dist/utilities/loadAdminPage.d.ts.map +1 -0
  52. package/dist/utilities/loadAdminPage.js +230 -0
  53. package/dist/utilities/loadAdminPage.js.map +1 -0
  54. package/dist/utilities/loadLayoutData.d.ts +15 -0
  55. package/dist/utilities/loadLayoutData.d.ts.map +1 -0
  56. package/dist/utilities/loadLayoutData.js +23 -0
  57. package/dist/utilities/loadLayoutData.js.map +1 -0
  58. package/dist/utilities/serverFunctionClient.d.ts +29 -0
  59. package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
  60. package/dist/utilities/serverFunctionClient.js +109 -0
  61. package/dist/utilities/serverFunctionClient.js.map +1 -0
  62. package/dist/vite/constants.d.ts +7 -2
  63. package/dist/vite/constants.d.ts.map +1 -1
  64. package/dist/vite/constants.js +53 -5
  65. package/dist/vite/constants.js.map +1 -1
  66. package/dist/vite/plugin.js +8 -12
  67. package/dist/vite/plugin.js.map +1 -1
  68. package/dist/vite/plugins/stripDistStyleImports.d.ts.map +1 -1
  69. package/dist/vite/plugins/stripDistStyleImports.js +37 -4
  70. package/dist/vite/plugins/stripDistStyleImports.js.map +1 -1
  71. package/package.json +7 -7
  72. package/dist/auth/switchLanguage.d.ts +0 -6
  73. package/dist/auth/switchLanguage.d.ts.map +0 -1
  74. package/dist/auth/switchLanguage.js +0 -11
  75. package/dist/auth/switchLanguage.js.map +0 -1
@@ -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,c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,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,cAA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IAAIE,IAAI,CAAC7B,oBAAoB4B,MAAMzB,OAAOE;QAC5C;QACAA,UAAUkB,MAAM,CAACd;QACjB,OAAOkB;IACT;IAEA,IAAIG,YAAYC,MAAM,CAACtB,MAAM;QAC3BJ,UAAUkB,MAAM,CAACd;QACjB,OAAOA;IACT;IAEA,MAAMuB,SAAkC,CAAC;IACzC7B,MAAMgB,GAAG,CAACV,KAAKuB;IACf,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAAC1B,KAAM;QAClC,MAAMY,IAAIrB,oBAAoBS,GAAG,CAACwB,IAAI,EAAE9B,OAAOE;QAC/C,IAAIgB,MAAMd,WAAW;YACnByB,MAAM,CAACC,IAAI,GAAGZ;QAChB;IACF;IACAhB,UAAUkB,MAAM,CAACd;IACjB,OAAOuB;AACT"}
@@ -16,8 +16,13 @@ export declare const ssrExternalPackages: string[];
16
16
  export declare const payloadNoExternalPatterns: Array<RegExp | string>;
17
17
  /**
18
18
  * The subset of `payloadNoExternalPatterns` that needs to participate in the
19
- * RSC environment. The RSC graph is narrower plugins and storage adapters
20
- * don't run in RSC, only the admin UI surface does.
19
+ * RSC environment. Plugins and storage adapters must be included: they register
20
+ * custom providers/components (e.g. `plugin-multi-tenant`'s `'use client'`
21
+ * `TenantSelectionProvider`) that render in the RSC graph via
22
+ * `RenderServerComponent`. If the package stays external to RSC, `plugin-rsc`
23
+ * never transforms its `'use client'` modules into client references, so the
24
+ * component executes server-side and crashes on the first hook
25
+ * (`Cannot read properties of null (reading 'useState')`).
21
26
  */
22
27
  export declare const payloadRscNoExternalPatterns: Array<RegExp | string>;
23
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/vite/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,EA0BvC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO5D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAK/D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAsB/C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAqC/C,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/vite/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,EA0BvC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO5D,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO/D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAsB/C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EA8E/C,CAAA"}
@@ -46,13 +46,20 @@
46
46
  ];
47
47
  /**
48
48
  * The subset of `payloadNoExternalPatterns` that needs to participate in the
49
- * RSC environment. The RSC graph is narrower plugins and storage adapters
50
- * don't run in RSC, only the admin UI surface does.
49
+ * RSC environment. Plugins and storage adapters must be included: they register
50
+ * custom providers/components (e.g. `plugin-multi-tenant`'s `'use client'`
51
+ * `TenantSelectionProvider`) that render in the RSC graph via
52
+ * `RenderServerComponent`. If the package stays external to RSC, `plugin-rsc`
53
+ * never transforms its `'use client'` modules into client references, so the
54
+ * component executes server-side and crashes on the first hook
55
+ * (`Cannot read properties of null (reading 'useState')`).
51
56
  */ export const payloadRscNoExternalPatterns = [
52
57
  '@payloadcms/ui',
53
58
  '@payloadcms/translations',
54
59
  '@payloadcms/tanstack-start',
55
- /^@payloadcms\/richtext-lexical/
60
+ /^@payloadcms\/richtext-lexical/,
61
+ /^@payloadcms\/plugin-/,
62
+ /^@payloadcms\/storage-/
56
63
  ];
57
64
  /**
58
65
  * Packages we know contain Node-only code or top-level side effects requiring
@@ -111,7 +118,20 @@
111
118
  '@payloadcms/ui > md5',
112
119
  'payload > deepmerge',
113
120
  'payload > pluralize',
114
- 'scheduler',
121
+ // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of
122
+ // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated
123
+ // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where
124
+ // it isn't hoisted to the top level. Path it through `react-dom` so the
125
+ // optimizer resolves the exact copy the runtime loads.
126
+ 'react-dom > scheduler',
127
+ // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the
128
+ // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.
129
+ // Because its parent is excluded, the optimizer never crawls in to discover
130
+ // this entry, so Vite serves `react/compiler-runtime` raw. That file is
131
+ // CommonJS (`module.exports = require(...)`), so the named `c` export can't be
132
+ // statically extracted and every client component throws "does not provide an
133
+ // export named 'c'". Pre-bundling it lets esbuild synthesize the named export.
134
+ 'react/compiler-runtime',
115
135
  // Transitive deps that Vite otherwise discovers *after* the initial crawl
116
136
  // (react-select pulls in @floating-ui at runtime; react-is is reached via
117
137
  // react-transition-group/prop-types; the default date-fns locale is loaded
@@ -123,7 +143,35 @@
123
143
  '@payloadcms/ui > react-select > @floating-ui/dom',
124
144
  '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',
125
145
  '@payloadcms/ui > react-select > prop-types > react-is',
126
- '@payloadcms/ui > date-fns/locale/en-US'
146
+ '@payloadcms/ui > date-fns/locale/en-US',
147
+ // Further late discoveries observed re-optimizing mid-run in CI cold starts
148
+ // (see CI logs: "✨ new dependencies optimized: @dnd-kit/modifiers / ajv /
149
+ // dequal/lite"). The modular dashboard pulls in `@dnd-kit/modifiers` on first
150
+ // render; form-state diffing reaches `dequal/lite` (a distinct entry point
151
+ // from the already-listed `dequal`); client-side field validation reaches
152
+ // `ajv` *through `payload`* — it is `ssrExternal` server-side but still
153
+ // bundled into the client, and must be pathed via `payload` so the optimizer
154
+ // pre-bundles the exact copy the runtime loads.
155
+ '@payloadcms/ui > @dnd-kit/modifiers',
156
+ '@payloadcms/ui > dequal/lite',
157
+ 'payload > ajv',
158
+ // The storage client-upload suites (esp. vercel-blob) crawl part of the
159
+ // `payload` server runtime into the client bundle and discover these late,
160
+ // triggering several "optimized dependencies changed. reloading" waves that
161
+ // reload the page mid-test (the bulk-upload drawer's Create New button /
162
+ // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the
163
+ // whole observed set so the first pass is complete.
164
+ 'payload > undici',
165
+ 'payload > jose',
166
+ 'payload > dataloader',
167
+ 'payload > path-to-regexp',
168
+ 'payload > console-table-printer',
169
+ 'payload > ci-info',
170
+ 'payload > image-size',
171
+ 'payload > image-size/fromFile',
172
+ 'payload > ipaddr.js',
173
+ 'payload > range-parser',
174
+ 'payload > sanitize-filename'
127
175
  ];
128
176
 
129
177
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/vite/constants.ts"],"sourcesContent":["/**\n * Vite-level configuration constants used by `payloadPlugin`. Kept separate so\n * `plugin.ts` stays focused on wiring.\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 */\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\n/**\n * The subset of `payloadNoExternalPatterns` that needs to participate in the\n * RSC environment. The RSC graph is narrower plugins and storage adapters\n * don't run in RSC, only the admin UI surface does.\n */\nexport const payloadRscNoExternalPatterns: Array<RegExp | string> = [\n '@payloadcms/ui',\n '@payloadcms/translations',\n '@payloadcms/tanstack-start',\n /^@payloadcms\\/richtext-lexical/,\n]\n\n/**\n * Packages we know contain Node-only code or top-level side effects requiring\n * Node APIs. Excluding them from the client optimizer prevents Vite from\n * walking into their main entries and trying to bundle server-only imports\n * for the browser.\n */\nexport const optimizeDepsExcludeDefaults: string[] = [\n 'sharp',\n '@payloadcms/ui',\n '@payloadcms/tanstack-start',\n 'payload',\n 'pino',\n 'pino-pretty',\n 'busboy',\n 'get-tsconfig',\n 'ws',\n 'croner',\n 'prompts',\n 'file-type',\n // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite\n // sometimes walks these from the main package entry while scanning\n // workspace deps, and the browser sub-bundles do not expose the\n // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev\n // server with a `MISSING_EXPORT` error before any test runs.\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be\n * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick\n * these up because their parent packages are in `optimizeDeps.exclude`, so we\n * list them explicitly using the `parent > child` syntax.\n */\nexport const optimizeDepsIncludeDefaults: string[] = [\n '@payloadcms/ui > sonner',\n '@payloadcms/ui > @faceless-ui/modal',\n '@payloadcms/ui > @faceless-ui/window-info',\n '@payloadcms/ui > @faceless-ui/scroll-info',\n '@payloadcms/ui > @dnd-kit/core',\n '@payloadcms/ui > @dnd-kit/sortable',\n '@payloadcms/ui > @dnd-kit/utilities',\n '@payloadcms/ui > react-datepicker',\n '@payloadcms/ui > react-select',\n '@payloadcms/ui > react-select/creatable',\n '@payloadcms/ui > react-image-crop',\n '@payloadcms/ui > @monaco-editor/react',\n '@payloadcms/ui > date-fns',\n '@payloadcms/ui > date-fns/transpose',\n '@payloadcms/ui > @date-fns/tz/date/mini',\n '@payloadcms/ui > uuid',\n '@payloadcms/ui > use-context-selector',\n '@payloadcms/ui > bson-objectid',\n '@payloadcms/ui > dequal',\n '@payloadcms/ui > object-to-formdata',\n '@payloadcms/ui > md5',\n 'payload > deepmerge',\n 'payload > pluralize',\n 'scheduler',\n // Transitive deps that Vite otherwise discovers *after* the initial crawl\n // (react-select pulls in @floating-ui at runtime; react-is is reached via\n // react-transition-group/prop-types; the default date-fns locale is loaded\n // through a dynamic `date-fns/locale/${key}` import). A late discovery forces\n // a full dep re-optimization mid-session, which 404s every in-flight\n // `.vite/deps/*` chunk (\"Pre-transform error: file does not exist in the\n // optimize deps directory\") and breaks the admin UI in CI cold starts.\n // Pre-bundling them keeps the first optimization pass complete.\n '@payloadcms/ui > react-select > @floating-ui/dom',\n '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',\n '@payloadcms/ui > react-select > prop-types > react-is',\n '@payloadcms/ui > date-fns/locale/en-US',\n]\n"],"names":["ssrExternalPackages","payloadNoExternalPatterns","payloadRscNoExternalPatterns","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults"],"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;;;;;CAKC,GACD,OAAO,MAAMC,4BAAoD;IAC/D;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;CAIC,GACD,OAAO,MAAMC,+BAAuD;IAClE;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kEAAkE;IAClE,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,6DAA6D;IAC7D;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,qEAAqE;IACrE,yEAAyE;IACzE,uEAAuE;IACvE,gEAAgE;IAChE;IACA;IACA;IACA;CACD,CAAA"}
1
+ {"version":3,"sources":["../../src/vite/constants.ts"],"sourcesContent":["/**\n * Vite-level configuration constants used by `payloadPlugin`. Kept separate so\n * `plugin.ts` stays focused on wiring.\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 */\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\n/**\n * The subset of `payloadNoExternalPatterns` that needs to participate in the\n * RSC environment. Plugins and storage adapters must be included: they register\n * custom providers/components (e.g. `plugin-multi-tenant`'s `'use client'`\n * `TenantSelectionProvider`) that render in the RSC graph via\n * `RenderServerComponent`. If the package stays external to RSC, `plugin-rsc`\n * never transforms its `'use client'` modules into client references, so the\n * component executes server-side and crashes on the first hook\n * (`Cannot read properties of null (reading 'useState')`).\n */\nexport const payloadRscNoExternalPatterns: 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\n/**\n * Packages we know contain Node-only code or top-level side effects requiring\n * Node APIs. Excluding them from the client optimizer prevents Vite from\n * walking into their main entries and trying to bundle server-only imports\n * for the browser.\n */\nexport const optimizeDepsExcludeDefaults: string[] = [\n 'sharp',\n '@payloadcms/ui',\n '@payloadcms/tanstack-start',\n 'payload',\n 'pino',\n 'pino-pretty',\n 'busboy',\n 'get-tsconfig',\n 'ws',\n 'croner',\n 'prompts',\n 'file-type',\n // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite\n // sometimes walks these from the main package entry while scanning\n // workspace deps, and the browser sub-bundles do not expose the\n // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev\n // server with a `MISSING_EXPORT` error before any test runs.\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be\n * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick\n * these up because their parent packages are in `optimizeDeps.exclude`, so we\n * list them explicitly using the `parent > child` syntax.\n */\nexport const optimizeDepsIncludeDefaults: string[] = [\n '@payloadcms/ui > sonner',\n '@payloadcms/ui > @faceless-ui/modal',\n '@payloadcms/ui > @faceless-ui/window-info',\n '@payloadcms/ui > @faceless-ui/scroll-info',\n '@payloadcms/ui > @dnd-kit/core',\n '@payloadcms/ui > @dnd-kit/sortable',\n '@payloadcms/ui > @dnd-kit/utilities',\n '@payloadcms/ui > react-datepicker',\n '@payloadcms/ui > react-select',\n '@payloadcms/ui > react-select/creatable',\n '@payloadcms/ui > react-image-crop',\n '@payloadcms/ui > @monaco-editor/react',\n '@payloadcms/ui > date-fns',\n '@payloadcms/ui > date-fns/transpose',\n '@payloadcms/ui > @date-fns/tz/date/mini',\n '@payloadcms/ui > uuid',\n '@payloadcms/ui > use-context-selector',\n '@payloadcms/ui > bson-objectid',\n '@payloadcms/ui > dequal',\n '@payloadcms/ui > object-to-formdata',\n '@payloadcms/ui > md5',\n 'payload > deepmerge',\n 'payload > pluralize',\n // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of\n // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated\n // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where\n // it isn't hoisted to the top level. Path it through `react-dom` so the\n // optimizer resolves the exact copy the runtime loads.\n 'react-dom > scheduler',\n // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the\n // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.\n // Because its parent is excluded, the optimizer never crawls in to discover\n // this entry, so Vite serves `react/compiler-runtime` raw. That file is\n // CommonJS (`module.exports = require(...)`), so the named `c` export can't be\n // statically extracted and every client component throws \"does not provide an\n // export named 'c'\". Pre-bundling it lets esbuild synthesize the named export.\n 'react/compiler-runtime',\n // Transitive deps that Vite otherwise discovers *after* the initial crawl\n // (react-select pulls in @floating-ui at runtime; react-is is reached via\n // react-transition-group/prop-types; the default date-fns locale is loaded\n // through a dynamic `date-fns/locale/${key}` import). A late discovery forces\n // a full dep re-optimization mid-session, which 404s every in-flight\n // `.vite/deps/*` chunk (\"Pre-transform error: file does not exist in the\n // optimize deps directory\") and breaks the admin UI in CI cold starts.\n // Pre-bundling them keeps the first optimization pass complete.\n '@payloadcms/ui > react-select > @floating-ui/dom',\n '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',\n '@payloadcms/ui > react-select > prop-types > react-is',\n '@payloadcms/ui > date-fns/locale/en-US',\n // Further late discoveries observed re-optimizing mid-run in CI cold starts\n // (see CI logs: \"✨ new dependencies optimized: @dnd-kit/modifiers / ajv /\n // dequal/lite\"). The modular dashboard pulls in `@dnd-kit/modifiers` on first\n // render; form-state diffing reaches `dequal/lite` (a distinct entry point\n // from the already-listed `dequal`); client-side field validation reaches\n // `ajv` *through `payload`* — it is `ssrExternal` server-side but still\n // bundled into the client, and must be pathed via `payload` so the optimizer\n // pre-bundles the exact copy the runtime loads.\n '@payloadcms/ui > @dnd-kit/modifiers',\n '@payloadcms/ui > dequal/lite',\n 'payload > ajv',\n // The storage client-upload suites (esp. vercel-blob) crawl part of the\n // `payload` server runtime into the client bundle and discover these late,\n // triggering several \"optimized dependencies changed. reloading\" waves that\n // reload the page mid-test (the bulk-upload drawer's Create New button /\n // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the\n // whole observed set so the first pass is complete.\n 'payload > undici',\n 'payload > jose',\n 'payload > dataloader',\n 'payload > path-to-regexp',\n 'payload > console-table-printer',\n 'payload > ci-info',\n 'payload > image-size',\n 'payload > image-size/fromFile',\n 'payload > ipaddr.js',\n 'payload > range-parser',\n 'payload > sanitize-filename',\n]\n"],"names":["ssrExternalPackages","payloadNoExternalPatterns","payloadRscNoExternalPatterns","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults"],"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;;;;;CAKC,GACD,OAAO,MAAMC,4BAAoD;IAC/D;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;;;;;CASC,GACD,OAAO,MAAMC,+BAAuD;IAClE;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kEAAkE;IAClE,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,6DAA6D;IAC7D;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,6EAA6E;IAC7E,+EAA+E;IAC/E,8EAA8E;IAC9E,wEAAwE;IACxE,uDAAuD;IACvD;IACA,8EAA8E;IAC9E,0EAA0E;IAC1E,4EAA4E;IAC5E,wEAAwE;IACxE,+EAA+E;IAC/E,8EAA8E;IAC9E,+EAA+E;IAC/E;IACA,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,qEAAqE;IACrE,yEAAyE;IACzE,uEAAuE;IACvE,gEAAgE;IAChE;IACA;IACA;IACA;IACA,4EAA4E;IAC5E,0EAA0E;IAC1E,8EAA8E;IAC9E,2EAA2E;IAC3E,0EAA0E;IAC1E,wEAAwE;IACxE,6EAA6E;IAC7E,gDAAgD;IAChD;IACA;IACA;IACA,wEAAwE;IACxE,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,oDAAoD;IACpD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}