@payloadcms/tanstack-start 4.0.0-internal.add4c47 → 4.0.0-internal.b6f3b9a
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 +16 -3
- package/dist/elements/RouterAdapter/index.js.map +1 -1
- package/dist/exports/client.d.ts +0 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +0 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/layouts.d.ts +1 -3
- 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 +0 -1
- 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 +6 -4
- package/dist/routes/adminRoutes.d.ts.map +1 -1
- package/dist/routes/adminRoutes.js +47 -42
- package/dist/routes/adminRoutes.js.map +1 -1
- 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/getRequestLocale.d.ts.map +1 -1
- package/dist/utilities/getRequestLocale.js +1 -2
- package/dist/utilities/getRequestLocale.js.map +1 -1
- package/dist/utilities/loadAdminPage.d.ts.map +1 -1
- package/dist/utilities/loadAdminPage.js +3 -11
- package/dist/utilities/loadAdminPage.js.map +1 -1
- 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/workarounds/stripDistStyleImports.js +1 -1
- package/dist/withPayload/workarounds/stripDistStyleImports.js.map +1 -1
- package/package.json +5 -5
- 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/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,6 +1,7 @@
|
|
|
1
1
|
import { getNavPrefs } from '@payloadcms/ui/elements/Nav/getNavPrefs';
|
|
2
2
|
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
|
|
3
3
|
import { getClientConfig } from '@payloadcms/ui/utilities/getClientConfig';
|
|
4
|
+
import { getRequestEmbed } from '@payloadcms/ui/utilities/getRequestEmbed';
|
|
4
5
|
import { getRequestTheme } from '@payloadcms/ui/utilities/getRequestTheme';
|
|
5
6
|
import { Outlet } from '@tanstack/react-router';
|
|
6
7
|
import { applyLocaleFiltering } from 'payload/shared';
|
|
@@ -19,6 +20,10 @@ import { initReq } from '../../utilities/initReq.server.js';
|
|
|
19
20
|
cookies,
|
|
20
21
|
headers
|
|
21
22
|
});
|
|
23
|
+
const isEmbedded = getRequestEmbed({
|
|
24
|
+
config,
|
|
25
|
+
cookies
|
|
26
|
+
});
|
|
22
27
|
const languageOptions = Object.entries(config.i18n.supportedLanguages || {}).reduce((acc, [language, languageConfig])=>{
|
|
23
28
|
if (Object.keys(config.i18n.supportedLanguages).includes(language)) {
|
|
24
29
|
acc.push({
|
|
@@ -76,6 +81,7 @@ import { initReq } from '../../utilities/initReq.server.js';
|
|
|
76
81
|
clientConfig,
|
|
77
82
|
dateFNSKey: req.i18n.dateFNSKey,
|
|
78
83
|
fallbackLang: config.i18n.fallbackLanguage,
|
|
84
|
+
isEmbedded,
|
|
79
85
|
isNavOpen: navPrefs?.open ?? true,
|
|
80
86
|
languageCode,
|
|
81
87
|
languageOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/layouts/Root/getLayoutData.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { ImportMap
|
|
1
|
+
{"version":3,"sources":["../../../src/layouts/Root/getLayoutData.ts"],"sourcesContent":["import type { AcceptedLanguages, I18nClient } from '@payloadcms/translations'\nimport type { Theme } from '@payloadcms/ui'\nimport type {\n ClientConfig,\n ImportMap,\n LanguageOptions,\n SanitizedConfig,\n SanitizedPermissions,\n ServerProps,\n User,\n} from 'payload'\n\nimport { getNavPrefs } from '@payloadcms/ui/elements/Nav/getNavPrefs'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { getClientConfig } from '@payloadcms/ui/utilities/getClientConfig'\nimport { getRequestEmbed } from '@payloadcms/ui/utilities/getRequestEmbed'\nimport { getRequestTheme } from '@payloadcms/ui/utilities/getRequestTheme'\nimport { Outlet } from '@tanstack/react-router'\nimport { applyLocaleFiltering } from 'payload/shared'\nimport { createElement } from 'react'\n\nimport { initReq } from '../../utilities/initReq.server.js'\n\nexport type RootLayoutData = {\n clientConfig: ClientConfig\n dateFNSKey: I18nClient['dateFNSKey']\n fallbackLang: string\n isEmbedded: boolean\n isNavOpen: boolean\n languageCode: string\n languageOptions: LanguageOptions\n locale?: string\n permissions: SanitizedPermissions\n /**\n * Custom admin provider tree (`config.admin.components.providers`) nested\n * around the router `<Outlet />`. Built unrendered by `getLayoutData`; the\n * layout server function renders it to an RSC payload before it reaches the\n * client. `undefined` when no custom providers are configured.\n */\n providers?: React.ReactNode\n theme: Theme\n translations: I18nClient['translations']\n user: null | User\n}\n\nexport type GetLayoutDataArgs = {\n configPromise: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n}\n\n/**\n * Fetches all data needed by the root admin layout.\n * Call this in your TanStack Start root route loader.\n */\nexport async function getLayoutData({\n configPromise,\n importMap,\n}: GetLayoutDataArgs): Promise<RootLayoutData> {\n const {\n cookies,\n headers,\n languageCode,\n permissions,\n req,\n req: {\n payload: { config },\n },\n } = await initReq({ configPromise, importMap })\n\n const theme = getRequestTheme({ config, cookies, headers })\n const isEmbedded = getRequestEmbed({ config, cookies })\n\n const languageOptions: LanguageOptions = Object.entries(\n config.i18n.supportedLanguages || {},\n ).reduce((acc, [language, languageConfig]) => {\n if (Object.keys(config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language as AcceptedLanguages,\n })\n }\n return acc\n }, [] as LanguageOptions)\n\n const navPrefs = await getNavPrefs(req)\n\n const clientConfig = getClientConfig({\n config,\n i18n: req.i18n,\n importMap,\n user: req.user ?? true,\n })\n\n await applyLocaleFiltering({ clientConfig, config, req })\n\n // Build the custom admin provider tree (`config.admin.components.providers`)\n // nested around the router `<Outlet />`, mirroring the Next adapter's\n // `NestProviders`. Returned as an unrendered element; the caller's server\n // function renders it to an RSC payload (so server-component providers run\n // server-side and client providers wrap the live Outlet). `undefined` when\n // no custom providers are configured — the caller falls back to `<Outlet />`.\n const providerPaths = config.admin?.components?.providers\n let providers: React.ReactNode = undefined\n if (Array.isArray(providerPaths) && providerPaths.length > 0) {\n const serverProps: ServerProps = {\n i18n: req.i18n,\n params: {},\n payload: req.payload,\n permissions,\n searchParams: {},\n server: req.server!,\n user: req.user ?? undefined,\n }\n // Mirror the Next adapter's `NestProviders`: render each configured provider\n // via `RenderServerComponent` so the entry's own `clientProps`/`serverProps`\n // (e.g. plugin-multi-tenant's `userHasAccessToAllTenants`) are merged in, and\n // server components receive `serverProps` while client components get only\n // `clientProps`. Nested around the router `<Outlet />` instead of `children`.\n providers = providerPaths.reduceRight<React.ReactNode>(\n (children, provider) =>\n RenderServerComponent({\n clientProps: { children },\n Component: provider,\n importMap,\n serverProps,\n }),\n createElement(Outlet),\n )\n }\n\n return {\n clientConfig,\n dateFNSKey: req.i18n.dateFNSKey,\n fallbackLang: config.i18n.fallbackLanguage,\n isEmbedded,\n isNavOpen: navPrefs?.open ?? true,\n languageCode,\n languageOptions,\n locale: req.locale ?? undefined,\n permissions,\n providers,\n theme,\n translations: req.i18n.translations,\n user: req.user,\n }\n}\n"],"names":["getNavPrefs","RenderServerComponent","getClientConfig","getRequestEmbed","getRequestTheme","Outlet","applyLocaleFiltering","createElement","initReq","getLayoutData","configPromise","importMap","cookies","headers","languageCode","permissions","req","payload","config","theme","isEmbedded","languageOptions","Object","entries","i18n","supportedLanguages","reduce","acc","language","languageConfig","keys","includes","push","label","translations","general","thisLanguage","value","navPrefs","clientConfig","user","providerPaths","admin","components","providers","undefined","Array","isArray","length","serverProps","params","searchParams","server","reduceRight","children","provider","clientProps","Component","dateFNSKey","fallbackLang","fallbackLanguage","isNavOpen","open","locale"],"mappings":"AAYA,SAASA,WAAW,QAAQ,0CAAyC;AACrE,SAASC,qBAAqB,QAAQ,gDAA+C;AACrF,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,MAAM,QAAQ,yBAAwB;AAC/C,SAASC,oBAAoB,QAAQ,iBAAgB;AACrD,SAASC,aAAa,QAAQ,QAAO;AAErC,SAASC,OAAO,QAAQ,oCAAmC;AA6B3D;;;CAGC,GACD,OAAO,eAAeC,cAAc,EAClCC,aAAa,EACbC,SAAS,EACS;IAClB,MAAM,EACJC,OAAO,EACPC,OAAO,EACPC,YAAY,EACZC,WAAW,EACXC,GAAG,EACHA,KAAK,EACHC,SAAS,EAAEC,MAAM,EAAE,EACpB,EACF,GAAG,MAAMV,QAAQ;QAAEE;QAAeC;IAAU;IAE7C,MAAMQ,QAAQf,gBAAgB;QAAEc;QA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AS;gBACxBG,WAAWF;gBACX5C;gBACAsC;YACF,IACF1C,cAAcF;IAElB;IAEA,OAAO;QACLkC;QACAmB,YAAY1C,IAAIQ,IAAI,CAACkC,UAAU;QAC/BC,cAAczC,OAAOM,IAAI,CAACoC,gBAAgB;QAC1CxC;QACAyC,WAAWvB,UAAUwB,QAAQ;QAC7BhD;QACAO;QACA0C,QAAQ/C,IAAI+C,MAAM,IAAIlB;QACtB9B;QACA6B;QACAzB;QACAe,cAAclB,IAAIQ,IAAI,CAACU,YAAY;QACnCM,MAAMxB,IAAIwB,IAAI;IAChB;AACF"}
|
|
@@ -49,6 +49,7 @@ export declare function payloadAdminSplatRoute({ load }: {
|
|
|
49
49
|
title: string;
|
|
50
50
|
})[];
|
|
51
51
|
};
|
|
52
|
+
notFoundComponent: typeof AdminNotFound;
|
|
52
53
|
loader: {
|
|
53
54
|
handler: ({ location, params }: {
|
|
54
55
|
location: any;
|
|
@@ -61,12 +62,11 @@ export declare function payloadAdminSplatRoute({ load }: {
|
|
|
61
62
|
}) => {
|
|
62
63
|
searchKey: string;
|
|
63
64
|
};
|
|
64
|
-
notFoundComponent: typeof AdminNotFound;
|
|
65
65
|
validateSearch: (search: Record<string, unknown>) => Record<string, unknown>;
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* Route options for the admin index route (`/_payload/admin/`).
|
|
69
|
-
*
|
|
68
|
+
* Route options for the admin index route (`/_payload/admin/`). Not-found
|
|
69
|
+
* results omit the RSC payload and fall back to `NotFoundClient`.
|
|
70
70
|
*/
|
|
71
71
|
export declare function payloadAdminIndexRoute({ load }: {
|
|
72
72
|
load: AdminLoad;
|
|
@@ -94,9 +94,11 @@ export declare function payloadAdminIndexRoute({ load }: {
|
|
|
94
94
|
title: string;
|
|
95
95
|
})[];
|
|
96
96
|
};
|
|
97
|
+
notFoundComponent: typeof AdminNotFound;
|
|
97
98
|
loader: {
|
|
98
|
-
handler: ({ location }: {
|
|
99
|
+
handler: ({ location, params }: {
|
|
99
100
|
location: any;
|
|
101
|
+
params: any;
|
|
100
102
|
}) => Promise<any>;
|
|
101
103
|
staleReloadMode: string;
|
|
102
104
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/routes/adminRoutes.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAY,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/routes/adminRoutes.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAY,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAA;AAI7E;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE;IAC7B,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAA;KAAE,CAAA;CACpE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAclB,iBAAS,SAAS,gCAqBjB;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;CAAE,+BAMrF;AAiDD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE;;2BArC3C;QAAE,UAAU,CAAC,EAAE,GAAG,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;QAUzC,OAAO,yBAA+B;YAAE,QAAQ,EAAE,GAAG,CAAC;YAAC,MAAM,EAAE,GAAG,CAAA;SAAE;QAYpE,eAAe;;6BAGQ;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE;QAC1D,SAAS;;6BAEc,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;EAejD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE;;2BAjD3C;QAAE,UAAU,CAAC,EAAE,GAAG,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;QAUzC,OAAO,yBAA+B;YAAE,QAAQ,EAAE,GAAG,CAAC;YAAC,MAAM,EAAE,GAAG,CAAA;SAAE;QAYpE,eAAe;;6BAGQ;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE;QAC1D,SAAS;;6BAEc,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;EA2BjD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { NotFoundClient } from '@payloadcms/ui';
|
|
3
|
+
import { NotFoundClient, useRouteTransition } from '@payloadcms/ui';
|
|
4
4
|
import { notFound, redirect, useLoaderData } from '@tanstack/react-router';
|
|
5
|
-
import { Fragment } from 'react';
|
|
5
|
+
import { Fragment, useDeferredValue, useEffect } from 'react';
|
|
6
6
|
import { getAdminMeta } from '../utilities/meta.js';
|
|
7
7
|
const searchToRecord = (searchStr)=>Object.fromEntries(new URLSearchParams(searchStr));
|
|
8
8
|
const runLoader = async (load, splat, searchStr)=>{
|
|
@@ -21,17 +21,29 @@ const runLoader = async (load, splat, searchStr)=>{
|
|
|
21
21
|
return data;
|
|
22
22
|
};
|
|
23
23
|
function AdminPage() {
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
// transition and would remount with the previous payload) so navigating to a
|
|
27
|
-
// different admin page remounts the view, mirroring Next route-segment
|
|
28
|
-
// semantics. Search params are excluded so search-only changes reconcile in place.
|
|
24
|
+
// Note: React key intentionally omitted here so the persistent template (nav, header) doesn't remount and flash on navigation.
|
|
25
|
+
// The per-route view key is attached server-side to the view subtree instead, via `renderRoot`'s `key` in `loadAdminPage`.
|
|
29
26
|
const data = useLoaderData({
|
|
30
27
|
strict: false
|
|
31
28
|
});
|
|
29
|
+
// Route state comes from an external store, so a new RSC payload that suspends
|
|
30
|
+
// on code-split client references can reveal the router's null fallback.
|
|
31
|
+
// Keep the current payload painted until the next one is renderable.
|
|
32
|
+
const rscPayload = useDeferredValue(data?.rscPayload);
|
|
33
|
+
const { beginRouteTransition } = useRouteTransition();
|
|
34
|
+
const isRscPayloadDeferred = rscPayload !== data?.rscPayload;
|
|
35
|
+
useEffect(()=>{
|
|
36
|
+
if (!isRscPayloadDeferred) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return beginRouteTransition();
|
|
40
|
+
}, [
|
|
41
|
+
beginRouteTransition,
|
|
42
|
+
isRscPayloadDeferred
|
|
43
|
+
]);
|
|
32
44
|
return /*#__PURE__*/ _jsx(Fragment, {
|
|
33
|
-
children:
|
|
34
|
-
}
|
|
45
|
+
children: rscPayload
|
|
46
|
+
});
|
|
35
47
|
}
|
|
36
48
|
function AdminNotFound(props) {
|
|
37
49
|
const rscPayload = props?.data?.rscPayload;
|
|
@@ -42,15 +54,12 @@ function AdminNotFound(props) {
|
|
|
42
54
|
children: rscPayload
|
|
43
55
|
}, props?.data?.routeKey);
|
|
44
56
|
}
|
|
45
|
-
|
|
46
|
-
* Route options for the admin splat route (`/_payload/admin/$`). Renders Payload's
|
|
47
|
-
* server-built NotFound page (shipped via the `notFound()` error's
|
|
48
|
-
* `data.rscPayload`) for unknown/access-denied routes, falling back to the bare
|
|
49
|
-
* client view.
|
|
50
|
-
*/ export function payloadAdminSplatRoute({ load }) {
|
|
51
|
-
return {
|
|
57
|
+
const adminRouteOptions = ({ forwardNotFoundPayload, load, resolveSplat })=>({
|
|
52
58
|
component: AdminPage,
|
|
53
59
|
head: ({ loaderData })=>getAdminMeta(loaderData?.metadata),
|
|
60
|
+
// Both admin routes must use the same boundary type so index ↔ splat
|
|
61
|
+
// navigation preserves the existing admin subtree.
|
|
62
|
+
notFoundComponent: AdminNotFound,
|
|
54
63
|
// `staleReloadMode: 'blocking'` (a property of the loader *object*, not a
|
|
55
64
|
// sibling route option — router-core only reads it off a non-function loader)
|
|
56
65
|
// makes stale-match revalidation await the fresh loader before committing,
|
|
@@ -58,15 +67,15 @@ function AdminNotFound(props) {
|
|
|
58
67
|
// (e.g. a just-created doc missing) until the reload lands.
|
|
59
68
|
loader: {
|
|
60
69
|
handler: async ({ location, params })=>{
|
|
61
|
-
const data = await runLoader(load, params
|
|
70
|
+
const data = await runLoader(load, resolveSplat(params), location.searchStr);
|
|
62
71
|
if (data?._notFound) {
|
|
63
72
|
// eslint-disable-next-line @typescript-eslint/only-throw-error -- TanStack Router requires throwing notFound objects
|
|
64
|
-
throw notFound({
|
|
73
|
+
throw notFound(forwardNotFoundPayload ? {
|
|
65
74
|
data: {
|
|
66
75
|
routeKey: data.routeKey,
|
|
67
76
|
rscPayload: data.rscPayload
|
|
68
77
|
}
|
|
69
|
-
});
|
|
78
|
+
} : undefined);
|
|
70
79
|
}
|
|
71
80
|
return data;
|
|
72
81
|
},
|
|
@@ -76,33 +85,29 @@ function AdminNotFound(props) {
|
|
|
76
85
|
loaderDeps: ({ search })=>({
|
|
77
86
|
searchKey: JSON.stringify(search)
|
|
78
87
|
}),
|
|
79
|
-
notFoundComponent: AdminNotFound,
|
|
80
88
|
validateSearch: (search)=>search
|
|
81
|
-
};
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Route options for the admin splat route (`/_payload/admin/$`). Renders Payload's
|
|
92
|
+
* server-built NotFound page (shipped via the `notFound()` error's
|
|
93
|
+
* `data.rscPayload`) for unknown/access-denied routes, falling back to the bare
|
|
94
|
+
* client view.
|
|
95
|
+
*/ export function payloadAdminSplatRoute({ load }) {
|
|
96
|
+
return adminRouteOptions({
|
|
97
|
+
forwardNotFoundPayload: true,
|
|
98
|
+
load,
|
|
99
|
+
resolveSplat: (params)=>params._splat ?? ''
|
|
100
|
+
});
|
|
82
101
|
}
|
|
83
102
|
/**
|
|
84
|
-
* Route options for the admin index route (`/_payload/admin/`).
|
|
85
|
-
*
|
|
103
|
+
* Route options for the admin index route (`/_payload/admin/`). Not-found
|
|
104
|
+
* results omit the RSC payload and fall back to `NotFoundClient`.
|
|
86
105
|
*/ export function payloadAdminIndexRoute({ load }) {
|
|
87
|
-
return {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const data = await runLoader(load, '', location.searchStr);
|
|
93
|
-
if (data?._notFound) {
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/only-throw-error -- TanStack Router requires throwing notFound objects
|
|
95
|
-
throw notFound();
|
|
96
|
-
}
|
|
97
|
-
return data;
|
|
98
|
-
},
|
|
99
|
-
staleReloadMode: 'blocking'
|
|
100
|
-
},
|
|
101
|
-
loaderDeps: ({ search })=>({
|
|
102
|
-
searchKey: JSON.stringify(search)
|
|
103
|
-
}),
|
|
104
|
-
validateSearch: (search)=>search
|
|
105
|
-
};
|
|
106
|
+
return adminRouteOptions({
|
|
107
|
+
forwardNotFoundPayload: false,
|
|
108
|
+
load,
|
|
109
|
+
resolveSplat: ()=>''
|
|
110
|
+
});
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
//# sourceMappingURL=adminRoutes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/routes/adminRoutes.tsx"],"sourcesContent":["'use client'\n\nimport { NotFoundClient } from '@payloadcms/ui'\nimport { notFound, redirect, useLoaderData } from '@tanstack/react-router'\nimport { Fragment, type ReactNode } from 'react'\n\nimport { getAdminMeta } from '../utilities/meta.js'\n\n/**\n * Loader supplied by the app — a TanStack Start `createServerFn` that delegates\n * to `loadAdminPage`. Typed loosely because the server-fn's call signature is\n * generated by the Start compiler.\n */\nexport type AdminLoad = (opts: {\n data: { _splat: string; search: Record<string, string | string[]> }\n}) => Promise<any>\n\nconst searchToRecord = (searchStr: string): Record<string, string | string[]> =>\n Object.fromEntries(new URLSearchParams(searchStr)) as Record<string, string | string[]>\n\nconst runLoader = async (load: AdminLoad, splat: string, searchStr: string) => {\n const data = await load({ data: { _splat: splat, search: searchToRecord(searchStr) } })\n if (data?._redirect) {\n // eslint-disable-next-line @typescript-eslint/only-throw-error -- TanStack Router requires throwing redirect objects\n throw redirect({ to: data._redirect })\n }\n return data\n}\n\nfunction AdminPage() {\n //
|
|
1
|
+
{"version":3,"sources":["../../src/routes/adminRoutes.tsx"],"sourcesContent":["'use client'\n\nimport { NotFoundClient, useRouteTransition } from '@payloadcms/ui'\nimport { notFound, redirect, useLoaderData } from '@tanstack/react-router'\nimport { Fragment, type ReactNode, useDeferredValue, useEffect } from 'react'\n\nimport { getAdminMeta } from '../utilities/meta.js'\n\n/**\n * Loader supplied by the app — a TanStack Start `createServerFn` that delegates\n * to `loadAdminPage`. Typed loosely because the server-fn's call signature is\n * generated by the Start compiler.\n */\nexport type AdminLoad = (opts: {\n data: { _splat: string; search: Record<string, string | string[]> }\n}) => Promise<any>\n\nconst searchToRecord = (searchStr: string): Record<string, string | string[]> =>\n Object.fromEntries(new URLSearchParams(searchStr)) as Record<string, string | string[]>\n\nconst runLoader = async (load: AdminLoad, splat: string, searchStr: string) => {\n const data = await load({ data: { _splat: splat, search: searchToRecord(searchStr) } })\n if (data?._redirect) {\n // eslint-disable-next-line @typescript-eslint/only-throw-error -- TanStack Router requires throwing redirect objects\n throw redirect({ to: data._redirect })\n }\n return data\n}\n\nfunction AdminPage() {\n // Note: React key intentionally omitted here so the persistent template (nav, header) doesn't remount and flash on navigation.\n // The per-route view key is attached server-side to the view subtree instead, via `renderRoot`'s `key` in `loadAdminPage`.\n const data = useLoaderData({ strict: false })\n\n // Route state comes from an external store, so a new RSC payload that suspends\n // on code-split client references can reveal the router's null fallback.\n // Keep the current payload painted until the next one is renderable.\n const rscPayload = useDeferredValue(data?.rscPayload)\n const { beginRouteTransition } = useRouteTransition()\n const isRscPayloadDeferred = rscPayload !== data?.rscPayload\n\n useEffect(() => {\n if (!isRscPayloadDeferred) {\n return\n }\n\n return beginRouteTransition()\n }, [beginRouteTransition, isRscPayloadDeferred])\n\n return <Fragment>{rscPayload}</Fragment>\n}\n\nfunction AdminNotFound(props: { data?: { routeKey?: string; rscPayload?: ReactNode } }) {\n const rscPayload = props?.data?.rscPayload\n if (!rscPayload) {\n return <NotFoundClient />\n }\n return <Fragment key={props?.data?.routeKey}>{rscPayload}</Fragment>\n}\n\nconst adminRouteOptions = ({\n forwardNotFoundPayload,\n load,\n resolveSplat,\n}: {\n /**\n * Ships the server-rendered NotFound tree through `notFound()`'s `data` so a\n * `notFoundComponent` can render it with the full admin chrome. Routes without\n * one throw bare.\n */\n forwardNotFoundPayload: boolean\n load: AdminLoad\n /** The route's splat, i.e. the path after `/admin/`. */\n resolveSplat: (params: any) => string\n}) => ({\n component: AdminPage,\n head: ({ loaderData }: { loaderData?: any }) => getAdminMeta(loaderData?.metadata),\n // Both admin routes must use the same boundary type so index ↔ splat\n // navigation preserves the existing admin subtree.\n notFoundComponent: AdminNotFound,\n // `staleReloadMode: 'blocking'` (a property of the loader *object*, not a\n // sibling route option — router-core only reads it off a non-function loader)\n // makes stale-match revalidation await the fresh loader before committing,\n // instead of the default background SWR that flashes the pre-navigation list\n // (e.g. a just-created doc missing) until the reload lands.\n loader: {\n handler: async ({ location, params }: { location: any; params: any }) => {\n const data = await runLoader(load, resolveSplat(params), location.searchStr)\n if (data?._notFound) {\n // eslint-disable-next-line @typescript-eslint/only-throw-error -- TanStack Router requires throwing notFound objects\n throw notFound(\n forwardNotFoundPayload\n ? { data: { routeKey: data.routeKey, rscPayload: data.rscPayload } }\n : undefined,\n )\n }\n return data\n },\n staleReloadMode: 'blocking',\n },\n // Surface query params in `loaderDeps` so `?locale=es` re-runs the loader.\n loaderDeps: ({ search }: { search: Record<string, unknown> }) => ({\n searchKey: JSON.stringify(search),\n }),\n validateSearch: (search: Record<string, unknown>) => search,\n})\n\n/**\n * Route options for the admin splat route (`/_payload/admin/$`). Renders Payload's\n * server-built NotFound page (shipped via the `notFound()` error's\n * `data.rscPayload`) for unknown/access-denied routes, falling back to the bare\n * client view.\n */\nexport function payloadAdminSplatRoute({ load }: { load: AdminLoad }) {\n return adminRouteOptions({\n forwardNotFoundPayload: true,\n load,\n resolveSplat: (params) => params._splat ?? '',\n })\n}\n\n/**\n * Route options for the admin index route (`/_payload/admin/`). Not-found\n * results omit the RSC payload and fall back to `NotFoundClient`.\n */\nexport function payloadAdminIndexRoute({ load }: { load: AdminLoad }) {\n return adminRouteOptions({\n forwardNotFoundPayload: false,\n load,\n resolveSplat: () => '',\n })\n}\n"],"names":["NotFoundClient","useRouteTransition","notFound","redirect","useLoaderData","Fragment","useDeferredValue","useEffect","getAdminMeta","searchToRecord","searchStr","Object","fromEntries","URLSearchParams","runLoader","load","splat","data","_splat","search","_redirect","to","AdminPage","strict","rscPayload","beginRouteTransition","isRscPayloadDeferred","AdminNotFound","props","routeKey","adminRouteOptions","forwardNotFoundPayload","resolveSplat","component","head","loaderData","metadata","notFoundComponent","loader","handler","location","params","_notFound","undefined","staleReloadMode","loaderDeps","searchKey","JSON","stringify","validateSearch","payloadAdminSplatRoute","payloadAdminIndexRoute"],"mappings":"AAAA;;AAEA,SAASA,cAAc,EAAEC,kBAAkB,QAAQ,iBAAgB;AACnE,SAASC,QAAQ,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,yBAAwB;AAC1E,SAASC,QAAQ,EAAkBC,gBAAgB,EAAEC,SAAS,QAAQ,QAAO;AAE7E,SAASC,YAAY,QAAQ,uBAAsB;AAWnD,MAAMC,iBAAiB,CAACC,YACtBC,OAAOC,WAAW,CAAC,IAAIC,gBAAgBH;AAEzC,MAAMI,YAAY,OAAOC,MAAiBC,OAAeN;IACvD,MAAMO,OAAO,MAAMF,KAAK;QAAEE,MAAM;YAAEC,QAAQF;YAAOG,QAAQV,eAAeC;QAAW;IAAE;IACrF,IAAIO,MAAMG,WAAW;QAC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AC;oBAAE,IACjEmB;gBAER;gBACA,OAAO1B;YACT;YACA2B,iBAAiB;QACnB;QACA,2EAA2E;QAC3EC,YAAY,CAAC,EAAE1B,MAAM,EAAuC,GAAM,CAAA;gBAChE2B,WAAWC,KAAKC,SAAS,CAAC7B;YAC5B,CAAA;QACA8B,gBAAgB,CAAC9B,SAAoCA;IACvD,CAAA;AAEA;;;;;CAKC,GACD,OAAO,SAAS+B,uBAAuB,EAAEnC,IAAI,EAAuB;IAClE,OAAOe,kBAAkB;QACvBC,wBAAwB;QACxBhB;QACAiB,cAAc,CAACS,SAAWA,OAAOvB,MAAM,IAAI;IAC7C;AACF;AAEA;;;CAGC,GACD,OAAO,SAASiC,uBAAuB,EAAEpC,IAAI,EAAuB;IAClE,OAAOe,kBAAkB;QACvBC,wBAAwB;QACxBhB;QACAiB,cAAc,IAAM;IACtB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutRoute.d.ts","sourceRoot":"","sources":["../../src/routes/layoutRoute.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAK1D;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAE/D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,cAAc,GACf,EAAE;IACD,IAAI,EAAE,UAAU,CAAA;IAChB,cAAc,EAAE,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC,gBAAgB,CAAC,CAAA;CACtE;
|
|
1
|
+
{"version":3,"file":"layoutRoute.d.ts","sourceRoot":"","sources":["../../src/routes/layoutRoute.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAK1D;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAE/D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,cAAc,GACf,EAAE;IACD,IAAI,EAAE,UAAU,CAAA;IAChB,cAAc,EAAE,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC,gBAAgB,CAAC,CAAA;CACtE;IAsCG,SAAS;IACT,MAAM;QAAI,OAAO;QAAgB,eAAe;;EAEnD"}
|
|
@@ -19,6 +19,7 @@ import { TanStackRouterAdapter } from '../elements/RouterAdapter/index.js';
|
|
|
19
19
|
/*#__PURE__*/ _jsxs(RootProvider, {
|
|
20
20
|
config: data.clientConfig,
|
|
21
21
|
dateFNSKey: data.dateFNSKey,
|
|
22
|
+
embed: data.isEmbedded,
|
|
22
23
|
fallbackLang: data.fallbackLang,
|
|
23
24
|
highContrastMode: false,
|
|
24
25
|
isNavOpen: data.isNavOpen,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/routes/layoutRoute.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentProps } from 'react'\n\nimport { ProgressBar, RootProvider } from '@payloadcms/ui'\nimport { Outlet, useLoaderData } from '@tanstack/react-router'\n\nimport { TanStackRouterAdapter } from '../elements/RouterAdapter/index.js'\n\n/**\n * Loader supplied by the app — a TanStack Start `createServerFn` that delegates\n * to `loadLayoutData`. Typed loosely because the server-fn's call signature is\n * generated by the Start compiler.\n */\nexport type LayoutLoad = () => Promise<Record<string, unknown>>\n\n/**\n * Route options for the Payload admin layout (`/_payload`). Maps the layout\n * loader data onto `RootProvider` and renders the admin chrome (progress bar,\n * custom-provider tree or router `<Outlet />`, portal mount). The app supplies\n * `load` (the layout-data server fn) and `serverFunction` (the server-function\n * client wired into `RootProvider`); everything else is adapter-owned.\n */\nexport function payloadLayoutRoute({\n load,\n serverFunction,\n}: {\n load: LayoutLoad\n serverFunction: ComponentProps<typeof RootProvider>['serverFunction']\n}) {\n function PayloadLayout() {\n const data = useLoaderData({ strict: false })\n\n return (\n <>\n <RootProvider\n config={data.clientConfig}\n dateFNSKey={data.dateFNSKey}\n fallbackLang={data.fallbackLang}\n highContrastMode={false}\n isNavOpen={data.isNavOpen}\n languageCode={data.languageCode}\n languageOptions={data.languageOptions}\n locale={data.locale}\n permissions={data.user ? data.permissions : null}\n RouterAdapter={TanStackRouterAdapter}\n serverFunction={serverFunction}\n theme={data.theme}\n translations={data.translations}\n user={data.user}\n >\n <ProgressBar />\n {/* `data.providers` is the custom-provider tree (config.admin.components.providers)\n already wrapping the router <Outlet />; falls back to a bare <Outlet /> when\n no custom providers are configured. */}\n {data.providers ?? <Outlet />}\n </RootProvider>\n <div id=\"portal\" />\n </>\n )\n }\n\n // `staleReloadMode` lives on the loader *object* — router-core only reads it\n // off a non-function loader — so stale-match revalidation blocks on the fresh\n // loader instead of flashing stale layout data via the default background SWR.\n return {\n component: PayloadLayout,\n loader: { handler: () => load(), staleReloadMode: 'blocking' },\n }\n}\n"],"names":["ProgressBar","RootProvider","Outlet","useLoaderData","TanStackRouterAdapter","payloadLayoutRoute","load","serverFunction","PayloadLayout","data","strict","config","clientConfig","dateFNSKey","fallbackLang","highContrastMode","isNavOpen","languageCode","languageOptions","locale","permissions","user","RouterAdapter","theme","translations","providers","div","id","component","loader","handler","staleReloadMode"],"mappings":"AAAA;;AAIA,SAASA,WAAW,EAAEC,YAAY,QAAQ,iBAAgB;AAC1D,SAASC,MAAM,EAAEC,aAAa,QAAQ,yBAAwB;AAE9D,SAASC,qBAAqB,QAAQ,qCAAoC;AAS1E;;;;;;CAMC,GACD,OAAO,SAASC,mBAAmB,EACjCC,IAAI,EACJC,cAAc,EAIf;IACC,SAASC;QACP,MAAMC,OAAON,cAAc;YAAEO,QAAQ;QAAM;QAE3C,qBACE;;8BACE,MAACT;oBACCU,QAAQF,KAAKG,YAAY;oBACzBC,YAAYJ,KAAKI,UAAU;oBAC3BC,
|
|
1
|
+
{"version":3,"sources":["../../src/routes/layoutRoute.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentProps } from 'react'\n\nimport { ProgressBar, RootProvider } from '@payloadcms/ui'\nimport { Outlet, useLoaderData } from '@tanstack/react-router'\n\nimport { TanStackRouterAdapter } from '../elements/RouterAdapter/index.js'\n\n/**\n * Loader supplied by the app — a TanStack Start `createServerFn` that delegates\n * to `loadLayoutData`. Typed loosely because the server-fn's call signature is\n * generated by the Start compiler.\n */\nexport type LayoutLoad = () => Promise<Record<string, unknown>>\n\n/**\n * Route options for the Payload admin layout (`/_payload`). Maps the layout\n * loader data onto `RootProvider` and renders the admin chrome (progress bar,\n * custom-provider tree or router `<Outlet />`, portal mount). The app supplies\n * `load` (the layout-data server fn) and `serverFunction` (the server-function\n * client wired into `RootProvider`); everything else is adapter-owned.\n */\nexport function payloadLayoutRoute({\n load,\n serverFunction,\n}: {\n load: LayoutLoad\n serverFunction: ComponentProps<typeof RootProvider>['serverFunction']\n}) {\n function PayloadLayout() {\n const data = useLoaderData({ strict: false })\n\n return (\n <>\n <RootProvider\n config={data.clientConfig}\n dateFNSKey={data.dateFNSKey}\n embed={data.isEmbedded}\n fallbackLang={data.fallbackLang}\n highContrastMode={false}\n isNavOpen={data.isNavOpen}\n languageCode={data.languageCode}\n languageOptions={data.languageOptions}\n locale={data.locale}\n permissions={data.user ? data.permissions : null}\n RouterAdapter={TanStackRouterAdapter}\n serverFunction={serverFunction}\n theme={data.theme}\n translations={data.translations}\n user={data.user}\n >\n <ProgressBar />\n {/* `data.providers` is the custom-provider tree (config.admin.components.providers)\n already wrapping the router <Outlet />; falls back to a bare <Outlet /> when\n no custom providers are configured. */}\n {data.providers ?? <Outlet />}\n </RootProvider>\n <div id=\"portal\" />\n </>\n )\n }\n\n // `staleReloadMode` lives on the loader *object* — router-core only reads it\n // off a non-function loader — so stale-match revalidation blocks on the fresh\n // loader instead of flashing stale layout data via the default background SWR.\n return {\n component: PayloadLayout,\n loader: { handler: () => load(), staleReloadMode: 'blocking' },\n }\n}\n"],"names":["ProgressBar","RootProvider","Outlet","useLoaderData","TanStackRouterAdapter","payloadLayoutRoute","load","serverFunction","PayloadLayout","data","strict","config","clientConfig","dateFNSKey","embed","isEmbedded","fallbackLang","highContrastMode","isNavOpen","languageCode","languageOptions","locale","permissions","user","RouterAdapter","theme","translations","providers","div","id","component","loader","handler","staleReloadMode"],"mappings":"AAAA;;AAIA,SAASA,WAAW,EAAEC,YAAY,QAAQ,iBAAgB;AAC1D,SAASC,MAAM,EAAEC,aAAa,QAAQ,yBAAwB;AAE9D,SAASC,qBAAqB,QAAQ,qCAAoC;AAS1E;;;;;;CAMC,GACD,OAAO,SAASC,mBAAmB,EACjCC,IAAI,EACJC,cAAc,EAIf;IACC,SAASC;QACP,MAAMC,OAAON,cAAc;YAAEO,QAAQ;QAAM;QAE3C,qBACE;;8BACE,MAACT;oBACCU,QAAQF,KAAKG,YAAY;oBACzBC,YAAYJ,KAAKI,UAAU;oBAC3BC,OAAOL,KAAKM,UAAU;oBACtBC,cAAcP,KAAKO,YAAY;oBAC/BC,kBAAkB;oBAClBC,WAAWT,KAAKS,SAAS;oBACzBC,cAAcV,KAAKU,YAAY;oBAC/BC,iBAAiBX,KAAKW,eAAe;oBACrCC,QAAQZ,KAAKY,MAAM;oBACnBC,aAAab,KAAKc,IAAI,GAAGd,KAAKa,WAAW,GAAG;oBAC5CE,eAAepB;oBACfG,gBAAgBA;oBAChBkB,OAAOhB,KAAKgB,KAAK;oBACjBC,cAAcjB,KAAKiB,YAAY;oBAC/BH,MAAMd,KAAKc,IAAI;;sCAEf,KAACvB;wBAIAS,KAAKkB,SAAS,kBAAI,KAACzB;;;8BAEtB,KAAC0B;oBAAIC,IAAG;;;;IAGd;IAEA,6EAA6E;IAC7E,8EAA8E;IAC9E,+EAA+E;IAC/E,OAAO;QACLC,WAAWtB;QACXuB,QAAQ;YAAEC,SAAS,IAAM1B;YAAQ2B,iBAAiB;QAAW;IAC/D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRequestLocale.d.ts","sourceRoot":"","sources":["../../src/utilities/getRequestLocale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getRequestLocale.d.ts","sourceRoot":"","sources":["../../src/utilities/getRequestLocale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKrD,KAAK,oBAAoB,GAAG;IAC1B,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,wBAAsB,gBAAgB,CAAC,EAAE,GAAG,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkCjG"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { upsertPreferences } from '@payloadcms/ui/rsc';
|
|
1
|
+
import { getPreferences, upsertPreferences } from '@payloadcms/ui/rsc';
|
|
2
2
|
import { findLocaleFromCode } from '@payloadcms/ui/shared';
|
|
3
|
-
import { getPreferences } from './getPreferences.js';
|
|
4
3
|
export async function getRequestLocale({ req }) {
|
|
5
4
|
if (req.payload.config.localization) {
|
|
6
5
|
const localeFromParams = req.query.locale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getRequestLocale.ts"],"sourcesContent":["import type { Locale, PayloadRequest } from 'payload'\n\nimport { upsertPreferences } from '@payloadcms/ui/rsc'\nimport { findLocaleFromCode } from '@payloadcms/ui/shared'\n\
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getRequestLocale.ts"],"sourcesContent":["import type { Locale, PayloadRequest } from 'payload'\n\nimport { getPreferences, upsertPreferences } from '@payloadcms/ui/rsc'\nimport { findLocaleFromCode } from '@payloadcms/ui/shared'\n\ntype GetRequestLocaleArgs = {\n req: PayloadRequest\n}\n\nexport async function getRequestLocale({ req }: GetRequestLocaleArgs): Promise<Locale | undefined> {\n if (req.payload.config.localization) {\n const localeFromParams = req.query.locale as string | undefined\n\n if (req.user && localeFromParams) {\n await upsertPreferences<Locale['code']>({ key: 'locale', req, value: localeFromParams })\n }\n\n const userLocale =\n req.user &&\n findLocaleFromCode(\n req.payload.config.localization,\n localeFromParams ||\n (\n await getPreferences<Locale['code']>(\n 'locale',\n req.payload,\n req.user.id,\n req.user.collection,\n )\n )?.value,\n )\n\n return (\n userLocale ??\n findLocaleFromCode(\n req.payload.config.localization,\n req.payload.config.localization.defaultLocale || 'en',\n ) ??\n undefined\n )\n }\n\n return undefined\n}\n"],"names":["getPreferences","upsertPreferences","findLocaleFromCode","getRequestLocale","req","payload","config","localization","localeFromParams","query","locale","user","key","value","userLocale","id","collection","defaultLocale","undefined"],"mappings":"AAEA,SAASA,cAAc,EAAEC,iBAAiB,QAAQ,qBAAoB;AACtE,SAASC,kBAAkB,QAAQ,wBAAuB;AAM1D,OAAO,eAAeC,iBAAiB,EAAEC,GAAG,EAAwB;IAClE,IAAIA,IAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACnC,MAAMC,mBAAmBJ,IAAIK,KAAK,CAACC,MAAM;QAEzC,IAAIN,IAAIO,IAAI,IAAIH,kBAAkB;YAChC,MAAMP,kBAAkC;gBAAEW,KAAK;gBAAUR;gBAAKS,OAAOL;YAAiB;QACxF;QAEA,MAAMM,aACJV,IAAIO,IAAI,IACRT,mBACEE,IAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BC,oBAEI,CAAA,MAAMR,eACJ,UACAI,IAAIC,OAAO,EACXD,IAAIO,IAAI,CAACI,EAAE,EACXX,IAAIO,IAAI,CAACK,UAAU,CACrB,GACCH;QAGT,OACEC,cACAZ,mBACEE,IAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BH,IAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,CAACU,aAAa,IAAI,SAEnDC;IAEJ;IAEA,OAAOA;AACT"}
|
|
@@ -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,KAAK,CAAC,SAAS,CAAA;CAAE,GACpE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB;IACE,QAAQ,EAAE,iBAAiB,CAAA;IAC3B;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B,CAAA;AA0FL;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,
|
|
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,KAAK,CAAC,SAAS,CAAA;CAAE,GACpE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB;IACE,QAAQ,EAAE,iBAAiB,CAAA;IAC3B;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B,CAAA;AA0FL;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,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
|
|
@@ -165,13 +156,14 @@ const resolveTitle = (title)=>{
|
|
|
165
156
|
config: Promise.resolve(config),
|
|
166
157
|
importMap,
|
|
167
158
|
initReq: boundInitReq,
|
|
168
|
-
|
|
159
|
+
key: splat ?? '',
|
|
160
|
+
notFound: pageServerAdapter.notFound,
|
|
169
161
|
// `segments` is intentionally `undefined` for the admin root (`/admin`),
|
|
170
162
|
// matching Next's optional catch-all; `renderRoot` handles it at runtime.
|
|
171
163
|
params: Promise.resolve({
|
|
172
164
|
segments
|
|
173
165
|
}),
|
|
174
|
-
redirect,
|
|
166
|
+
redirect: pageServerAdapter.redirect,
|
|
175
167
|
searchParams: Promise.resolve(searchParams)
|
|
176
168
|
});
|
|
177
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 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","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,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,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jC,IAAIjC,GAAG,IAAIuE,QAAQE,KAAK,CAAC,YAAYxD,MAAM;YAAE;QACnE;QACA,MAAMqD;IACR;AACF"}
|
|
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 // 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":"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,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,MAAMK,KAAK;QAAC,IACnFlB,WAEPmB,MAAM,CAACC;IAEV,MAAMC,WAAWjB,KAAKkB,KAAK;IAC3B,MAAMC,WAAWb,MAAMC,OAAO,C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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 +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"}
|
|
@@ -11,7 +11,7 @@ import { builtinModules } from 'node:module';
|
|
|
11
11
|
/^@payloadcms\/richtext-lexical\/rsc/,
|
|
12
12
|
/^@payloadcms\/richtext-slate\/rsc/,
|
|
13
13
|
'@payloadcms/ui/server',
|
|
14
|
-
/^@payloadcms\/tanstack-start\/(layouts|rsc|server
|
|
14
|
+
/^@payloadcms\/tanstack-start\/(layouts|rsc|server)/,
|
|
15
15
|
'sharp',
|
|
16
16
|
'busboy',
|
|
17
17
|
'croner',
|
|
@@ -30,7 +30,7 @@ import { builtinModules } from 'node:module';
|
|
|
30
30
|
* to permit even when they appear to cross a server/client boundary.
|
|
31
31
|
*/ export function onImportProtectionViolation(violation) {
|
|
32
32
|
const info = violation;
|
|
33
|
-
const allowedClientFileImporters = /\/richtext-lexical\/.*\/exports\/client\/|\/
|
|
33
|
+
const allowedClientFileImporters = /\/richtext-lexical\/.*\/exports\/client\/|\/ui\//;
|
|
34
34
|
if (info.envType === 'server' && info.resolved?.includes('.client.') && allowedClientFileImporters.test(info.importer)) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/withPayload/importProtection.ts"],"sourcesContent":["import { builtinModules } from 'node:module'\n\n/**\n * Specifiers that must never appear in the client module graph. These are the\n * server-only Payload entry points plus Node.js built-ins and a handful of\n * Node-only npm packages that Payload pulls in transitively.\n */\nexport const serverOnlyClientSpecifiers: Array<RegExp | string> = [\n /^node:/,\n new RegExp(`^(${builtinModules.join('|')})(\\\\/|$)`),\n '@payload-config',\n /^@payloadcms\\/next\\/rsc/,\n /^@payloadcms\\/richtext-lexical\\/rsc/,\n /^@payloadcms\\/richtext-slate\\/rsc/,\n '@payloadcms/ui/server',\n /^@payloadcms\\/tanstack-start\\/(layouts|rsc|server
|
|
1
|
+
{"version":3,"sources":["../../src/withPayload/importProtection.ts"],"sourcesContent":["import { builtinModules } from 'node:module'\n\n/**\n * Specifiers that must never appear in the client module graph. These are the\n * server-only Payload entry points plus Node.js built-ins and a handful of\n * Node-only npm packages that Payload pulls in transitively.\n */\nexport const serverOnlyClientSpecifiers: Array<RegExp | string> = [\n /^node:/,\n new RegExp(`^(${builtinModules.join('|')})(\\\\/|$)`),\n '@payload-config',\n /^@payloadcms\\/next\\/rsc/,\n /^@payloadcms\\/richtext-lexical\\/rsc/,\n /^@payloadcms\\/richtext-slate\\/rsc/,\n '@payloadcms/ui/server',\n /^@payloadcms\\/tanstack-start\\/(layouts|rsc|server)/,\n 'sharp',\n 'busboy',\n 'croner',\n 'pino',\n 'pino-pretty',\n 'prompts',\n 'ws',\n 'undici',\n 'get-tsconfig',\n /^file-type/,\n /^react-dom\\/server/,\n]\n\n/**\n * Allowlist callback for the `tanstackStart` plugin's import-protection. These\n * are the legitimate cross-environment imports in our monorepo that we want\n * to permit even when they appear to cross a server/client boundary.\n */\nexport function onImportProtectionViolation(violation: unknown): boolean | void {\n const info = violation as {\n envType: 'client' | 'server'\n importer: string\n resolved?: string\n }\n\n const allowedClientFileImporters = /\\/richtext-lexical\\/.*\\/exports\\/client\\/|\\/ui\\//\n\n if (\n info.envType === 'server' &&\n info.resolved?.includes('.client.') &&\n allowedClientFileImporters.test(info.importer)\n ) {\n return false\n }\n\n if (info.importer.includes('/richtext-lexical/') && info.importer.includes('/field/Diff/')) {\n return false\n }\n\n if (info.importer.includes('/packages/payload/') || info.importer.includes('/payload/dist/')) {\n return false\n }\n\n if (\n info.importer.includes('@payloadcms/ui') &&\n (info.importer.includes('/exports/rsc/') || info.importer.includes('/rsc/index'))\n ) {\n return false\n }\n\n if (info.envType === 'server' && info.importer.includes('vite-rsc/client-references')) {\n return false\n }\n}\n\nexport const defaultImportProtectionIgnoreImporters: RegExp[] = [/^src\\/importMap\\.js(?:\\?.*)?$/]\n"],"names":["builtinModules","serverOnlyClientSpecifiers","RegExp","join","onImportProtectionViolation","violation","info","allowedClientFileImporters","envType","resolved","includes","test","importer","defaultImportProtectionIgnoreImporters"],"mappings":"AAAA,SAASA,cAAc,QAAQ,cAAa;AAE5C;;;;CAIC,GACD,OAAO,MAAMC,6BAAqD;IAChE;IACA,IAAIC,OAAO,CAAC,EAAE,EAAEF,eAAeG,IAAI,CAAC,KAAK,QAAQ,CAAC;IAClD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;CAIC,GACD,OAAO,SAASC,4BAA4BC,SAAkB;IAC5D,MAAMC,OAAOD;IAMb,MAAME,6BAA6B;IAEnC,IACED,KAAKE,OAAO,KAAK,YACjBF,KAAKG,QAAQ,EAAEC,SAAS,eACxBH,2BAA2BI,IAAI,CAACL,KAAKM,QAAQ,GAC7C;QACA,OAAO;IACT;IAEA,IAAIN,KAAKM,QAAQ,CAACF,QAAQ,CAAC,yBAAyBJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,iBAAiB;QAC1F,OAAO;IACT;IAEA,IAAIJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,yBAAyBJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,mBAAmB;QAC5F,OAAO;IACT;IAEA,IACEJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,qBACtBJ,CAAAA,KAAKM,QAAQ,CAACF,QAAQ,CAAC,oBAAoBJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,aAAY,GAC/E;QACA,OAAO;IACT;IAEA,IAAIJ,KAAKE,OAAO,KAAK,YAAYF,KAAKM,QAAQ,CAACF,QAAQ,CAAC,+BAA+B;QACrF,OAAO;IACT;AACF;AAEA,OAAO,MAAMG,yCAAmD;IAAC;CAAgC,CAAA"}
|
|
@@ -37,7 +37,7 @@ const STYLE_EXTENSION_RE = /\.(?:s?css|less)$/i;
|
|
|
37
37
|
* blowing past the e2e waits. Stripping them collapses it back to ~3s.
|
|
38
38
|
*
|
|
39
39
|
* Safe because every one of these components' styles also ship in the global
|
|
40
|
-
* `@payloadcms/ui/
|
|
40
|
+
* `@payloadcms/ui/css/app.css` the admin imports, so dropping the per-module
|
|
41
41
|
* RSC collection here changes nothing visually (verified: diff + Nav stay
|
|
42
42
|
* styled). The admin `Nav` etc. are deliberately excluded — they rely on the
|
|
43
43
|
* RSC collection and a broad strip leaves them unstyled.
|