@payloadcms/tanstack-start 4.0.0-internal.a0ef1b8 → 4.0.0-internal.bc5cf8c
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.
- package/dist/elements/RouterAdapter/index.d.ts.map +1 -1
- package/dist/elements/RouterAdapter/index.js +38 -15
- package/dist/elements/RouterAdapter/index.js.map +1 -1
- package/dist/exports/client.d.ts +4 -0
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/layouts.d.ts +1 -0
- package/dist/exports/layouts.d.ts.map +1 -1
- package/dist/exports/layouts.js +1 -0
- package/dist/exports/layouts.js.map +1 -1
- package/dist/exports/server.d.ts +2 -1
- package/dist/exports/server.d.ts.map +1 -1
- package/dist/exports/server.js +2 -1
- package/dist/exports/server.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
- package/dist/layouts/Root/getLayoutData.js +36 -0
- package/dist/layouts/Root/getLayoutData.js.map +1 -1
- package/dist/layouts/Root/index.d.ts +7 -0
- package/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/layouts/Root/withPayloadRoot.d.ts +65 -0
- package/dist/layouts/Root/withPayloadRoot.d.ts.map +1 -0
- package/dist/layouts/Root/withPayloadRoot.js +92 -0
- package/dist/layouts/Root/withPayloadRoot.js.map +1 -0
- package/dist/routes/adminRoutes.d.ts +105 -0
- package/dist/routes/adminRoutes.d.ts.map +1 -0
- package/dist/routes/adminRoutes.js +97 -0
- package/dist/routes/adminRoutes.js.map +1 -0
- package/dist/routes/apiRoute.d.ts +29 -0
- package/dist/routes/apiRoute.d.ts.map +1 -0
- package/dist/routes/apiRoute.js +38 -0
- package/dist/routes/apiRoute.js.map +1 -0
- package/dist/routes/layoutRoute.d.ts +23 -0
- package/dist/routes/layoutRoute.d.ts.map +1 -0
- package/dist/routes/layoutRoute.js +51 -0
- package/dist/routes/layoutRoute.js.map +1 -0
- package/dist/utilities/handleAPIRoute.d.ts +11 -0
- package/dist/utilities/handleAPIRoute.d.ts.map +1 -0
- package/dist/utilities/handleAPIRoute.js +17 -0
- package/dist/utilities/handleAPIRoute.js.map +1 -0
- package/dist/utilities/importMap.server.d.ts +4 -5
- package/dist/utilities/importMap.server.d.ts.map +1 -1
- package/dist/utilities/importMap.server.js +5 -6
- package/dist/utilities/importMap.server.js.map +1 -1
- package/dist/utilities/loadAdminPage.d.ts +54 -0
- package/dist/utilities/loadAdminPage.d.ts.map +1 -0
- package/dist/utilities/loadAdminPage.js +217 -0
- package/dist/utilities/loadAdminPage.js.map +1 -0
- package/dist/utilities/loadLayoutData.d.ts +15 -0
- package/dist/utilities/loadLayoutData.d.ts.map +1 -0
- package/dist/utilities/loadLayoutData.js +23 -0
- package/dist/utilities/loadLayoutData.js.map +1 -0
- package/dist/utilities/serializeForRsc.d.ts.map +1 -1
- package/dist/utilities/serializeForRsc.js +17 -0
- package/dist/utilities/serializeForRsc.js.map +1 -1
- package/dist/utilities/serverFunctionClient.d.ts +29 -0
- package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
- package/dist/utilities/serverFunctionClient.js +109 -0
- package/dist/utilities/serverFunctionClient.js.map +1 -0
- package/dist/vite/constants.d.ts +7 -2
- package/dist/vite/constants.d.ts.map +1 -1
- package/dist/vite/constants.js +53 -5
- package/dist/vite/constants.js.map +1 -1
- package/dist/vite/plugin.js +10 -13
- package/dist/vite/plugin.js.map +1 -1
- package/dist/vite/plugins/devTransforms.d.ts +11 -0
- package/dist/vite/plugins/devTransforms.d.ts.map +1 -1
- package/dist/vite/plugins/devTransforms.js +13 -2
- package/dist/vite/plugins/devTransforms.js.map +1 -1
- package/dist/vite/plugins/stripDistStyleImports.d.ts.map +1 -1
- package/dist/vite/plugins/stripDistStyleImports.js +54 -3
- package/dist/vite/plugins/stripDistStyleImports.js.map +1 -1
- package/package.json +7 -7
- package/dist/auth/switchLanguage.d.ts +0 -6
- package/dist/auth/switchLanguage.d.ts.map +0 -1
- package/dist/auth/switchLanguage.js +0 -11
- package/dist/auth/switchLanguage.js.map +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
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
|
+
// Navigation thrown deep inside a streamed view component (e.g. access
|
|
173
|
+
// denied → notFound, already-authenticated → redirect) is swallowed into
|
|
174
|
+
// the RSC stream and never rejects the render. Honor it from the holder,
|
|
175
|
+
// discarding the (broken) payload from the aborted render.
|
|
176
|
+
if (nav.type === 'redirect' && nav.url) {
|
|
177
|
+
return {
|
|
178
|
+
_redirect: nav.url
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (nav.type === 'notFound') {
|
|
182
|
+
return await renderNotFound();
|
|
183
|
+
}
|
|
184
|
+
// Resolve metadata through the same shared generator Next.js uses. Only
|
|
185
|
+
// plain strings cross the wire (the full `MetaConfig` carries a `URL`
|
|
186
|
+
// `metadataBase` and icons that seroval cannot serialize).
|
|
187
|
+
const i18n = await getRequestI18n({
|
|
188
|
+
config
|
|
189
|
+
});
|
|
190
|
+
const meta = await generatePageMetadata({
|
|
191
|
+
adminViews: defaultAdminViews,
|
|
192
|
+
config,
|
|
193
|
+
i18n,
|
|
194
|
+
params: {
|
|
195
|
+
segments
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return {
|
|
199
|
+
metadata: toAdminPageMetadata(meta),
|
|
200
|
+
routeKey: splat ?? '',
|
|
201
|
+
rscPayload
|
|
202
|
+
};
|
|
203
|
+
} catch (err) {
|
|
204
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
205
|
+
if (nav.type === 'notFound' || message === 'not-found') {
|
|
206
|
+
return await renderNotFound();
|
|
207
|
+
}
|
|
208
|
+
if (nav.type === 'redirect' || message.startsWith('redirect:')) {
|
|
209
|
+
return {
|
|
210
|
+
_redirect: nav.url ?? message.slice('redirect:'.length)
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//# 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 // 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","_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,MAAME,GAAG;YAAEC,QAAQH,MAAMG,MAAM;YAAEF,KAAKG,OAAOJ,MAAMC,GAAG;YAAGI,OAAOL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;QAEA,OAAO;YACLyB,UAAUnE,oBAAoBC;YAC9B6D,UAAU1B,SAAS;YACnBwB;QACF;IACF,EAAE,OAAOQ,KAAK;QACZ,MAAMC,UAAUD,eAAehB,QAAQgB,IAAIC,OAAO,GAAGvD,OAAOsD;QAC5D,IAAIxB,IAAIrB,IAAI,KAAK,cAAc8C,YAAY,aAAa;YACtD,OAAO,MAAMf;QACf;QACA,IAAIV,IAAIrB,IAAI,KAAK,cAAc8C,QAAQC,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAEL,WAAWrB,IAAIjC,GAAG,IAAI0D,QAAQE,KAAK,CAAC,YAAY3C,MAAM;YAAE;QACnE;QACA,MAAMwC;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializeForRsc.d.ts","sourceRoot":"","sources":["../../src/utilities/serializeForRsc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializeForRsc.d.ts","sourceRoot":"","sources":["../../src/utilities/serializeForRsc.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE7D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { renderServerComponent } from '@tanstack/react-start/rsc';
|
|
2
|
+
import { createElement, Fragment } from 'react';
|
|
2
3
|
/**
|
|
3
4
|
* Recursively walk a server-function return value and prepare it for transit
|
|
4
5
|
* to the client as an RSC payload.
|
|
@@ -78,6 +79,22 @@ async function walk(value, cache, ancestors) {
|
|
|
78
79
|
return cleaned;
|
|
79
80
|
}
|
|
80
81
|
if (Array.isArray(obj)) {
|
|
82
|
+
// An array consisting entirely of React elements (e.g. a field's
|
|
83
|
+
// `beforeInput` / `afterInput` component list, produced by
|
|
84
|
+
// `RenderServerComponent`) must be rendered as a SINGLE RSC handle.
|
|
85
|
+
// Converting each element individually below turns every item into its own
|
|
86
|
+
// `renderServerComponent` handle, which drops the element's React `key` —
|
|
87
|
+
// the client then renders `{[handle, handle]}` as unkeyed array children
|
|
88
|
+
// and React warns "Each child in a list should have a unique key prop".
|
|
89
|
+
// Payload always renders these component arrays wholesale (`{BeforeInput}`),
|
|
90
|
+
// so collapsing them into one Fragment-rendered handle is render-equivalent
|
|
91
|
+
// and keeps the per-element keys intact inside the single Flight payload.
|
|
92
|
+
const items = obj.filter((item)=>item !== null && item !== undefined);
|
|
93
|
+
const isReactElementArray = items.length > 0 && items.every((item)=>typeof item === 'object' && typeof item.$$typeof === 'symbol');
|
|
94
|
+
if (isReactElementArray) {
|
|
95
|
+
ancestors.delete(obj);
|
|
96
|
+
return await renderServerComponent(createElement(Fragment, null, ...obj));
|
|
97
|
+
}
|
|
81
98
|
const arr = [];
|
|
82
99
|
cache.set(obj, arr);
|
|
83
100
|
for (const item of obj){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/serializeForRsc.ts"],"sourcesContent":["import type React from 'react'\n\nimport { renderServerComponent } from '@tanstack/react-start/rsc'\n\n/**\n * Recursively walk a server-function return value and prepare it for transit\n * to the client as an RSC payload.\n *\n * Mirrors `toSerializable`'s walk (Maps, Sets, Dates, typed arrays, circular\n * refs) with two key differences:\n *\n * 1. React elements are NOT stripped. They are passed through\n * `renderServerComponent` from `@tanstack/react-start/rsc` to produce a\n * \"renderable RSC handle\". TanStack Start's `$RSC` serialization adapter\n * streams the underlying Flight payload to the client, where it is\n * decoded back into a renderable React node. This matches the way\n * Next.js's RSC payload format ships React elements over server actions\n * and lets server-rendered custom field components (e.g. those returned\n * by `buildFormState` / `RenderServerComponent`) survive a `form-state`\n * round trip.\n *\n * 2. Functions, Symbols, and RegExps are still stripped — TanStack's seroval\n * transport cannot handle them, and Payload doesn't intentionally include\n * them in server-function return values.\n *\n * Use this in `createServerFn` handlers that return Payload form/view state\n * containing React elements (e.g. `state[path].customComponents.Field`).\n */\nexport async function serializeForRsc<T>(value: T): Promise<T> {\n return (await walk(value, new WeakMap<object, unknown>(), new WeakSet<object>())) as T\n}\n\nasync function walk(\n value: unknown,\n cache: WeakMap<object, unknown>,\n ancestors: WeakSet<object>,\n): Promise<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 await renderServerComponent(value as React.ReactElement)\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 return obj\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 = await walk(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 = await walk(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(await walk(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 = await walk(obj[key], cache, ancestors)\n if (v !== undefined) {\n result[key] = v\n }\n }\n ancestors.delete(obj)\n return result\n}\n"],"names":["renderServerComponent","serializeForRsc","value","walk","WeakMap","WeakSet","cache","ancestors","undefined","t","obj","$$typeof","has","get","Date","RegExp","add","Map","cleaned","set","k","v","cv","delete","Set","Array","isArray","
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/serializeForRsc.ts"],"sourcesContent":["import type React from 'react'\n\nimport { renderServerComponent } from '@tanstack/react-start/rsc'\nimport { createElement, Fragment } from 'react'\n\n/**\n * Recursively walk a server-function return value and prepare it for transit\n * to the client as an RSC payload.\n *\n * Mirrors `toSerializable`'s walk (Maps, Sets, Dates, typed arrays, circular\n * refs) with two key differences:\n *\n * 1. React elements are NOT stripped. They are passed through\n * `renderServerComponent` from `@tanstack/react-start/rsc` to produce a\n * \"renderable RSC handle\". TanStack Start's `$RSC` serialization adapter\n * streams the underlying Flight payload to the client, where it is\n * decoded back into a renderable React node. This matches the way\n * Next.js's RSC payload format ships React elements over server actions\n * and lets server-rendered custom field components (e.g. those returned\n * by `buildFormState` / `RenderServerComponent`) survive a `form-state`\n * round trip.\n *\n * 2. Functions, Symbols, and RegExps are still stripped — TanStack's seroval\n * transport cannot handle them, and Payload doesn't intentionally include\n * them in server-function return values.\n *\n * Use this in `createServerFn` handlers that return Payload form/view state\n * containing React elements (e.g. `state[path].customComponents.Field`).\n */\nexport async function serializeForRsc<T>(value: T): Promise<T> {\n return (await walk(value, new WeakMap<object, unknown>(), new WeakSet<object>())) as T\n}\n\nasync function walk(\n value: unknown,\n cache: WeakMap<object, unknown>,\n ancestors: WeakSet<object>,\n): Promise<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 await renderServerComponent(value as React.ReactElement)\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 return obj\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 = await walk(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 = await walk(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 // An array consisting entirely of React elements (e.g. a field's\n // `beforeInput` / `afterInput` component list, produced by\n // `RenderServerComponent`) must be rendered as a SINGLE RSC handle.\n // Converting each element individually below turns every item into its own\n // `renderServerComponent` handle, which drops the element's React `key` —\n // the client then renders `{[handle, handle]}` as unkeyed array children\n // and React warns \"Each child in a list should have a unique key prop\".\n // Payload always renders these component arrays wholesale (`{BeforeInput}`),\n // so collapsing them into one Fragment-rendered handle is render-equivalent\n // and keeps the per-element keys intact inside the single Flight payload.\n const items = obj.filter((item) => item !== null && item !== undefined)\n const isReactElementArray =\n items.length > 0 &&\n items.every(\n (item) => typeof item === 'object' && typeof (item as { $$typeof?: unknown }).$$typeof === 'symbol',\n )\n if (isReactElementArray) {\n ancestors.delete(obj)\n return await renderServerComponent(createElement(Fragment, null, ...(obj as React.ReactNode[])))\n }\n\n const arr: unknown[] = []\n cache.set(obj, arr)\n for (const item of obj) {\n arr.push(await walk(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 = await walk(obj[key], cache, ancestors)\n if (v !== undefined) {\n result[key] = v\n }\n }\n ancestors.delete(obj)\n return result\n}\n"],"names":["renderServerComponent","createElement","Fragment","serializeForRsc","value","walk","WeakMap","WeakSet","cache","ancestors","undefined","t","obj","$$typeof","has","get","Date","RegExp","add","Map","cleaned","set","k","v","cv","delete","Set","Array","isArray","items","filter","item","isReactElementArray","length","every","arr","push","ArrayBuffer","isView","result","key","Object","keys"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,4BAA2B;AACjE,SAASC,aAAa,EAAEC,QAAQ,QAAQ,QAAO;AAE/C;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,eAAeC,gBAAmBC,KAAQ;IAC/C,OAAQ,MAAMC,KAAKD,OAAO,IAAIE,WAA4B,IAAIC;AAChE;AAEA,eAAeF,KACbD,KAAc,EACdI,KAA+B,EAC/BC,SAA0B;IAE1B,IAAIL,UAAU,QAAQA,UAAUM,WAAW;QACzC,OAAON;IACT;IAEA,MAAMO,IAAI,OAAOP;IACjB,IAAIO,MAAM,cAAcA,MAAM,UAAU;QACtC,OAAOD;IACT;IACA,IAAIC,MAAM,UAAU;QAClB,OAAOP;IACT;IAEA,MAAMQ,MAAMR;IAEZ,IAAI,OAAOQ,IAAIC,QAAQ,KAAK,UAAU;QACpC,OAAO,MAAMb,sBAAsBI;IACrC;IAEA,IAAIK,UAAUK,GAAG,CAACF,MAAM;QACtB,OAAOF;IACT;IAEA,IAAIF,MAAMM,GAAG,CAACF,MAAM;QAClB,OAAOJ,MAAMO,GAAG,CAACH;IACnB;IAEA,IAAIA,eAAeI,MAAM;QACvB,OAAOJ;IACT;IAEA,IAAIA,eAAeK,QAAQ;QACzB,OAAOP;IACT;IAEAD,UAAUS,GAAG,CAACN;IAEd,IAAIA,eAAeO,KAAK;QACtB,MAAMC,UAAU,IAAID;QACpBX,MAAMa,GAAG,CAACT,KAAKQ;QACf,KAAK,MAAM,CAACE,GAAGC,EAAE,IAAIX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AM,CAACb;QACjB,OAAOA;IACT;IAEA,MAAM2B,SAAkC,CAAC;IACzC/B,MAAMa,GAAG,CAACT,KAAK2B;IACf,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAAC9B,KAAM;QAClC,MAAMW,IAAI,MAAMlB,KAAKO,GAAG,CAAC4B,IAAI,EAAEhC,OAAOC;QACtC,IAAIc,MAAMb,WAAW;YACnB6B,MAAM,CAACC,IAAI,GAAGjB;QAChB;IACF;IACAd,UAAUgB,MAAM,CAACb;IACjB,OAAO2B;AACT"}
|
|
@@ -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,KAA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d;QACjB,OAAOS;IACT;IAEA,IAAIO,MAAMC,OAAO,CAACjB,MAAM;QACtB,MAAMkB,MAAiB,EAAE;QACzBxB,MAAMgB,GAAG,CAACV,KAAKkB;QACf,KAAK,MAAMC,QAAQnB,IAAK;YACtBkB,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"}
|
package/dist/vite/constants.d.ts
CHANGED
|
@@ -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.
|
|
20
|
-
*
|
|
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
|
|
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"}
|