@payloadcms/tanstack-start 4.0.0-internal.e7d4ebc → 4.0.0-internal.f05c47f
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/auth/login.d.ts +3 -16
- package/dist/auth/login.d.ts.map +1 -1
- package/dist/auth/login.js +6 -46
- package/dist/auth/login.js.map +1 -1
- package/dist/auth/logout.d.ts +2 -5
- package/dist/auth/logout.d.ts.map +1 -1
- package/dist/auth/logout.js +6 -47
- package/dist/auth/logout.js.map +1 -1
- package/dist/auth/refresh.d.ts +2 -4
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +6 -49
- package/dist/auth/refresh.js.map +1 -1
- package/dist/elements/RouterAdapter/index.d.ts.map +1 -1
- package/dist/elements/RouterAdapter/index.js +17 -3
- package/dist/elements/RouterAdapter/index.js.map +1 -1
- package/dist/exports/client.d.ts +0 -2
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +0 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/layouts.d.ts +2 -4
- package/dist/exports/layouts.d.ts.map +1 -1
- package/dist/exports/layouts.js +0 -1
- package/dist/exports/layouts.js.map +1 -1
- package/dist/exports/rsc.browser.d.ts +4 -1
- package/dist/exports/rsc.browser.d.ts.map +1 -1
- package/dist/exports/rsc.browser.js +4 -1
- package/dist/exports/rsc.browser.js.map +1 -1
- package/dist/exports/rsc.d.ts +0 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +0 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/exports/server.d.ts +1 -2
- package/dist/exports/server.d.ts.map +1 -1
- package/dist/exports/server.js +0 -1
- package/dist/exports/server.js.map +1 -1
- package/dist/layouts/Root/getLayoutData.d.ts +24 -2
- package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
- package/dist/layouts/Root/getLayoutData.js +6 -0
- package/dist/layouts/Root/getLayoutData.js.map +1 -1
- package/dist/routes/adminRoutes.d.ts +10 -13
- package/dist/routes/adminRoutes.d.ts.map +1 -1
- package/dist/routes/adminRoutes.js +49 -39
- package/dist/routes/adminRoutes.js.map +1 -1
- package/dist/routes/layoutRoute.d.ts +4 -3
- package/dist/routes/layoutRoute.d.ts.map +1 -1
- package/dist/routes/layoutRoute.js +1 -0
- package/dist/routes/layoutRoute.js.map +1 -1
- package/dist/utilities/devConfigReload.server.d.ts +2 -0
- package/dist/utilities/devConfigReload.server.d.ts.map +1 -0
- package/dist/utilities/devConfigReload.server.js +38 -0
- package/dist/utilities/devConfigReload.server.js.map +1 -0
- package/dist/utilities/devConfigReloadEvent.d.ts +9 -0
- package/dist/utilities/devConfigReloadEvent.d.ts.map +1 -0
- package/dist/utilities/devConfigReloadEvent.js +9 -0
- package/dist/utilities/devConfigReloadEvent.js.map +1 -0
- package/dist/utilities/getRequestLocale.d.ts.map +1 -1
- package/dist/utilities/getRequestLocale.js +1 -2
- package/dist/utilities/getRequestLocale.js.map +1 -1
- package/dist/utilities/initReq.server.d.ts +1 -0
- package/dist/utilities/initReq.server.d.ts.map +1 -1
- package/dist/utilities/initReq.server.js +3 -0
- package/dist/utilities/initReq.server.js.map +1 -1
- package/dist/utilities/loadAdminPage.d.ts +5 -2
- package/dist/utilities/loadAdminPage.d.ts.map +1 -1
- package/dist/utilities/loadAdminPage.js +2 -11
- package/dist/utilities/loadAdminPage.js.map +1 -1
- package/dist/utilities/loadLayoutData.d.ts +3 -1
- package/dist/utilities/loadLayoutData.d.ts.map +1 -1
- package/dist/utilities/loadLayoutData.js +2 -3
- package/dist/utilities/loadLayoutData.js.map +1 -1
- package/dist/utilities/toSerializable.d.ts +9 -0
- package/dist/utilities/toSerializable.d.ts.map +1 -1
- package/dist/utilities/toSerializable.js +13 -2
- package/dist/utilities/toSerializable.js.map +1 -1
- package/dist/withPayload/config/external.d.ts +16 -8
- package/dist/withPayload/config/external.d.ts.map +1 -1
- package/dist/withPayload/config/external.js +23 -9
- package/dist/withPayload/config/external.js.map +1 -1
- package/dist/withPayload/config/optimizeDeps.d.ts.map +1 -1
- package/dist/withPayload/config/optimizeDeps.js +7 -3
- package/dist/withPayload/config/optimizeDeps.js.map +1 -1
- package/dist/withPayload/devConfigReload.d.ts +14 -0
- package/dist/withPayload/devConfigReload.d.ts.map +1 -0
- package/dist/withPayload/devConfigReload.js +84 -0
- package/dist/withPayload/devConfigReload.js.map +1 -0
- package/dist/withPayload/importProtection.d.ts.map +1 -1
- package/dist/withPayload/importProtection.js +2 -2
- package/dist/withPayload/importProtection.js.map +1 -1
- package/dist/withPayload/index.d.ts +13 -0
- package/dist/withPayload/index.d.ts.map +1 -1
- package/dist/withPayload/index.js +28 -3
- package/dist/withPayload/index.js.map +1 -1
- package/dist/withPayload/workarounds/stripDistStyleImports.js +1 -1
- package/dist/withPayload/workarounds/stripDistStyleImports.js.map +1 -1
- package/package.json +8 -7
- package/dist/elements/DocumentHeaderClient/index.d.ts +0 -16
- package/dist/elements/DocumentHeaderClient/index.d.ts.map +0 -1
- package/dist/elements/DocumentHeaderClient/index.js +0 -116
- package/dist/elements/DocumentHeaderClient/index.js.map +0 -1
- package/dist/elements/RenderComponent/index.d.ts +0 -10
- package/dist/elements/RenderComponent/index.d.ts.map +0 -1
- package/dist/elements/RenderComponent/index.js +0 -12
- package/dist/elements/RenderComponent/index.js.map +0 -1
- package/dist/layouts/Root/index.d.ts +0 -32
- package/dist/layouts/Root/index.d.ts.map +0 -1
- package/dist/layouts/Root/index.js +0 -53
- package/dist/layouts/Root/index.js.map +0 -1
- package/dist/rsc/renderPayloadRSC.d.ts +0 -6
- package/dist/rsc/renderPayloadRSC.d.ts.map +0 -1
- package/dist/rsc/renderPayloadRSC.js +0 -6
- package/dist/rsc/renderPayloadRSC.js.map +0 -1
- package/dist/utilities/devReloadStrategy.d.ts +0 -10
- package/dist/utilities/devReloadStrategy.d.ts.map +0 -1
- package/dist/utilities/devReloadStrategy.js +0 -27
- package/dist/utilities/devReloadStrategy.js.map +0 -1
- package/dist/utilities/getExistingAuthToken.d.ts +0 -7
- package/dist/utilities/getExistingAuthToken.d.ts.map +0 -1
- package/dist/utilities/getExistingAuthToken.js +0 -18
- package/dist/utilities/getExistingAuthToken.js.map +0 -1
- package/dist/utilities/getPreferences.d.ts +0 -10
- package/dist/utilities/getPreferences.d.ts.map +0 -1
- package/dist/utilities/getPreferences.js +0 -33
- package/dist/utilities/getPreferences.js.map +0 -1
- package/dist/utilities/importMap.server.d.ts +0 -8
- package/dist/utilities/importMap.server.d.ts.map +0 -1
- package/dist/utilities/importMap.server.js +0 -11
- package/dist/utilities/importMap.server.js.map +0 -1
- package/dist/utilities/setPayloadAuthCookie.d.ts +0 -9
- package/dist/utilities/setPayloadAuthCookie.d.ts.map +0 -1
- package/dist/utilities/setPayloadAuthCookie.js +0 -31
- package/dist/utilities/setPayloadAuthCookie.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadAdminPage.d.ts","sourceRoot":"","sources":["../../src/utilities/loadAdminPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,eAAe,EAAE,MAAM,SAAS,CAAA;AAKrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAMlD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAA;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"loadAdminPage.d.ts","sourceRoot":"","sources":["../../src/utilities/loadAdminPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAc,eAAe,EAAE,MAAM,SAAS,CAAA;AAKrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAMlD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAA;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,KAAK,UAAU,GAAG,yBAAyB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AAE/D,MAAM,MAAM,mBAAmB,GAC3B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,UAAU,CAAA;CAAE,GAC/D;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB;IACE,QAAQ,EAAE,iBAAiB,CAAA;IAC3B;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AA0FL;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAkJlD"}
|
|
@@ -115,15 +115,6 @@ const resolveTitle = (title)=>{
|
|
|
115
115
|
userAgent = result.headers.get('user-agent') ?? undefined;
|
|
116
116
|
return result;
|
|
117
117
|
};
|
|
118
|
-
const notFound = ()=>{
|
|
119
|
-
nav.type = 'notFound';
|
|
120
|
-
throw new Error('not-found');
|
|
121
|
-
};
|
|
122
|
-
const redirect = (url)=>{
|
|
123
|
-
nav.type = 'redirect';
|
|
124
|
-
nav.url = url;
|
|
125
|
-
throw new Error(`redirect:${url}`);
|
|
126
|
-
};
|
|
127
118
|
// Build the 404 result the route loader re-throws as TanStack `notFound()`.
|
|
128
119
|
//
|
|
129
120
|
// Throwing `notFound()` is the only way to set the SSR document status to 404
|
|
@@ -166,13 +157,13 @@ const resolveTitle = (title)=>{
|
|
|
166
157
|
importMap,
|
|
167
158
|
initReq: boundInitReq,
|
|
168
159
|
key: splat ?? '',
|
|
169
|
-
notFound,
|
|
160
|
+
notFound: pageServerAdapter.notFound,
|
|
170
161
|
// `segments` is intentionally `undefined` for the admin root (`/admin`),
|
|
171
162
|
// matching Next's optional catch-all; `renderRoot` handles it at runtime.
|
|
172
163
|
params: Promise.resolve({
|
|
173
164
|
segments
|
|
174
165
|
}),
|
|
175
|
-
redirect,
|
|
166
|
+
redirect: pageServerAdapter.redirect,
|
|
176
167
|
searchParams: Promise.resolve(searchParams)
|
|
177
168
|
});
|
|
178
169
|
const rscPayload = await renderServerComponent(node);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/loadAdminPage.tsx"],"sourcesContent":["import type { ImportMap, MetaConfig, SanitizedConfig } from 'payload'\n\nimport { getViewportContent } from '@payloadcms/ui/shared'\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 let userAgent: string | undefined\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'] = async (args) => {\n const result = await initReq({\n configPromise: args.configPromise,\n importMap: args.importMap,\n overrides: args.overrides,\n serverAdapter: pageServerAdapter,\n })\n userAgent = result.headers.get('user-agent') ?? undefined\n return result\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 key: splat ?? '',\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: {\n ...toAdminPageMetadata(meta),\n viewport: getViewportContent(userAgent),\n },\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":["getViewportContent","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","userAgent","boundInitReq","args","result","configPromise","overrides","serverAdapter","headers","get","notFound","Error","redirect","renderNotFound","renderNotFoundPage","notFoundNode","Promise","resolve","params","rscPayload","_notFound","routeKey","node","adminViews","key","wrapper","Symbol","for","createReplayStream","buffer","Response","arrayBuffer","body","_redirect","i18n","metadata","viewport","err","message","startsWith","slice"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,wBAAuB;AAC1D,SAASC,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,UAA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0B,IAAIC,OAAO,GAAGrE,OAAOoE;QAC5D,IAAItC,IAAIrB,IAAI,KAAK,cAAc4D,YAAY,aAAa;YACtD,OAAO,MAAMzB;QACf;QACA,IAAId,IAAIrB,IAAI,KAAK,cAAc4D,QAAQC,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAEN,WAAWlC,IAAIjC,GAAG,IAAIwE,QAAQE,KAAK,CAAC,YAAYzD,MAAM;YAAE;QACnE;QACA,MAAMsD;IACR;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/loadAdminPage.tsx"],"sourcesContent":["import type { RenderableServerComponent } from '@tanstack/react-start/rsc'\nimport type { ImportMap, MetaConfig, SanitizedConfig } from 'payload'\n\nimport { getViewportContent } from '@payloadcms/ui/shared'\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\ntype RSCPayload = RenderableServerComponent<React.ReactElement>\n\nexport type LoadAdminPageResult =\n | { _notFound: true; routeKey?: string; rscPayload?: RSCPayload }\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: RSCPayload\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 let userAgent: string | undefined\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'] = async (args) => {\n const result = await initReq({\n configPromise: args.configPromise,\n importMap: args.importMap,\n overrides: args.overrides,\n serverAdapter: pageServerAdapter,\n })\n userAgent = result.headers.get('user-agent') ?? undefined\n return result\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 key: splat ?? '',\n notFound: pageServerAdapter.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: pageServerAdapter.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: {\n ...toAdminPageMetadata(meta),\n viewport: getViewportContent(userAgent),\n },\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":["getViewportContent","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","userAgent","boundInitReq","args","result","configPromise","overrides","serverAdapter","headers","get","renderNotFound","renderNotFoundPage","notFoundNode","Promise","resolve","params","rscPayload","_notFound","routeKey","node","adminViews","key","notFound","redirect","wrapper","Symbol","for","createReplayStream","buffer","Response","arrayBuffer","body","_redirect","i18n","metadata","viewport","err","message","Error","startsWith","slice"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,wBAAuB;AAC1D,SAASC,qBAAqB,QAAQ,4BAA2B;AAIjE,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,OAAO,QAAQ,sBAAqB;AAC7C,SAASC,6BAA6B,QAAQ,4BAA2B;AA+BzE,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,OA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3EN,QAAQG,kBAAkB,GAAG,IAAM,IAAIE,SAASD,QAAQG,IAAI;YAC9D;QACF;QAEA,uEAAuE;QACvE,yEAAyE;QACzE,yEAAyE;QACzE,2DAA2D;QAC3D,IAAIhC,IAAIrB,IAAI,KAAK,cAAcqB,IAAIjC,GAAG,EAAE;YACtC,OAAO;gBAAEkE,WAAWjC,IAAIjC,GAAG;YAAC;QAC9B;QACA,IAAIiC,IAAIrB,IAAI,KAAK,YAAY;YAC3B,OAAO,MAAMgC;QACf;QAEA,wEAAwE;QACxE,sEAAsE;QACtE,2DAA2D;QAC3D,MAAMuB,OAAO,MAAMtF,eAAe;YAAEyC;QAAO;QAC3C,MAAMhC,OAAO,MAAMsC,qBAAqB;YACtC0B,YAAY3B;YACZL;YACA6C;YACAlB,QAAQ;gBAAElB;YAAS;QACrB;QAEA,OAAO;YACLqC,UAAU;gBACR,GAAG/E,oBAAoBC,KAAK;gBAC5B+E,UAAU1F,mBAAmBwD;YAC/B;YACAiB,UAAU3B,SAAS;YACnByB;QACF;IACF,EAAE,OAAOoB,KAAK;QACZ,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAGpE,OAAOmE;QAC5D,IAAIrC,IAAIrB,IAAI,KAAK,cAAc2D,YAAY,aAAa;YACtD,OAAO,MAAM3B;QACf;QACA,IAAIX,IAAIrB,IAAI,KAAK,cAAc2D,QAAQE,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAEP,WAAWjC,IAAIjC,GAAG,IAAIuE,QAAQG,KAAK,CAAC,YAAYzD,MAAM;YAAE;QACnE;QACA,MAAMqD;IACR;AACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ImportMap, SanitizedConfig } from 'payload';
|
|
2
|
+
import type { SerializableRecord } from './toSerializable.js';
|
|
3
|
+
export type LoadLayoutDataResult = SerializableRecord;
|
|
2
4
|
/**
|
|
3
5
|
* Resolves the admin layout data for TanStack Start and returns a serializable
|
|
4
6
|
* payload for the `/_payload` route loader. The framework adapter wraps this in
|
|
@@ -11,5 +13,5 @@ import type { ImportMap, SanitizedConfig } from 'payload';
|
|
|
11
13
|
export declare function loadLayoutData({ config, importMap, }: {
|
|
12
14
|
config: SanitizedConfig;
|
|
13
15
|
importMap: ImportMap;
|
|
14
|
-
}): Promise<
|
|
16
|
+
}): Promise<LoadLayoutDataResult>;
|
|
15
17
|
//# sourceMappingURL=loadLayoutData.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAIzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAK7D,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AAErD;;;;;;;;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,oBAAoB,CAAC,CAMhC"}
|
|
@@ -14,10 +14,9 @@ import { toSerializable } from './toSerializable.js';
|
|
|
14
14
|
configPromise: config,
|
|
15
15
|
importMap
|
|
16
16
|
});
|
|
17
|
-
return {
|
|
18
|
-
...toSerializable(data),
|
|
17
|
+
return toSerializable(data, {
|
|
19
18
|
providers: providers ? await renderServerComponent(providers) : undefined
|
|
20
|
-
};
|
|
19
|
+
});
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=loadLayoutData.js.map
|
|
@@ -1 +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<
|
|
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 type { SerializableRecord } from './toSerializable.js'\n\nimport { getLayoutData } from '../layouts/Root/getLayoutData.js'\nimport { toSerializable } from './toSerializable.js'\n\nexport type LoadLayoutDataResult = SerializableRecord\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<LoadLayoutDataResult> {\n const { providers, ...data } = await getLayoutData({ configPromise: config, importMap })\n\n return toSerializable(data, {\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;AAIjE,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAIpD;;;;;;;;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,OAAOH,eAAeK,MAAM;QAC1BD,WAAWA,YAAY,MAAMN,sBAAsBM,aAAoBG;IACzE;AACF"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import type { Serializable, SerializableExtensions } from '@tanstack/react-router';
|
|
2
|
+
/** A record sanitized for TanStack's server-function transport. */
|
|
3
|
+
export type SerializableRecord = Record<string, unknown> & SerializableExtensions['TsrSerializable'];
|
|
4
|
+
/**
|
|
5
|
+
* Removes values unsupported by TanStack's serializer. Trusted serializable
|
|
6
|
+
* additions are merged afterward so opaque handles such as RSC payloads are
|
|
7
|
+
* preserved while the source record is sanitized.
|
|
8
|
+
*/
|
|
1
9
|
export declare function toSerializable<T>(value: T): T;
|
|
10
|
+
export declare function toSerializable(value: Record<string, unknown>, additions: Record<string, Serializable>): SerializableRecord;
|
|
2
11
|
//# sourceMappingURL=toSerializable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toSerializable.d.ts","sourceRoot":"","sources":["../../src/utilities/toSerializable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toSerializable.d.ts","sourceRoot":"","sources":["../../src/utilities/toSerializable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAElF,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,CAAA;AA+HpG;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;AAC9C,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACtC,kBAAkB,CAAA"}
|
|
@@ -104,8 +104,19 @@
|
|
|
104
104
|
ancestors.delete(obj);
|
|
105
105
|
return result;
|
|
106
106
|
}
|
|
107
|
-
export function toSerializable(value) {
|
|
108
|
-
|
|
107
|
+
export function toSerializable(value, additions) {
|
|
108
|
+
const serialized = stripUnserializable(value);
|
|
109
|
+
if (additions) {
|
|
110
|
+
if (typeof serialized !== 'object' || serialized === null || Array.isArray(serialized)) {
|
|
111
|
+
throw new TypeError('Serializable additions require an object source');
|
|
112
|
+
}
|
|
113
|
+
const result = {
|
|
114
|
+
...serialized,
|
|
115
|
+
...additions
|
|
116
|
+
};
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
return serialized;
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
//# sourceMappingURL=toSerializable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/toSerializable.ts"],"sourcesContent":["/**\n * Recursively strip values that seroval cannot serialize (React elements,\n * functions, Symbols) while preserving Maps, Sets, Dates, typed arrays, etc.\n *\n * TanStack Start uses seroval to transfer server function return values to\n * the client. Payload's `getClientConfig` / `getLayoutData` may include\n * callback functions or RegExp instances that seroval chokes on. Running\n * the data through this function before returning from a `createServerFn`\n * handler keeps the transfer safe.\n *\n * For server functions whose payloads contain React elements (e.g. the\n * shared `form-state` / `render-list` / `render-document` handlers), use\n * `serializeForRsc` instead — it converts elements into RSC handles rather\n * than stripping them.\n *\n * Uses a WeakMap cache so that shared object references (e.g. the same array\n * referenced by both `doc.hasMany` and `formState.hasMany.value`) are\n * returned correctly instead of being dropped as \"already seen\".\n *\n * A separate `ancestors` WeakSet tracks objects currently being recursed into.\n * If an object is encountered while it is still on the recursion stack, the\n * reference is circular and is replaced with `undefined` to keep the output\n * JSON-safe. Once recursion completes the object is removed from `ancestors`,\n * so sibling/cousin references to the same (fully-processed) object still\n * resolve to the cached clone.\n */\nfunction stripUnserializable(\n value: unknown,\n cache = new WeakMap<object, unknown>(),\n ancestors = new WeakSet<object>(),\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 return obj\n }\n\n // RegExp: seroval's SSR bootstrap emits regex literals with broken escape\n // sequences (e.g. `/!\\\\[.../` instead of `/!\\[.../`), crashing the client\n // script that populates `window.$_TSR` and preventing hydration. Rich-text\n // feature transformer regexes aren't needed on the client (they drive\n // server-side markdown import/export), so strip them here.\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\nexport function toSerializable<T>(value: T): T {\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/toSerializable.ts"],"sourcesContent":["import type { Serializable, SerializableExtensions } from '@tanstack/react-router'\n\n/** A record sanitized for TanStack's server-function transport. */\nexport type SerializableRecord = Record<string, unknown> & SerializableExtensions['TsrSerializable']\n\n/**\n * Recursively strip values that seroval cannot serialize (React elements,\n * functions, Symbols) while preserving Maps, Sets, Dates, typed arrays, etc.\n *\n * TanStack Start uses seroval to transfer server function return values to\n * the client. Payload's `getClientConfig` / `getLayoutData` may include\n * callback functions or RegExp instances that seroval chokes on. Running\n * the data through this function before returning from a `createServerFn`\n * handler keeps the transfer safe.\n *\n * For server functions whose payloads contain React elements (e.g. the\n * shared `form-state` / `render-list` / `render-document` handlers), use\n * `serializeForRsc` instead — it converts elements into RSC handles rather\n * than stripping them.\n *\n * Uses a WeakMap cache so that shared object references (e.g. the same array\n * referenced by both `doc.hasMany` and `formState.hasMany.value`) are\n * returned correctly instead of being dropped as \"already seen\".\n *\n * A separate `ancestors` WeakSet tracks objects currently being recursed into.\n * If an object is encountered while it is still on the recursion stack, the\n * reference is circular and is replaced with `undefined` to keep the output\n * JSON-safe. Once recursion completes the object is removed from `ancestors`,\n * so sibling/cousin references to the same (fully-processed) object still\n * resolve to the cached clone.\n */\nfunction stripUnserializable(\n value: unknown,\n cache = new WeakMap<object, unknown>(),\n ancestors = new WeakSet<object>(),\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 return obj\n }\n\n // RegExp: seroval's SSR bootstrap emits regex literals with broken escape\n // sequences (e.g. `/!\\\\[.../` instead of `/!\\[.../`), crashing the client\n // script that populates `window.$_TSR` and preventing hydration. Rich-text\n // feature transformer regexes aren't needed on the client (they drive\n // server-side markdown import/export), so strip them here.\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\n/**\n * Removes values unsupported by TanStack's serializer. Trusted serializable\n * additions are merged afterward so opaque handles such as RSC payloads are\n * preserved while the source record is sanitized.\n */\nexport function toSerializable<T>(value: T): T\nexport function toSerializable(\n value: Record<string, unknown>,\n additions: Record<string, Serializable>,\n): SerializableRecord\nexport function toSerializable(value: unknown, additions?: Record<string, Serializable>): unknown {\n const serialized = stripUnserializable(value)\n\n if (additions) {\n if (typeof serialized !== 'object' || serialized === null || Array.isArray(serialized)) {\n throw new TypeError('Serializable additions require an object source')\n }\n\n const result = { ...serialized, ...additions } satisfies Record<string, unknown>\n\n return result as SerializableRecord\n }\n\n return serialized\n}\n"],"names":["stripUnserializable","value","cache","WeakMap","ancestors","WeakSet","undefined","t","obj","$$typeof","has","get","Date","RegExp","add","Map","cleaned","set","k","v","cv","delete","Set","Array","isArray","arr","item","push","ArrayBuffer","isView","result","key","Object","keys","toSerializable","additions","serialized","TypeError"],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,SAASA,oBACPC,KAAc,EACdC,QAAQ,IAAIC,SAA0B,EACtCC,YAAY,IAAIC,SAAiB;IAEjC,IAAIJ,UAAU,QAAQA,UAAUK,WAAW;QACzC,OAAOL;IACT;IAEA,MAAMM,IAAI,OAAON;IACjB,IAAIM,MAAM,cAAcA,MAAM,UAAU;QACtC,OAAOD;IACT;IACA,IAAIC,MAAM,UAAU;QAClB,OAAON;IACT;IAEA,MAAMO,MAAMP;IAEZ,IAAI,OAAOO,IAAIC,QAAQ,KAAK,UAAU;QACpC,OAAOH;IACT;IAEA,IAAIF,UAAUM,GAAG,CAACF,MAAM;QACtB,OAAOF;IACT;IAEA,IAAIJ,MAAMQ,GAAG,CAACF,MAAM;QAClB,OAAON,MAAMS,GAAG,CAACH;IACnB;IAEA,IAAIA,eAAeI,MAAM;QACvB,OAAOJ;IACT;IAEA,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,sEAAsE;IACtE,2DAA2D;IAC3D,IAAIA,eAAeK,QAAQ;QACzB,OAAOP;IACT;IAEAF,UAAUU,GAAG,CAACN;IAEd,IAAIA,eAAeO,KAAK;QACtB,MAAMC,UAAU,IAAID;QACpBb,MAAMe,GAAG,CAACT,KAAKQ;QACf,KAAK,MAAM,CAACE,GAAGC,EAAE,IAAIX,IAAK;YACxB,MAAMY,KAAKpB,oBAAoBmB,GAAGjB,OAAOE;YACzC,IAAIgB,OAAOd,WAAW;gBACpBU,QAAQC,GAAG,CAACC,GAAGE;YACjB;QACF;QACAhB,UAAUiB,MAAM,CAACb;QACjB,OA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@@ -8,10 +8,23 @@
|
|
|
8
8
|
* fragile UMD wrappers (e.g. `pluralize`, whose `this`-based global assignment
|
|
9
9
|
* throws when transformed rather than required).
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Safe here whoever declared the entry: Node resolves from the importing package,
|
|
12
|
+
* so pnpm's isolated layout never applies. The build is stricter — see
|
|
13
|
+
* {@link buildBundledPackages}.
|
|
13
14
|
*/
|
|
14
15
|
export declare const ssrExternalPackages: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Entries of {@link ssrExternalPackages} that must bundle in the production build.
|
|
18
|
+
*
|
|
19
|
+
* Externalizing only works for specifiers resolvable from the project root. These
|
|
20
|
+
* are leaf deps of Payload packages, so under pnpm they live in `.pnpm/…` and a bare
|
|
21
|
+
* specifier in a root-resolved chunk is invisible — `ERR_MODULE_NOT_FOUND` at
|
|
22
|
+
* runtime, or a build-time resolve failure under Nitro's re-bundle pass.
|
|
23
|
+
*
|
|
24
|
+
* `pluralize` also needs forcing back via `noExternal` (see `withPayload`); the
|
|
25
|
+
* storage leaves don't, since their adapters are already `noExternal`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const buildBundledPackages: string[];
|
|
15
28
|
/**
|
|
16
29
|
* External packages for the production `vite build` only (not dev serve).
|
|
17
30
|
*
|
|
@@ -19,17 +32,12 @@ export declare const ssrExternalPackages: string[];
|
|
|
19
32
|
* resolves its own transitive Node deps (`pino`, `drizzle-orm`, `libsql`, …) from
|
|
20
33
|
* its own `node_modules` at runtime. Externalizing only the leaf deps breaks under
|
|
21
34
|
* pnpm: a leaf imported by bundled code becomes an unresolvable bare specifier from
|
|
22
|
-
* `dist/`, since pnpm does not hoist it.
|
|
35
|
+
* `dist/`, since pnpm does not hoist it; see {@link buildBundledPackages}.
|
|
23
36
|
*
|
|
24
37
|
* Kept out of dev's `ssr.external` on purpose: the monorepo resolves these to
|
|
25
38
|
* TypeScript source (`.ts` imported via `.js` specifiers), which only Vite's
|
|
26
39
|
* transform can resolve — an externalized copy would hit Node's raw resolver and
|
|
27
40
|
* fail on the `.js`→`.ts` mismatch.
|
|
28
|
-
*
|
|
29
|
-
* `pluralize` is excluded: it is reached from client-safe code (`payload`'s
|
|
30
|
-
* `formatLabels`, shipped in the `/shared` export), so externalizing it would
|
|
31
|
-
* leave a bare specifier in a bundled client chunk that pnpm can't resolve from
|
|
32
|
-
* `dist/` at runtime. It must bundle for the build.
|
|
33
41
|
*/
|
|
34
42
|
export declare const buildExternalPackages: string[];
|
|
35
43
|
export declare const payloadNoExternalPatterns: Array<RegExp | string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../../src/withPayload/config/external.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../../src/withPayload/config/external.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,EA+BvC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAOxC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,EAUzC,CAAA;AAED,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO5D,CAAA"}
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* fragile UMD wrappers (e.g. `pluralize`, whose `this`-based global assignment
|
|
8
8
|
* throws when transformed rather than required).
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Safe here whoever declared the entry: Node resolves from the importing package,
|
|
11
|
+
* so pnpm's isolated layout never applies. The build is stricter — see
|
|
12
|
+
* {@link buildBundledPackages}.
|
|
12
13
|
*/ export const ssrExternalPackages = [
|
|
13
14
|
'ajv',
|
|
14
15
|
'fast-uri',
|
|
@@ -41,6 +42,24 @@
|
|
|
41
42
|
'mongodb',
|
|
42
43
|
'mongoose'
|
|
43
44
|
];
|
|
45
|
+
/**
|
|
46
|
+
* Entries of {@link ssrExternalPackages} that must bundle in the production build.
|
|
47
|
+
*
|
|
48
|
+
* Externalizing only works for specifiers resolvable from the project root. These
|
|
49
|
+
* are leaf deps of Payload packages, so under pnpm they live in `.pnpm/…` and a bare
|
|
50
|
+
* specifier in a root-resolved chunk is invisible — `ERR_MODULE_NOT_FOUND` at
|
|
51
|
+
* runtime, or a build-time resolve failure under Nitro's re-bundle pass.
|
|
52
|
+
*
|
|
53
|
+
* `pluralize` also needs forcing back via `noExternal` (see `withPayload`); the
|
|
54
|
+
* storage leaves don't, since their adapters are already `noExternal`.
|
|
55
|
+
*/ export const buildBundledPackages = [
|
|
56
|
+
'pluralize',
|
|
57
|
+
// Leaf deps of the `@payloadcms/storage-*` adapters.
|
|
58
|
+
'@aws-sdk/client-s3',
|
|
59
|
+
'@aws-sdk/s3-request-presigner',
|
|
60
|
+
'@azure/storage-blob',
|
|
61
|
+
'@google-cloud/storage'
|
|
62
|
+
];
|
|
44
63
|
/**
|
|
45
64
|
* External packages for the production `vite build` only (not dev serve).
|
|
46
65
|
*
|
|
@@ -48,17 +67,12 @@
|
|
|
48
67
|
* resolves its own transitive Node deps (`pino`, `drizzle-orm`, `libsql`, …) from
|
|
49
68
|
* its own `node_modules` at runtime. Externalizing only the leaf deps breaks under
|
|
50
69
|
* pnpm: a leaf imported by bundled code becomes an unresolvable bare specifier from
|
|
51
|
-
* `dist/`, since pnpm does not hoist it.
|
|
70
|
+
* `dist/`, since pnpm does not hoist it; see {@link buildBundledPackages}.
|
|
52
71
|
*
|
|
53
72
|
* Kept out of dev's `ssr.external` on purpose: the monorepo resolves these to
|
|
54
73
|
* TypeScript source (`.ts` imported via `.js` specifiers), which only Vite's
|
|
55
74
|
* transform can resolve — an externalized copy would hit Node's raw resolver and
|
|
56
75
|
* fail on the `.js`→`.ts` mismatch.
|
|
57
|
-
*
|
|
58
|
-
* `pluralize` is excluded: it is reached from client-safe code (`payload`'s
|
|
59
|
-
* `formatLabels`, shipped in the `/shared` export), so externalizing it would
|
|
60
|
-
* leave a bare specifier in a bundled client chunk that pnpm can't resolve from
|
|
61
|
-
* `dist/` at runtime. It must bundle for the build.
|
|
62
76
|
*/ export const buildExternalPackages = [
|
|
63
77
|
'payload',
|
|
64
78
|
'payload/node',
|
|
@@ -68,7 +82,7 @@
|
|
|
68
82
|
'@payloadcms/db-vercel-postgres',
|
|
69
83
|
'@payloadcms/db-sqlite',
|
|
70
84
|
'@payloadcms/db-d1-sqlite',
|
|
71
|
-
...ssrExternalPackages.filter((pkg)
|
|
85
|
+
...ssrExternalPackages.filter((pkg)=>!buildBundledPackages.includes(pkg))
|
|
72
86
|
];
|
|
73
87
|
export const payloadNoExternalPatterns = [
|
|
74
88
|
'@payloadcms/ui',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/withPayload/config/external.ts"],"sourcesContent":["/**\n * SSR/RSC externalization config used by `withPayload`. Kept separate from the\n * client optimizer config (`./optimizeDeps.ts`) so each concern stays small.\n */\n\n/**\n * Packages externalized during dev serve (`ssr.external`). Node's loader resolves\n * their CJS/UMD directly; letting Vite's dev SSR transform touch them can break\n * fragile UMD wrappers (e.g. `pluralize`, whose `this`-based global assignment\n * throws when transformed rather than required).\n *\n *
|
|
1
|
+
{"version":3,"sources":["../../../src/withPayload/config/external.ts"],"sourcesContent":["/**\n * SSR/RSC externalization config used by `withPayload`. Kept separate from the\n * client optimizer config (`./optimizeDeps.ts`) so each concern stays small.\n */\n\n/**\n * Packages externalized during dev serve (`ssr.external`). Node's loader resolves\n * their CJS/UMD directly; letting Vite's dev SSR transform touch them can break\n * fragile UMD wrappers (e.g. `pluralize`, whose `this`-based global assignment\n * throws when transformed rather than required).\n *\n * Safe here whoever declared the entry: Node resolves from the importing package,\n * so pnpm's isolated layout never applies. The build is stricter — see\n * {@link buildBundledPackages}.\n */\nexport const ssrExternalPackages: string[] = [\n 'ajv',\n 'fast-uri',\n 'drizzle-kit',\n 'drizzle-kit/api',\n 'drizzle-orm',\n 'sharp',\n 'require-in-the-middle',\n 'json-schema-to-typescript',\n 'pino',\n 'pino-pretty',\n 'graphql',\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 // Database drivers + their lazily-required companions, one group per adapter.\n // Postgres (`@payloadcms/db-postgres`, `@payloadcms/db-vercel-postgres`)\n 'pg',\n 'pg-native',\n 'pg-cloudflare',\n // SQLite (`@payloadcms/db-sqlite`)\n 'better-sqlite3',\n 'libsql',\n // Mongo (`@payloadcms/db-mongodb`)\n 'mongodb',\n 'mongoose',\n]\n\n/**\n * Entries of {@link ssrExternalPackages} that must bundle in the production build.\n *\n * Externalizing only works for specifiers resolvable from the project root. These\n * are leaf deps of Payload packages, so under pnpm they live in `.pnpm/…` and a bare\n * specifier in a root-resolved chunk is invisible — `ERR_MODULE_NOT_FOUND` at\n * runtime, or a build-time resolve failure under Nitro's re-bundle pass.\n *\n * `pluralize` also needs forcing back via `noExternal` (see `withPayload`); the\n * storage leaves don't, since their adapters are already `noExternal`.\n */\nexport const buildBundledPackages: string[] = [\n 'pluralize',\n // Leaf deps of the `@payloadcms/storage-*` adapters.\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@azure/storage-blob',\n '@google-cloud/storage',\n]\n\n/**\n * External packages for the production `vite build` only (not dev serve).\n *\n * Externalizes the `@payloadcms/*` package boundaries — plus `payload` — so each\n * resolves its own transitive Node deps (`pino`, `drizzle-orm`, `libsql`, …) from\n * its own `node_modules` at runtime. Externalizing only the leaf deps breaks under\n * pnpm: a leaf imported by bundled code becomes an unresolvable bare specifier from\n * `dist/`, since pnpm does not hoist it; see {@link buildBundledPackages}.\n *\n * Kept out of dev's `ssr.external` on purpose: the monorepo resolves these to\n * TypeScript source (`.ts` imported via `.js` specifiers), which only Vite's\n * transform can resolve — an externalized copy would hit Node's raw resolver and\n * fail on the `.js`→`.ts` mismatch.\n */\nexport const buildExternalPackages: string[] = [\n 'payload',\n 'payload/node',\n '@payloadcms/drizzle',\n '@payloadcms/db-mongodb',\n '@payloadcms/db-postgres',\n '@payloadcms/db-vercel-postgres',\n '@payloadcms/db-sqlite',\n '@payloadcms/db-d1-sqlite',\n ...ssrExternalPackages.filter((pkg) => !buildBundledPackages.includes(pkg)),\n]\n\nexport const payloadNoExternalPatterns: Array<RegExp | string> = [\n '@payloadcms/ui',\n '@payloadcms/translations',\n '@payloadcms/tanstack-start',\n /^@payloadcms\\/richtext-lexical/,\n /^@payloadcms\\/plugin-/,\n /^@payloadcms\\/storage-/,\n]\n"],"names":["ssrExternalPackages","buildBundledPackages","buildExternalPackages","filter","pkg","includes","payloadNoExternalPatterns"],"mappings":"AAAA;;;CAGC,GAED;;;;;;;;;CASC,GACD,OAAO,MAAMA,sBAAgC;IAC3C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,8EAA8E;IAC9E,yEAAyE;IACzE;IACA;IACA;IACA,mCAAmC;IACnC;IACA;IACA,mCAAmC;IACnC;IACA;CACD,CAAA;AAED;;;;;;;;;;CAUC,GACD,OAAO,MAAMC,uBAAiC;IAC5C;IACA,qDAAqD;IACrD;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,wBAAkC;IAC7C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;OACGF,oBAAoBG,MAAM,CAAC,CAACC,MAAQ,CAACH,qBAAqBI,QAAQ,CAACD;CACvE,CAAA;AAED,OAAO,MAAME,4BAAoD;IAC/D;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimizeDeps.d.ts","sourceRoot":"","sources":["../../../src/withPayload/config/optimizeDeps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"optimizeDeps.d.ts","sourceRoot":"","sources":["../../../src/withPayload/config/optimizeDeps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAyB/C,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EA+E/C,CAAA"}
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
// server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev
|
|
26
26
|
// server with a `MISSING_EXPORT` error before any test runs.
|
|
27
27
|
'@azure/storage-blob',
|
|
28
|
+
// Preserve RSC client boundaries on storage admin upload handlers.
|
|
29
|
+
'@payloadcms/storage-azure',
|
|
30
|
+
'@payloadcms/storage-vercel-blob',
|
|
28
31
|
'@aws-sdk/client-s3',
|
|
29
32
|
'@aws-sdk/s3-request-presigner',
|
|
30
33
|
'@google-cloud/storage'
|
|
@@ -113,11 +116,12 @@
|
|
|
113
116
|
'payload > path-to-regexp',
|
|
114
117
|
'payload > console-table-printer',
|
|
115
118
|
'payload > ci-info',
|
|
116
|
-
'payload > image-
|
|
117
|
-
'payload > image-size/fromFile',
|
|
119
|
+
'payload > image-dimensions',
|
|
118
120
|
'payload > ipaddr.js',
|
|
119
121
|
'payload > range-parser',
|
|
120
|
-
'payload > sanitize-filename'
|
|
122
|
+
'payload > sanitize-filename',
|
|
123
|
+
// `@azure/storage-blob` is excluded, so pre-bundle its CommonJS browser dependency explicitly.
|
|
124
|
+
'@azure/storage-blob > events'
|
|
121
125
|
];
|
|
122
126
|
|
|
123
127
|
//# sourceMappingURL=optimizeDeps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/withPayload/config/optimizeDeps.ts"],"sourcesContent":["/**\n * Client dep-optimizer config used by `withPayload`. Kept separate from the\n * SSR/RSC externalization config (`./external.ts`) so each concern stays small.\n */\n\n/**\n * Packages we know contain Node-only code or top-level side effects requiring\n * Node APIs. Excluding them from the client optimizer prevents Vite from\n * walking into their main entries and trying to bundle server-only imports\n * for the browser.\n */\nexport const optimizeDepsExcludeDefaults: string[] = [\n 'sharp',\n '@payloadcms/ui',\n '@payloadcms/tanstack-start',\n 'payload',\n 'pino',\n 'pino-pretty',\n 'busboy',\n 'get-tsconfig',\n 'ws',\n 'croner',\n 'prompts',\n 'file-type',\n // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite\n // sometimes walks these from the main package entry while scanning\n // workspace deps, and the browser sub-bundles do not expose the\n // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev\n // server with a `MISSING_EXPORT` error before any test runs.\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be\n * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick\n * these up because their parent packages are in `optimizeDeps.exclude`, so we\n * list them explicitly using the `parent > child` syntax.\n *\n * Each entry below fixes a specific late-discovery re-optimization: without it,\n * Vite discovers the dep *after* its initial crawl, forcing a full dep\n * re-optimization mid-session that 404s in-flight `.vite/deps/*` chunks and\n * remounts the admin (dropping client state). This is why the list can't simply\n * be deleted — it is the \"complete first pass\" for the admin's dep graph.\n */\nexport const optimizeDepsIncludeDefaults: string[] = [\n '@payloadcms/ui > sonner',\n '@payloadcms/ui > @faceless-ui/modal',\n '@payloadcms/ui > @faceless-ui/window-info',\n '@payloadcms/ui > @faceless-ui/scroll-info',\n '@payloadcms/ui > @dnd-kit/core',\n '@payloadcms/ui > @dnd-kit/sortable',\n '@payloadcms/ui > @dnd-kit/utilities',\n '@payloadcms/ui > react-datepicker',\n '@payloadcms/ui > react-select',\n '@payloadcms/ui > react-select/creatable',\n '@payloadcms/ui > react-image-crop',\n '@payloadcms/ui > @monaco-editor/react',\n '@payloadcms/ui > date-fns',\n '@payloadcms/ui > date-fns/transpose',\n '@payloadcms/ui > @date-fns/tz/date/mini',\n '@payloadcms/ui > uuid',\n '@payloadcms/ui > use-context-selector',\n '@payloadcms/ui > bson-objectid',\n '@payloadcms/ui > dequal',\n '@payloadcms/ui > object-to-formdata',\n '@payloadcms/ui > md5',\n 'payload > deepmerge',\n 'payload > pluralize',\n // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of\n // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated\n // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where\n // it isn't hoisted to the top level. Path it through `react-dom` so the\n // optimizer resolves the exact copy the runtime loads.\n 'react-dom > scheduler',\n // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the\n // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.\n // Because its parent is excluded, the optimizer never crawls in to discover\n // this entry, so Vite serves `react/compiler-runtime` raw. That file is\n // CommonJS (`module.exports = require(...)`), so the named `c` export can't be\n // statically extracted and every client component throws \"does not provide an\n // export named 'c'\". Pre-bundling it lets esbuild synthesize the named export.\n 'react/compiler-runtime',\n // Transitive deps that Vite otherwise discovers *after* the initial crawl\n // (react-select pulls in @floating-ui at runtime; react-is is reached via\n // react-transition-group/prop-types; the default date-fns locale is loaded\n // through a dynamic `date-fns/locale/${key}` import). A late discovery forces\n // a full dep re-optimization mid-session, which 404s every in-flight\n // `.vite/deps/*` chunk (\"Pre-transform error: file does not exist in the\n // optimize deps directory\") and breaks the admin UI in CI cold starts.\n // Pre-bundling them keeps the first optimization pass complete.\n '@payloadcms/ui > react-select > @floating-ui/dom',\n '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',\n '@payloadcms/ui > react-select > prop-types > react-is',\n '@payloadcms/ui > date-fns/locale/en-US',\n // Further late discoveries observed re-optimizing mid-run in CI cold starts\n // (see CI logs: \"✨ new dependencies optimized: @dnd-kit/modifiers / ajv /\n // dequal/lite\"). The modular dashboard pulls in `@dnd-kit/modifiers` on first\n // render; form-state diffing reaches `dequal/lite` (a distinct entry point\n // from the already-listed `dequal`); client-side field validation reaches\n // `ajv` *through `payload`* — it is `ssrExternal` server-side but still\n // bundled into the client, and must be pathed via `payload` so the optimizer\n // pre-bundles the exact copy the runtime loads.\n '@payloadcms/ui > @dnd-kit/modifiers',\n '@payloadcms/ui > dequal/lite',\n 'payload > ajv',\n // The storage client-upload suites (esp. vercel-blob) crawl part of the\n // `payload` server runtime into the client bundle and discover these late,\n // triggering several \"optimized dependencies changed. reloading\" waves that\n // reload the page mid-test (the bulk-upload drawer's Create New button /\n // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the\n // whole observed set so the first pass is complete.\n 'payload > undici',\n 'payload > jose',\n 'payload > dataloader',\n 'payload > path-to-regexp',\n 'payload > console-table-printer',\n 'payload > ci-info',\n 'payload > image-
|
|
1
|
+
{"version":3,"sources":["../../../src/withPayload/config/optimizeDeps.ts"],"sourcesContent":["/**\n * Client dep-optimizer config used by `withPayload`. Kept separate from the\n * SSR/RSC externalization config (`./external.ts`) so each concern stays small.\n */\n\n/**\n * Packages we know contain Node-only code or top-level side effects requiring\n * Node APIs. Excluding them from the client optimizer prevents Vite from\n * walking into their main entries and trying to bundle server-only imports\n * for the browser.\n */\nexport const optimizeDepsExcludeDefaults: string[] = [\n 'sharp',\n '@payloadcms/ui',\n '@payloadcms/tanstack-start',\n 'payload',\n 'pino',\n 'pino-pretty',\n 'busboy',\n 'get-tsconfig',\n 'ws',\n 'croner',\n 'prompts',\n 'file-type',\n // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite\n // sometimes walks these from the main package entry while scanning\n // workspace deps, and the browser sub-bundles do not expose the\n // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev\n // server with a `MISSING_EXPORT` error before any test runs.\n '@azure/storage-blob',\n // Preserve RSC client boundaries on storage admin upload handlers.\n '@payloadcms/storage-azure',\n '@payloadcms/storage-vercel-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be\n * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick\n * these up because their parent packages are in `optimizeDeps.exclude`, so we\n * list them explicitly using the `parent > child` syntax.\n *\n * Each entry below fixes a specific late-discovery re-optimization: without it,\n * Vite discovers the dep *after* its initial crawl, forcing a full dep\n * re-optimization mid-session that 404s in-flight `.vite/deps/*` chunks and\n * remounts the admin (dropping client state). This is why the list can't simply\n * be deleted — it is the \"complete first pass\" for the admin's dep graph.\n */\nexport const optimizeDepsIncludeDefaults: string[] = [\n '@payloadcms/ui > sonner',\n '@payloadcms/ui > @faceless-ui/modal',\n '@payloadcms/ui > @faceless-ui/window-info',\n '@payloadcms/ui > @faceless-ui/scroll-info',\n '@payloadcms/ui > @dnd-kit/core',\n '@payloadcms/ui > @dnd-kit/sortable',\n '@payloadcms/ui > @dnd-kit/utilities',\n '@payloadcms/ui > react-datepicker',\n '@payloadcms/ui > react-select',\n '@payloadcms/ui > react-select/creatable',\n '@payloadcms/ui > react-image-crop',\n '@payloadcms/ui > @monaco-editor/react',\n '@payloadcms/ui > date-fns',\n '@payloadcms/ui > date-fns/transpose',\n '@payloadcms/ui > @date-fns/tz/date/mini',\n '@payloadcms/ui > uuid',\n '@payloadcms/ui > use-context-selector',\n '@payloadcms/ui > bson-objectid',\n '@payloadcms/ui > dequal',\n '@payloadcms/ui > object-to-formdata',\n '@payloadcms/ui > md5',\n 'payload > deepmerge',\n 'payload > pluralize',\n // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of\n // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated\n // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where\n // it isn't hoisted to the top level. Path it through `react-dom` so the\n // optimizer resolves the exact copy the runtime loads.\n 'react-dom > scheduler',\n // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the\n // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.\n // Because its parent is excluded, the optimizer never crawls in to discover\n // this entry, so Vite serves `react/compiler-runtime` raw. That file is\n // CommonJS (`module.exports = require(...)`), so the named `c` export can't be\n // statically extracted and every client component throws \"does not provide an\n // export named 'c'\". Pre-bundling it lets esbuild synthesize the named export.\n 'react/compiler-runtime',\n // Transitive deps that Vite otherwise discovers *after* the initial crawl\n // (react-select pulls in @floating-ui at runtime; react-is is reached via\n // react-transition-group/prop-types; the default date-fns locale is loaded\n // through a dynamic `date-fns/locale/${key}` import). A late discovery forces\n // a full dep re-optimization mid-session, which 404s every in-flight\n // `.vite/deps/*` chunk (\"Pre-transform error: file does not exist in the\n // optimize deps directory\") and breaks the admin UI in CI cold starts.\n // Pre-bundling them keeps the first optimization pass complete.\n '@payloadcms/ui > react-select > @floating-ui/dom',\n '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',\n '@payloadcms/ui > react-select > prop-types > react-is',\n '@payloadcms/ui > date-fns/locale/en-US',\n // Further late discoveries observed re-optimizing mid-run in CI cold starts\n // (see CI logs: \"✨ new dependencies optimized: @dnd-kit/modifiers / ajv /\n // dequal/lite\"). The modular dashboard pulls in `@dnd-kit/modifiers` on first\n // render; form-state diffing reaches `dequal/lite` (a distinct entry point\n // from the already-listed `dequal`); client-side field validation reaches\n // `ajv` *through `payload`* — it is `ssrExternal` server-side but still\n // bundled into the client, and must be pathed via `payload` so the optimizer\n // pre-bundles the exact copy the runtime loads.\n '@payloadcms/ui > @dnd-kit/modifiers',\n '@payloadcms/ui > dequal/lite',\n 'payload > ajv',\n // The storage client-upload suites (esp. vercel-blob) crawl part of the\n // `payload` server runtime into the client bundle and discover these late,\n // triggering several \"optimized dependencies changed. reloading\" waves that\n // reload the page mid-test (the bulk-upload drawer's Create New button /\n // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the\n // whole observed set so the first pass is complete.\n 'payload > undici',\n 'payload > jose',\n 'payload > dataloader',\n 'payload > path-to-regexp',\n 'payload > console-table-printer',\n 'payload > ci-info',\n 'payload > image-dimensions',\n 'payload > ipaddr.js',\n 'payload > range-parser',\n 'payload > sanitize-filename',\n // `@azure/storage-blob` is excluded, so pre-bundle its CommonJS browser dependency explicitly.\n '@azure/storage-blob > events',\n]\n"],"names":["optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults"],"mappings":"AAAA;;;CAGC,GAED;;;;;CAKC,GACD,OAAO,MAAMA,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kEAAkE;IAClE,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,6DAA6D;IAC7D;IACA,mEAAmE;IACnE;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,6EAA6E;IAC7E,+EAA+E;IAC/E,8EAA8E;IAC9E,wEAAwE;IACxE,uDAAuD;IACvD;IACA,8EAA8E;IAC9E,0EAA0E;IAC1E,4EAA4E;IAC5E,wEAAwE;IACxE,+EAA+E;IAC/E,8EAA8E;IAC9E,+EAA+E;IAC/E;IACA,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,qEAAqE;IACrE,yEAAyE;IACzE,uEAAuE;IACvE,gEAAgE;IAChE;IACA;IACA;IACA;IACA,4EAA4E;IAC5E,0EAA0E;IAC1E,8EAA8E;IAC9E,2EAA2E;IAC3E,0EAA0E;IAC1E,wEAAwE;IACxE,6EAA6E;IAC7E,gDAAgD;IAChD;IACA;IACA;IACA,wEAAwE;IACxE,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,oDAAoD;IACpD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,+FAA+F;IAC/F;CACD,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Reloads Payload when `payload.config.ts`, or anything it imports, changes.
|
|
4
|
+
*
|
|
5
|
+
* Vite re-evaluates the config module on its own, but `getPayload` keeps
|
|
6
|
+
* serving its cached instance until a `DevReloadStrategy` marks it stale. This
|
|
7
|
+
* plugin only broadcasts the change; `devConfigReload.server.ts` subscribes
|
|
8
|
+
* from inside the server runtime and marks the instance, which `getPayload`
|
|
9
|
+
* then reloads on its next call.
|
|
10
|
+
*/
|
|
11
|
+
export declare function payloadDevConfigReload({ payloadConfigPath, }: {
|
|
12
|
+
payloadConfigPath: string;
|
|
13
|
+
}): PluginOption;
|
|
14
|
+
//# sourceMappingURL=devConfigReload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devConfigReload.d.ts","sourceRoot":"","sources":["../../src/withPayload/devConfigReload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,YAAY,EAAiB,MAAM,MAAM,CAAA;AAO9E;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,iBAAiB,GAClB,EAAE;IACD,iBAAiB,EAAE,MAAM,CAAA;CAC1B,GAAG,YAAY,CA+Cf"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizePath } from 'vite';
|
|
3
|
+
import { PAYLOAD_CONFIG_CHANGED_EVENT } from '../utilities/devConfigReloadEvent.js';
|
|
4
|
+
/**
|
|
5
|
+
* Reloads Payload when `payload.config.ts`, or anything it imports, changes.
|
|
6
|
+
*
|
|
7
|
+
* Vite re-evaluates the config module on its own, but `getPayload` keeps
|
|
8
|
+
* serving its cached instance until a `DevReloadStrategy` marks it stale. This
|
|
9
|
+
* plugin only broadcasts the change; `devConfigReload.server.ts` subscribes
|
|
10
|
+
* from inside the server runtime and marks the instance, which `getPayload`
|
|
11
|
+
* then reloads on its next call.
|
|
12
|
+
*/ export function payloadDevConfigReload({ payloadConfigPath }) {
|
|
13
|
+
const configFile = normalizePath(path.resolve(payloadConfigPath));
|
|
14
|
+
let server;
|
|
15
|
+
// Vite runs `hotUpdate` once per environment (client, ssr, rsc) per change,
|
|
16
|
+
// sharing one timestamp; without this the notice prints three times.
|
|
17
|
+
let lastHandled = '';
|
|
18
|
+
return {
|
|
19
|
+
name: 'payload:dev-config-reload',
|
|
20
|
+
apply: 'serve',
|
|
21
|
+
configureServer (devServer) {
|
|
22
|
+
server = devServer;
|
|
23
|
+
},
|
|
24
|
+
hotUpdate ({ file, modules, timestamp }) {
|
|
25
|
+
if (!server) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const changeKey = `${file}:${timestamp}`;
|
|
29
|
+
if (changeKey === lastHandled) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!affectsPayloadConfig({
|
|
33
|
+
configFile,
|
|
34
|
+
file,
|
|
35
|
+
modules
|
|
36
|
+
})) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
lastHandled = changeKey;
|
|
40
|
+
server.config.logger.info(`payload config changed, reloading Payload (${path.basename(file)})`, {
|
|
41
|
+
timestamp: true
|
|
42
|
+
});
|
|
43
|
+
// Broadcast to every environment rather than just `this.environment`: the
|
|
44
|
+
// changed module may only be in the graph of the environment that saw it,
|
|
45
|
+
// while the Payload instance was built in another. Each environment's
|
|
46
|
+
// runtime subscribes with its own copy of `payload`, and environments with
|
|
47
|
+
// no subscriber (e.g. `client`) simply ignore the event.
|
|
48
|
+
for (const environment of Object.values(server.environments)){
|
|
49
|
+
environment.hot.send({
|
|
50
|
+
type: 'custom',
|
|
51
|
+
event: PAYLOAD_CONFIG_CHANGED_EVENT
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether `file` is the Payload config or something it imports. Walks *up*
|
|
59
|
+
* through importers, since the config sits at the root of that subtree.
|
|
60
|
+
*/ function affectsPayloadConfig({ configFile, file, modules }) {
|
|
61
|
+
if (normalizePath(file) === configFile) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const queue = [
|
|
66
|
+
...modules
|
|
67
|
+
];
|
|
68
|
+
while(queue.length > 0){
|
|
69
|
+
const mod = queue.pop();
|
|
70
|
+
if (seen.has(mod)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
seen.add(mod);
|
|
74
|
+
if (mod.file && normalizePath(mod.file) === configFile) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
for (const importer of mod.importers){
|
|
78
|
+
queue.push(importer);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=devConfigReload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/withPayload/devConfigReload.ts"],"sourcesContent":["import type { EnvironmentModuleNode, PluginOption, ViteDevServer } from 'vite'\n\nimport path from 'node:path'\nimport { normalizePath } from 'vite'\n\nimport { PAYLOAD_CONFIG_CHANGED_EVENT } from '../utilities/devConfigReloadEvent.js'\n\n/**\n * Reloads Payload when `payload.config.ts`, or anything it imports, changes.\n *\n * Vite re-evaluates the config module on its own, but `getPayload` keeps\n * serving its cached instance until a `DevReloadStrategy` marks it stale. This\n * plugin only broadcasts the change; `devConfigReload.server.ts` subscribes\n * from inside the server runtime and marks the instance, which `getPayload`\n * then reloads on its next call.\n */\nexport function payloadDevConfigReload({\n payloadConfigPath,\n}: {\n payloadConfigPath: string\n}): PluginOption {\n const configFile = normalizePath(path.resolve(payloadConfigPath))\n\n let server: undefined | ViteDevServer\n\n // Vite runs `hotUpdate` once per environment (client, ssr, rsc) per change,\n // sharing one timestamp; without this the notice prints three times.\n let lastHandled = ''\n\n return {\n name: 'payload:dev-config-reload',\n apply: 'serve',\n configureServer(devServer) {\n server = devServer\n },\n hotUpdate({ file, modules, timestamp }) {\n if (!server) {\n return\n }\n\n const changeKey = `${file}:${timestamp}`\n\n if (changeKey === lastHandled) {\n return\n }\n\n if (!affectsPayloadConfig({ configFile, file, modules })) {\n return\n }\n\n lastHandled = changeKey\n\n server.config.logger.info(\n `payload config changed, reloading Payload (${path.basename(file)})`,\n { timestamp: true },\n )\n\n // Broadcast to every environment rather than just `this.environment`: the\n // changed module may only be in the graph of the environment that saw it,\n // while the Payload instance was built in another. Each environment's\n // runtime subscribes with its own copy of `payload`, and environments with\n // no subscriber (e.g. `client`) simply ignore the event.\n for (const environment of Object.values(server.environments)) {\n environment.hot.send({ type: 'custom', event: PAYLOAD_CONFIG_CHANGED_EVENT })\n }\n },\n }\n}\n\n/**\n * Whether `file` is the Payload config or something it imports. Walks *up*\n * through importers, since the config sits at the root of that subtree.\n */\nfunction affectsPayloadConfig({\n configFile,\n file,\n modules,\n}: {\n configFile: string\n file: string\n modules: EnvironmentModuleNode[]\n}): boolean {\n if (normalizePath(file) === configFile) {\n return true\n }\n\n const seen = new Set<EnvironmentModuleNode>()\n const queue = [...modules]\n\n while (queue.length > 0) {\n const mod = queue.pop()!\n\n if (seen.has(mod)) {\n continue\n }\n seen.add(mod)\n\n if (mod.file && normalizePath(mod.file) === configFile) {\n return true\n }\n\n for (const importer of mod.importers) {\n queue.push(importer)\n }\n }\n\n return false\n}\n"],"names":["path","normalizePath","PAYLOAD_CONFIG_CHANGED_EVENT","payloadDevConfigReload","payloadConfigPath","configFile","resolve","server","lastHandled","name","apply","configureServer","devServer","hotUpdate","file","modules","timestamp","changeKey","affectsPayloadConfig","config","logger","info","basename","environment","Object","values","environments","hot","send","type","event","seen","Set","queue","length","mod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;IAE1B,MAAOkB,MAAMC,MAAM,GAAG,EAAG;QACvB,MAAMC,MAAMF,MAAMG,GAAG;QAErB,IAAIL,KAAKM,GAAG,CAACF,MAAM;YACjB;QACF;QACAJ,KAAKO,GAAG,CAACH;QAET,IAAIA,IAAIrB,IAAI,IAAIb,cAAckC,IAAIrB,IAAI,MAAMT,YAAY;YACtD,OAAO;QACT;QAEA,KAAK,MAAMkC,YAAYJ,IAAIK,SAAS,CAAE;YACpCP,MAAMQ,IAAI,CAACF;QACb;IACF;IAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importProtection.d.ts","sourceRoot":"","sources":["../../src/withPayload/importProtection.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAoB7D,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"importProtection.d.ts","sourceRoot":"","sources":["../../src/withPayload/importProtection.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAoB7D,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAmC9E;AAED,eAAO,MAAM,sCAAsC,EAAE,MAAM,EAAsC,CAAA"}
|