@payloadcms/tanstack-start 4.0.0-internal.c7d5de4 → 4.0.0-internal.cb69780
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 +18 -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 -4
- package/dist/exports/server.d.ts.map +1 -1
- package/dist/exports/server.js +0 -3
- package/dist/exports/server.js.map +1 -1
- package/dist/exports/shared.d.ts +2 -0
- package/dist/exports/shared.d.ts.map +1 -0
- package/dist/exports/shared.js +3 -0
- package/dist/exports/shared.js.map +1 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.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 +11 -5
- 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 +53 -45
- package/dist/routes/adminRoutes.js.map +1 -1
- package/dist/routes/layoutRoute.d.ts +5 -4
- package/dist/routes/layoutRoute.d.ts.map +1 -1
- package/dist/routes/layoutRoute.js +3 -1
- 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 +63 -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/getRequestI18n.server.d.ts +1 -1
- package/dist/utilities/getRequestI18n.server.js +1 -1
- package/dist/utilities/getRequestI18n.server.js.map +1 -1
- package/dist/utilities/graphqlHandler.server.js +2 -2
- package/dist/utilities/graphqlHandler.server.js.map +1 -1
- package/dist/utilities/handleServerFunctions.d.ts +1 -19
- package/dist/utilities/handleServerFunctions.d.ts.map +1 -1
- package/dist/utilities/handleServerFunctions.js +6 -57
- package/dist/utilities/handleServerFunctions.js.map +1 -1
- package/dist/utilities/initAdminContext.server.d.ts +9 -0
- package/dist/utilities/initAdminContext.server.d.ts.map +1 -0
- package/dist/utilities/initAdminContext.server.js +13 -0
- package/dist/utilities/initAdminContext.server.js.map +1 -0
- package/dist/utilities/loadAdminPage.d.ts +7 -4
- package/dist/utilities/loadAdminPage.d.ts.map +1 -1
- package/dist/utilities/loadAdminPage.js +11 -23
- 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/routerSearch.d.ts +1 -1
- package/dist/utilities/routerSearch.js +1 -1
- package/dist/utilities/routerSearch.js.map +1 -1
- package/dist/utilities/serializeForRsc.d.ts.map +1 -1
- package/dist/utilities/serializeForRsc.js +6 -1
- package/dist/utilities/serializeForRsc.js.map +1 -1
- package/dist/utilities/serverFunctionClient.d.ts.map +1 -1
- package/dist/utilities/serverFunctionClient.js +6 -1
- package/dist/utilities/serverFunctionClient.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 +19 -3
- package/dist/utilities/toSerializable.js.map +1 -1
- package/dist/withPayload/config/external.d.ts +44 -0
- package/dist/withPayload/config/external.d.ts.map +1 -0
- package/dist/{vite → withPayload}/config/external.js +29 -5
- package/dist/withPayload/config/external.js.map +1 -0
- package/dist/withPayload/config/optimizeDeps.d.ts.map +1 -0
- package/dist/{vite → withPayload}/config/optimizeDeps.js +27 -7
- package/dist/withPayload/config/optimizeDeps.js.map +1 -0
- package/dist/withPayload/config/scss.d.ts.map +1 -0
- package/dist/withPayload/config/scss.js.map +1 -0
- 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 -0
- package/dist/{vite → withPayload}/importProtection.js +2 -2
- package/dist/withPayload/importProtection.js.map +1 -0
- package/dist/{vite → withPayload}/index.d.ts +19 -0
- package/dist/withPayload/index.d.ts.map +1 -0
- package/dist/{vite → withPayload}/index.js +58 -8
- package/dist/withPayload/index.js.map +1 -0
- package/dist/withPayload/workarounds/clientModuleResolution.d.ts.map +1 -0
- package/dist/withPayload/workarounds/clientModuleResolution.js.map +1 -0
- package/dist/withPayload/workarounds/devTransforms.d.ts.map +1 -0
- package/dist/withPayload/workarounds/devTransforms.js.map +1 -0
- package/dist/withPayload/workarounds/reactDomServerInRsc.d.ts.map +1 -0
- package/dist/withPayload/workarounds/reactDomServerInRsc.js.map +1 -0
- package/dist/withPayload/workarounds/stripDistStyleImports.d.ts.map +1 -0
- package/dist/{vite → withPayload}/workarounds/stripDistStyleImports.js +1 -1
- package/dist/withPayload/workarounds/stripDistStyleImports.js.map +1 -0
- package/dist/withPayload/workarounds/stubPrettierInClient.d.ts.map +1 -0
- package/dist/withPayload/workarounds/stubPrettierInClient.js.map +1 -0
- package/dist/withPayload/workarounds/wrapCjsForClient.d.ts.map +1 -0
- package/dist/withPayload/workarounds/wrapCjsForClient.js.map +1 -0
- package/package.json +15 -14
- 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/exports/vite.d.ts +0 -3
- package/dist/exports/vite.d.ts.map +0 -1
- package/dist/exports/vite.js +0 -3
- package/dist/exports/vite.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/getRequestLocale.d.ts +0 -7
- package/dist/utilities/getRequestLocale.d.ts.map +0 -1
- package/dist/utilities/getRequestLocale.js +0 -20
- package/dist/utilities/getRequestLocale.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/initReq.server.d.ts +0 -19
- package/dist/utilities/initReq.server.d.ts.map +0 -1
- package/dist/utilities/initReq.server.js +0 -87
- package/dist/utilities/initReq.server.js.map +0 -1
- package/dist/utilities/serverFunctionHandlers.d.ts +0 -18
- package/dist/utilities/serverFunctionHandlers.d.ts.map +0 -1
- package/dist/utilities/serverFunctionHandlers.js +0 -17
- package/dist/utilities/serverFunctionHandlers.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
- package/dist/vite/config/external.d.ts +0 -26
- package/dist/vite/config/external.d.ts.map +0 -1
- package/dist/vite/config/external.js.map +0 -1
- package/dist/vite/config/optimizeDeps.d.ts.map +0 -1
- package/dist/vite/config/optimizeDeps.js.map +0 -1
- package/dist/vite/config/scss.d.ts.map +0 -1
- package/dist/vite/config/scss.js.map +0 -1
- package/dist/vite/importProtection.d.ts.map +0 -1
- package/dist/vite/importProtection.js.map +0 -1
- package/dist/vite/index.d.ts.map +0 -1
- package/dist/vite/index.js.map +0 -1
- package/dist/vite/workarounds/clientModuleResolution.d.ts.map +0 -1
- package/dist/vite/workarounds/clientModuleResolution.js.map +0 -1
- package/dist/vite/workarounds/devTransforms.d.ts.map +0 -1
- package/dist/vite/workarounds/devTransforms.js.map +0 -1
- package/dist/vite/workarounds/reactDomServerInRsc.d.ts.map +0 -1
- package/dist/vite/workarounds/reactDomServerInRsc.js.map +0 -1
- package/dist/vite/workarounds/stripDistStyleImports.d.ts.map +0 -1
- package/dist/vite/workarounds/stripDistStyleImports.js.map +0 -1
- package/dist/vite/workarounds/stubPrettierInClient.d.ts.map +0 -1
- package/dist/vite/workarounds/stubPrettierInClient.js.map +0 -1
- package/dist/vite/workarounds/wrapCjsForClient.d.ts.map +0 -1
- package/dist/vite/workarounds/wrapCjsForClient.js.map +0 -1
- /package/dist/{vite → withPayload}/config/optimizeDeps.d.ts +0 -0
- /package/dist/{vite → withPayload}/config/scss.d.ts +0 -0
- /package/dist/{vite → withPayload}/config/scss.js +0 -0
- /package/dist/{vite → withPayload}/importProtection.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/clientModuleResolution.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/clientModuleResolution.js +0 -0
- /package/dist/{vite → withPayload}/workarounds/devTransforms.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/devTransforms.js +0 -0
- /package/dist/{vite → withPayload}/workarounds/reactDomServerInRsc.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/reactDomServerInRsc.js +0 -0
- /package/dist/{vite → withPayload}/workarounds/stripDistStyleImports.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/stubPrettierInClient.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/stubPrettierInClient.js +0 -0
- /package/dist/{vite → withPayload}/workarounds/wrapCjsForClient.d.ts +0 -0
- /package/dist/{vite → withPayload}/workarounds/wrapCjsForClient.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devConfigReloadEvent.d.ts","sourceRoot":"","sources":["../../src/utilities/devConfigReloadEvent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Vite HMR event the `payload:dev-config-reload` plugin broadcasts when
|
|
3
|
+
* the Payload config (or anything it imports) changes on disk.
|
|
4
|
+
*
|
|
5
|
+
* Kept in its own module so the Vite plugin can name the event without pulling
|
|
6
|
+
* in the server runtime — and therefore the whole CMS — when `vite.config.ts` loads.
|
|
7
|
+
*/ export const PAYLOAD_CONFIG_CHANGED_EVENT = 'payload:config-changed';
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=devConfigReloadEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/devConfigReloadEvent.ts"],"sourcesContent":["/**\n * Custom Vite HMR event the `payload:dev-config-reload` plugin broadcasts when\n * the Payload config (or anything it imports) changes on disk.\n *\n * Kept in its own module so the Vite plugin can name the event without pulling\n * in the server runtime — and therefore the whole CMS — when `vite.config.ts` loads.\n */\nexport const PAYLOAD_CONFIG_CHANGED_EVENT = 'payload:config-changed'\n"],"names":["PAYLOAD_CONFIG_CHANGED_EVENT"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,MAAMA,+BAA+B,yBAAwB"}
|
|
@@ -2,7 +2,7 @@ import type { I18nClient } from '@payloadcms/translations';
|
|
|
2
2
|
import type { SanitizedConfig } from 'payload';
|
|
3
3
|
/**
|
|
4
4
|
* Resolves the client `I18n` for the current TanStack Start request without a
|
|
5
|
-
* full `
|
|
5
|
+
* full `initAdminContext` (no `getPayload`/auth/access). Mirrors the Next.js adapter's
|
|
6
6
|
* `getNextRequestI18n` and feeds the shared `generatePageMetadata`, which only
|
|
7
7
|
* needs `config` + `i18n` to translate admin-page titles.
|
|
8
8
|
*/
|
|
@@ -3,7 +3,7 @@ import { getRequest } from '@tanstack/react-start/server';
|
|
|
3
3
|
import { getRequestLanguage, parseCookies } from 'payload';
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the client `I18n` for the current TanStack Start request without a
|
|
6
|
-
* full `
|
|
6
|
+
* full `initAdminContext` (no `getPayload`/auth/access). Mirrors the Next.js adapter's
|
|
7
7
|
* `getNextRequestI18n` and feeds the shared `generatePageMetadata`, which only
|
|
8
8
|
* needs `config` + `i18n` to translate admin-page titles.
|
|
9
9
|
*/ export async function getRequestI18n({ config }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getRequestI18n.server.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { SanitizedConfig } from 'payload'\n\nimport { initI18n } from '@payloadcms/translations'\nimport { getRequest } from '@tanstack/react-start/server'\nimport { getRequestLanguage, parseCookies } from 'payload'\n\n/**\n * Resolves the client `I18n` for the current TanStack Start request without a\n * full `
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getRequestI18n.server.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { SanitizedConfig } from 'payload'\n\nimport { initI18n } from '@payloadcms/translations'\nimport { getRequest } from '@tanstack/react-start/server'\nimport { getRequestLanguage, parseCookies } from 'payload'\n\n/**\n * Resolves the client `I18n` for the current TanStack Start request without a\n * full `initAdminContext` (no `getPayload`/auth/access). Mirrors the Next.js adapter's\n * `getNextRequestI18n` and feeds the shared `generatePageMetadata`, which only\n * needs `config` + `i18n` to translate admin-page titles.\n */\nexport async function getRequestI18n({ config }: { config: SanitizedConfig }): Promise<I18nClient> {\n const webRequest = getRequest()\n const headers = new Headers(webRequest.headers)\n const cookies = parseCookies(headers)\n\n const languageCode = getRequestLanguage({ config, cookies, headers })\n\n return initI18n({\n config: config.i18n,\n context: 'client',\n language: languageCode,\n })\n}\n"],"names":["initI18n","getRequest","getRequestLanguage","parseCookies","getRequestI18n","config","webRequest","headers","Headers","cookies","languageCode","i18n","context","language"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,UAAU,QAAQ,+BAA8B;AACzD,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,UAAS;AAE1D;;;;;CAKC,GACD,OAAO,eAAeC,eAAe,EAAEC,MAAM,EAA+B;IAC1E,MAAMC,aAAaL;IACnB,MAAMM,UAAU,IAAIC,QAAQF,WAAWC,OAAO;IAC9C,MAAME,UAAUN,aAAaI;IAE7B,MAAMG,eAAeR,mBAAmB;QAAEG;QAAQI;QAASF;IAAQ;IAEnE,OAAOP,SAAS;QACdK,QAAQA,OAAOM,IAAI;QACnBC,SAAS;QACTC,UAAUH;IACZ;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addDataAndFileToRequest, addLocalesToRequestFromData,
|
|
1
|
+
import { addDataAndFileToRequest, addLocalesToRequestFromData, createPayloadRequestFromWebRequest, headersWithCors, logError, mergeHeaders } from 'payload';
|
|
2
2
|
const handleError = async ({ err, payload, req })=>{
|
|
3
3
|
const status = err.originalError?.status || 500;
|
|
4
4
|
let errorMessage = err.message;
|
|
@@ -72,7 +72,7 @@ const getGraphql = async (config)=>{
|
|
|
72
72
|
* Requires `@payloadcms/graphql` and `graphql-http` to be installed in the consuming app.
|
|
73
73
|
*/ export const handleGraphQL = async ({ config, request })=>{
|
|
74
74
|
const originalRequest = request.clone();
|
|
75
|
-
const req = await
|
|
75
|
+
const req = await createPayloadRequestFromWebRequest({
|
|
76
76
|
canSetHeaders: true,
|
|
77
77
|
config,
|
|
78
78
|
request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/graphqlHandler.server.ts"],"sourcesContent":["import type { Payload, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport {\n addDataAndFileToRequest,\n addLocalesToRequestFromData,\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/graphqlHandler.server.ts"],"sourcesContent":["import type { Payload, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport {\n addDataAndFileToRequest,\n addLocalesToRequestFromData,\n createPayloadRequestFromWebRequest,\n headersWithCors,\n logError,\n mergeHeaders,\n} from 'payload'\n\nconst handleError = async ({\n err,\n payload,\n req,\n}: {\n err: any\n payload: Payload\n req: PayloadRequest\n}): Promise<any> => {\n const status = err.originalError?.status || 500\n let errorMessage = err.message\n logError({ err, payload })\n\n if (!payload.config.debug && status === 500) {\n errorMessage = 'Something went wrong.'\n }\n\n let response: any = {\n extensions: {\n name: err?.originalError?.name || undefined,\n data: (err && err.originalError && err.originalError.data) || undefined,\n stack: payload.config.debug ? err.stack : undefined,\n statusCode: status,\n },\n locations: err.locations,\n message: errorMessage,\n path: err.path,\n }\n\n await payload.config.hooks.afterError?.reduce(async (promise, hook) => {\n await promise\n\n const result = await hook({\n context: req.context,\n error: err,\n graphqlResult: response,\n req,\n })\n\n if (result) {\n response = result.graphqlResult || response\n }\n }, Promise.resolve())\n\n return response\n}\n\nlet cached: { graphql: any; promise: null | Promise<any> } = { graphql: null, promise: null }\n\nconst getGraphql = async (config: Promise<SanitizedConfig> | SanitizedConfig) => {\n if (process.env.NODE_ENV === 'development') {\n cached = { graphql: null, promise: null }\n }\n\n if (cached.graphql) {\n return cached.graphql\n }\n\n if (!cached.promise) {\n const resolvedConfig = await config\n const graphqlPackage = '@payloadcms/graphql'\n const { configToSchema } = await import(/* @vite-ignore */ graphqlPackage)\n cached.promise = new Promise((resolve) => {\n const schema = configToSchema(resolvedConfig)\n resolve(cached.graphql || schema)\n })\n }\n\n try {\n cached.graphql = await cached.promise\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.graphql\n}\n\n/**\n * Handles GraphQL HTTP requests for TanStack Start apps.\n * Mirrors the behaviour of `@payloadcms/next`'s GraphQL route handler.\n *\n * Requires `@payloadcms/graphql` and `graphql-http` to be installed in the consuming app.\n */\nexport const handleGraphQL = async ({\n config,\n request,\n}: {\n config: Promise<SanitizedConfig> | SanitizedConfig\n request: Request\n}): Promise<Response> => {\n const originalRequest = request.clone()\n\n const req = await createPayloadRequestFromWebRequest({\n canSetHeaders: true,\n config,\n request,\n })\n\n await addDataAndFileToRequest(req)\n addLocalesToRequestFromData(req)\n\n const { schema, validationRules } = await getGraphql(config)\n\n const { payload } = req\n\n const graphqlHttpHandlerPath = 'graphql-http/lib/use/fetch'\n const { createHandler } = await import(/* @vite-ignore */ graphqlHttpHandlerPath)\n\n const headers: Record<string, string> = {}\n const apiResponse = await createHandler({\n context: { headers, req },\n onOperation: async (_request: any, args: any, result: any) => {\n const response =\n typeof payload.extensions === 'function'\n ? await payload.extensions({\n args,\n req: _request,\n result,\n })\n : result\n if (response.errors) {\n const errors = await Promise.all(\n response.errors.map((error: any) => {\n return handleError({ err: error, payload, req })\n }),\n )\n return { ...response, errors }\n }\n return response\n },\n schema,\n validationRules: (_: any, args: any, defaultRules: any) =>\n defaultRules.concat(validationRules(args)),\n })(originalRequest)\n\n const resHeaders = headersWithCors({\n headers: new Headers(apiResponse.headers),\n req,\n })\n\n for (const key of Object.keys(headers)) {\n resHeaders.append(key, headers[key]!)\n }\n\n return new Response(apiResponse.body, {\n headers: req.responseHeaders ? mergeHeaders(req.responseHeaders, resHeaders) : resHeaders,\n status: apiResponse.status,\n })\n}\n"],"names":["addDataAndFileToRequest","addLocalesToRequestFromData","createPayloadRequestFromWebRequest","headersWithCors","logError","mergeHeaders","handleError","err","payload","req","status","originalError","errorMessage","message","config","debug","response","extensions","name","undefined","data","stack","statusCode","locations","path","hooks","afterError","reduce","promise","hook","result","context","error","graphqlResult","Promise","resolve","cached","graphql","getGraphql","process","env","NODE_ENV","resolvedConfig","graphqlPackage","configToSchema","schema","e","handleGraphQL","request","originalRequest","clone","canSetHeaders","validationRules","graphqlHttpHandlerPath","createHandler","headers","apiResponse","onOperation","_request","args","errors","all","map","_","defaultRules","concat","resHeaders","Headers","key","Object","keys","append","Response","body","responseHeaders"],"mappings":"AAEA,SACEA,uBAAuB,EACvBC,2BAA2B,EAC3BC,kCAAkC,EAClCC,eAAe,EACfC,QAAQ,EACRC,YAAY,QACP,UAAS;AAEhB,MAAMC,cAAc,OAAO,EACzBC,GAAG,EACHC,OAAO,EACPC,GAAG,EAKJ;IACC,MAAMC,SAASH,IAAII,aAAa,EAAED,UAAU;IAC5C,IAAIE,eAAeL,IAAIM,OAAO;IAC9BT,SAAS;QAAEG;QAAKC;IAAQ;IAExB,IAAI,CAACA,QAAQM,MAAM,CAACC,KAAK,IAAIL,WAAW,KAAK;QAC3CE,eAAe;IACjB;IAEA,IAAII,WAAgB;QAClBC,YAAY;YACVC,MAAMX,KAAKI,eAAeO,QAAQC;YAClCC,MAAM,AAACb,OAAOA,IAAII,aAAa,IAAIJ,IAAII,aAAa,CAACS,IAAI,IAAKD;YAC9DE,OAAOb,QAAQM,MAAM,CAACC,KAAK,GAAGR,IAAIc,KAAK,GAAGF;YAC1CG,YAAYZ;QACd;QACAa,WAAWhB,IAAIgB,SAAS;QACxBV,SAASD;QACTY,MAAMjB,IAAIiB,IAAI;IAChB;IAEA,MAAMhB,QAAQM,MAAM,CAACW,KAAK,CAACC,UAAU,EAAEC,OAAO,OAAOC,SAASC;QAC5D,MAAMD;QAEN,MAAME,SAAS,MAAMD,KAAK;YACxBE,SAAStB,IAAIsB,OAAO;YACpBC,OAAOzB;YACP0B,eAAejB;YACfP;QACF;QAEA,IAAIqB,QAAQ;YACVd,WAAWc,OAAOG,aAAa,IAAIjB;QACrC;IACF,GAAGkB,QAAQC,OAAO;IAElB,OAAOnB;AACT;AAEA,IAAIoB,SAAyD;IAAEC,SAAS;IAAMT,SAAS;AAAK;AAE5F,MAAMU,aAAa,OAAOxB;IACxB,IAAIyB,QAA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,QAAQS,UAAU,CAAC;gBACvB0C;gBACAlD,KAAKiD;gBACL5B;YACF,KACAA;YACN,IAAId,SAAS4C,MAAM,EAAE;gBACnB,MAAMA,SAAS,MAAM1B,QAAQ2B,GAAG,CAC9B7C,SAAS4C,MAAM,CAACE,GAAG,CAAC,CAAC9B;oBACnB,OAAO1B,YAAY;wBAAEC,KAAKyB;wBAAOxB;wBAASC;oBAAI;gBAChD;gBAEF,OAAO;oBAAE,GAAGO,QAAQ;oBAAE4C;gBAAO;YAC/B;YACA,OAAO5C;QACT;QACA6B;QACAO,iBAAiB,CAACW,GAAQJ,MAAWK,eACnCA,aAAaC,MAAM,CAACb,gBAAgBO;IACxC,GAAGV;IAEH,MAAMiB,aAAa/D,gBAAgB;QACjCoD,SAAS,IAAIY,QAAQX,YAAYD,OAAO;QACxC9C;IACF;IAEA,KAAK,MAAM2D,OAAOC,OAAOC,IAAI,CAACf,SAAU;QACtCW,WAAWK,MAAM,CAACH,KAAKb,OAAO,CAACa,IAAI;IACrC;IAEA,OAAO,IAAII,SAAShB,YAAYiB,IAAI,EAAE;QACpClB,SAAS9C,IAAIiE,eAAe,GAAGrE,aAAaI,IAAIiE,eAAe,EAAER,cAAcA;QAC/ExD,QAAQ8C,YAAY9C,MAAM;IAC5B;AACF,EAAC"}
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Server function dispatcher for TanStack Start.
|
|
4
|
-
*
|
|
5
|
-
* Mirrors `packages/next/src/utilities/handleServerFunctions.ts` and uses the
|
|
6
|
-
* exact same set of handlers — both adapters share `sharedServerFunctions`
|
|
7
|
-
* plus the small set of RSC-only handlers re-exported by `@payloadcms/ui`.
|
|
8
|
-
*
|
|
9
|
-
* Pipes the result through `serializeForRsc`, which converts any React
|
|
10
|
-
* elements left in the response (e.g. `state[path].customComponents.Field`
|
|
11
|
-
* produced by `buildFormState`, the `List` / `Document` nodes returned by
|
|
12
|
-
* `render-list` / `render-document`) into RSC "renderable handles" via
|
|
13
|
-
* `renderServerComponent` from `@tanstack/react-start/rsc`. TanStack Start's
|
|
14
|
-
* `$RSC` serialization adapter then ships those handles to the client as
|
|
15
|
-
* Flight payloads — so this dispatcher must be invoked from a context that
|
|
16
|
-
* uses TanStack's wire format (e.g. `createServerFn`), not raw
|
|
17
|
-
* `JSON.stringify`.
|
|
18
|
-
*/
|
|
19
|
-
export declare const handleServerFunctions: ServerFunctionHandler;
|
|
1
|
+
export declare const handleServerFunctions: import("payload").ServerFunctionHandler;
|
|
20
2
|
//# sourceMappingURL=handleServerFunctions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleServerFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/handleServerFunctions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handleServerFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/handleServerFunctions.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,yCAGhC,CAAA"}
|
|
@@ -1,60 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { sharedServerFunctions } from '@payloadcms/ui/utilities/serverFunctionRegistry';
|
|
4
|
-
import { getDefaultLayoutHandler } from '@payloadcms/ui/views/Dashboard/Default/ModularDashboard/renderWidget/getDefaultLayoutServerFn';
|
|
5
|
-
import { renderWidgetHandler } from '@payloadcms/ui/views/Dashboard/Default/ModularDashboard/renderWidget/renderWidgetServerFn';
|
|
6
|
-
import { renderDocumentSlotsHandler } from '@payloadcms/ui/views/Document/renderDocumentSlots';
|
|
7
|
-
import { RenderRSCComponent } from '../rsc/renderPayloadRSC.js';
|
|
8
|
-
import { initReq } from './initReq.server.js';
|
|
1
|
+
import { createServerFunctionHandler } from '@payloadcms/ui/utilities/handleServerFunctions';
|
|
2
|
+
import { initAdminContext } from './initAdminContext.server.js';
|
|
9
3
|
import { serializeForRsc } from './serializeForRsc.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'render-document-slots': renderDocumentSlotsHandler,
|
|
15
|
-
'render-field': _internal_renderFieldHandler,
|
|
16
|
-
'render-tab': renderTabHandler,
|
|
17
|
-
'render-widget': renderWidgetHandler,
|
|
18
|
-
'switch-language': switchLanguageHandler
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Server function dispatcher for TanStack Start.
|
|
22
|
-
*
|
|
23
|
-
* Mirrors `packages/next/src/utilities/handleServerFunctions.ts` and uses the
|
|
24
|
-
* exact same set of handlers — both adapters share `sharedServerFunctions`
|
|
25
|
-
* plus the small set of RSC-only handlers re-exported by `@payloadcms/ui`.
|
|
26
|
-
*
|
|
27
|
-
* Pipes the result through `serializeForRsc`, which converts any React
|
|
28
|
-
* elements left in the response (e.g. `state[path].customComponents.Field`
|
|
29
|
-
* produced by `buildFormState`, the `List` / `Document` nodes returned by
|
|
30
|
-
* `render-list` / `render-document`) into RSC "renderable handles" via
|
|
31
|
-
* `renderServerComponent` from `@tanstack/react-start/rsc`. TanStack Start's
|
|
32
|
-
* `$RSC` serialization adapter then ships those handles to the client as
|
|
33
|
-
* Flight payloads — so this dispatcher must be invoked from a context that
|
|
34
|
-
* uses TanStack's wire format (e.g. `createServerFn`), not raw
|
|
35
|
-
* `JSON.stringify`.
|
|
36
|
-
*/ export const handleServerFunctions = async (args)=>{
|
|
37
|
-
const { name: fnKey, args: fnArgs, config: configPromise, importMap, serverFunctions: extraServerFunctions } = args;
|
|
38
|
-
const { cookies, locale, permissions, req } = await initReq({
|
|
39
|
-
configPromise,
|
|
40
|
-
importMap
|
|
41
|
-
});
|
|
42
|
-
const augmentedArgs = {
|
|
43
|
-
...fnArgs,
|
|
44
|
-
cookies,
|
|
45
|
-
importMap,
|
|
46
|
-
locale,
|
|
47
|
-
mode: 'rsc',
|
|
48
|
-
permissions,
|
|
49
|
-
renderComponent: RenderRSCComponent,
|
|
50
|
-
req
|
|
51
|
-
};
|
|
52
|
-
const fn = extraServerFunctions?.[fnKey] || baseServerFunctions[fnKey];
|
|
53
|
-
if (!fn) {
|
|
54
|
-
throw new Error(`Unknown Server Function: ${fnKey}`);
|
|
55
|
-
}
|
|
56
|
-
const result = await fn(augmentedArgs);
|
|
57
|
-
return await serializeForRsc(result);
|
|
58
|
-
};
|
|
4
|
+
export const handleServerFunctions = createServerFunctionHandler({
|
|
5
|
+
initAdminContext,
|
|
6
|
+
transformResult: serializeForRsc
|
|
7
|
+
});
|
|
59
8
|
|
|
60
9
|
//# sourceMappingURL=handleServerFunctions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import { createServerFunctionHandler } from '@payloadcms/ui/utilities/handleServerFunctions'\n\nimport { initAdminContext } from './initAdminContext.server.js'\nimport { serializeForRsc } from './serializeForRsc.js'\n\nexport const handleServerFunctions = createServerFunctionHandler({\n initAdminContext,\n transformResult: serializeForRsc,\n})\n"],"names":["createServerFunctionHandler","initAdminContext","serializeForRsc","handleServerFunctions","transformResult"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,iDAAgD;AAE5F,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,OAAO,MAAMC,wBAAwBH,4BAA4B;IAC/DC;IACAG,iBAAiBF;AACnB,GAAE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ServerAdapter } from 'payload';
|
|
2
|
+
import type { InitAdminContextArgs } from 'payload/internal';
|
|
3
|
+
import './devConfigReload.server.js';
|
|
4
|
+
type TanStackInitAdminContextArgs = {
|
|
5
|
+
serverAdapter?: ServerAdapter;
|
|
6
|
+
} & Omit<InitAdminContextArgs, 'cache' | 'requestURL' | 'serverAdapter'>;
|
|
7
|
+
export declare const initAdminContext: ({ serverAdapter, ...args }: TanStackInitAdminContextArgs) => Promise<import("payload").AdminContext>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=initAdminContext.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initAdminContext.server.d.ts","sourceRoot":"","sources":["../../src/utilities/initAdminContext.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAO5D,OAAO,6BAA6B,CAAA;AAGpC,KAAK,4BAA4B,GAAG;IAClC,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,YAAY,GAAG,eAAe,CAAC,CAAA;AAExE,eAAO,MAAM,gBAAgB,+BAG1B,4BAA4B,4CAK3B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getRequest } from '@tanstack/react-start/server';
|
|
2
|
+
import { initAdminContext as initPayloadAdminContext } from 'payload/internal';
|
|
3
|
+
// Registers the dev reload strategy before `initPayloadAdminContext` can build an instance.
|
|
4
|
+
// Side-effect only, and a no-op outside of dev serve.
|
|
5
|
+
import './devConfigReload.server.js';
|
|
6
|
+
import { tanstackServerAdapter } from './serverAdapter.server.js';
|
|
7
|
+
export const initAdminContext = ({ serverAdapter = tanstackServerAdapter, ...args })=>initPayloadAdminContext({
|
|
8
|
+
...args,
|
|
9
|
+
requestURL: getRequest().url,
|
|
10
|
+
serverAdapter
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=initAdminContext.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/initAdminContext.server.ts"],"sourcesContent":["import type { ServerAdapter } from 'payload'\nimport type { InitAdminContextArgs } from 'payload/internal'\n\nimport { getRequest } from '@tanstack/react-start/server'\nimport { initAdminContext as initPayloadAdminContext } from 'payload/internal'\n\n// Registers the dev reload strategy before `initPayloadAdminContext` can build an instance.\n// Side-effect only, and a no-op outside of dev serve.\nimport './devConfigReload.server.js'\nimport { tanstackServerAdapter } from './serverAdapter.server.js'\n\ntype TanStackInitAdminContextArgs = {\n serverAdapter?: ServerAdapter\n} & Omit<InitAdminContextArgs, 'cache' | 'requestURL' | 'serverAdapter'>\n\nexport const initAdminContext = ({\n serverAdapter = tanstackServerAdapter,\n ...args\n}: TanStackInitAdminContextArgs) =>\n initPayloadAdminContext({\n ...args,\n requestURL: getRequest().url,\n serverAdapter,\n })\n"],"names":["getRequest","initAdminContext","initPayloadAdminContext","tanstackServerAdapter","serverAdapter","args","requestURL","url"],"mappings":"AAGA,SAASA,UAAU,QAAQ,+BAA8B;AACzD,SAASC,oBAAoBC,uBAAuB,QAAQ,mBAAkB;AAE9E,4FAA4F;AAC5F,sDAAsD;AACtD,OAAO,8BAA6B;AACpC,SAASC,qBAAqB,QAAQ,4BAA2B;AAMjE,OAAO,MAAMF,mBAAmB,CAAC,EAC/BG,gBAAgBD,qBAAqB,EACrC,GAAGE,MAC0B,GAC7BH,wBAAwB;QACtB,GAAGG,IAAI;QACPC,YAAYN,aAAaO,GAAG;QAC5BH;IACF,GAAE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RenderableServerComponent } from '@tanstack/react-start/rsc';
|
|
1
2
|
import type { ImportMap, SanitizedConfig } from 'payload';
|
|
2
3
|
import type { AdminPageMetadata } from './meta.js';
|
|
3
4
|
export type LoadAdminPageArgs = {
|
|
@@ -6,10 +7,11 @@ export type LoadAdminPageArgs = {
|
|
|
6
7
|
search?: Record<string, string | string[]>;
|
|
7
8
|
splat?: string;
|
|
8
9
|
};
|
|
10
|
+
type RSCPayload = RenderableServerComponent<React.ReactElement>;
|
|
9
11
|
export type LoadAdminPageResult = {
|
|
10
12
|
_notFound: true;
|
|
11
13
|
routeKey?: string;
|
|
12
|
-
rscPayload?:
|
|
14
|
+
rscPayload?: RSCPayload;
|
|
13
15
|
} | {
|
|
14
16
|
_redirect: string;
|
|
15
17
|
} | {
|
|
@@ -26,15 +28,15 @@ export type LoadAdminPageResult = {
|
|
|
26
28
|
* so search-only changes (e.g. list-view filtering) reconcile in place.
|
|
27
29
|
*/
|
|
28
30
|
routeKey: string;
|
|
29
|
-
rscPayload:
|
|
31
|
+
rscPayload: RSCPayload;
|
|
30
32
|
};
|
|
31
33
|
/**
|
|
32
34
|
* Renders an admin page for TanStack Start and returns a serializable loader
|
|
33
35
|
* result. The framework adapter wraps this in a `createServerFn` that supplies
|
|
34
36
|
* the app's `config` and generated `importMap`.
|
|
35
37
|
*
|
|
36
|
-
* 1.
|
|
37
|
-
* from `@payloadcms/ui`, passing a TanStack-bound `
|
|
38
|
+
* 1. Gets the Payload admin context via the shared `renderRoot` orchestrator
|
|
39
|
+
* from `@payloadcms/ui`, passing a TanStack-bound `initAdminContext`. The injected
|
|
38
40
|
* page-render `ServerAdapter` records navigation intent and throws the
|
|
39
41
|
* framework-agnostic error contract.
|
|
40
42
|
* 2. Pipes the resulting React server tree through `renderServerComponent`
|
|
@@ -51,4 +53,5 @@ export type LoadAdminPageResult = {
|
|
|
51
53
|
* so it's read from the `nav` holder after `renderServerComponent` resolves.
|
|
52
54
|
*/
|
|
53
55
|
export declare function loadAdminPage({ config, importMap, search, splat, }: LoadAdminPageArgs): Promise<LoadAdminPageResult>;
|
|
56
|
+
export {};
|
|
54
57
|
//# sourceMappingURL=loadAdminPage.d.ts.map
|
|
@@ -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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,wBAAsB,aAAa,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA+IlD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getViewportContent } from '@payloadcms/ui/shared';
|
|
2
2
|
import { renderServerComponent } from '@tanstack/react-start/rsc';
|
|
3
3
|
import { getRequestI18n } from './getRequestI18n.server.js';
|
|
4
|
-
import {
|
|
4
|
+
import { initAdminContext } from './initAdminContext.server.js';
|
|
5
5
|
import { createPageRenderServerAdapter } from './serverAdapter.server.js';
|
|
6
6
|
const resolveTitle = (title)=>{
|
|
7
7
|
if (!title) {
|
|
@@ -67,8 +67,8 @@ const resolveTitle = (title)=>{
|
|
|
67
67
|
* result. The framework adapter wraps this in a `createServerFn` that supplies
|
|
68
68
|
* the app's `config` and generated `importMap`.
|
|
69
69
|
*
|
|
70
|
-
* 1.
|
|
71
|
-
* from `@payloadcms/ui`, passing a TanStack-bound `
|
|
70
|
+
* 1. Gets the Payload admin context via the shared `renderRoot` orchestrator
|
|
71
|
+
* from `@payloadcms/ui`, passing a TanStack-bound `initAdminContext`. The injected
|
|
72
72
|
* page-render `ServerAdapter` records navigation intent and throws the
|
|
73
73
|
* framework-agnostic error contract.
|
|
74
74
|
* 2. Pipes the resulting React server tree through `renderServerComponent`
|
|
@@ -101,12 +101,12 @@ const resolveTitle = (title)=>{
|
|
|
101
101
|
const nav = {};
|
|
102
102
|
const pageServerAdapter = createPageRenderServerAdapter(nav);
|
|
103
103
|
let userAgent;
|
|
104
|
-
// `renderRoot` calls `
|
|
104
|
+
// `renderRoot` calls `initAdminContext` itself with its own overrides (query
|
|
105
105
|
// re-nesting, `urlSuffix`, `fallbackLocale`). Forward them, injecting the
|
|
106
106
|
// page-render `ServerAdapter` so `req.server.redirect()` / `.notFound()`
|
|
107
107
|
// is recorded + thrown rather than escaping as raw TanStack nav.
|
|
108
|
-
const
|
|
109
|
-
const result = await
|
|
108
|
+
const boundInitAdminContext = async (args)=>{
|
|
109
|
+
const result = await initAdminContext({
|
|
110
110
|
configPromise: args.configPromise,
|
|
111
111
|
importMap: args.importMap,
|
|
112
112
|
overrides: args.overrides,
|
|
@@ -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
|
|
@@ -142,11 +133,7 @@ const resolveTitle = (title)=>{
|
|
|
142
133
|
const notFoundNode = await renderNotFoundPage({
|
|
143
134
|
config: Promise.resolve(config),
|
|
144
135
|
importMap,
|
|
145
|
-
|
|
146
|
-
configPromise: args.configPromise,
|
|
147
|
-
importMap: args.importMap,
|
|
148
|
-
overrides: args.overrides
|
|
149
|
-
}),
|
|
136
|
+
initAdminContext,
|
|
150
137
|
params: Promise.resolve({
|
|
151
138
|
segments: splatSegments
|
|
152
139
|
}),
|
|
@@ -164,14 +151,15 @@ const resolveTitle = (title)=>{
|
|
|
164
151
|
adminViews: defaultAdminViews,
|
|
165
152
|
config: Promise.resolve(config),
|
|
166
153
|
importMap,
|
|
167
|
-
|
|
168
|
-
|
|
154
|
+
initAdminContext: boundInitAdminContext,
|
|
155
|
+
key: splat ?? '',
|
|
156
|
+
notFound: pageServerAdapter.notFound,
|
|
169
157
|
// `segments` is intentionally `undefined` for the admin root (`/admin`),
|
|
170
158
|
// matching Next's optional catch-all; `renderRoot` handles it at runtime.
|
|
171
159
|
params: Promise.resolve({
|
|
172
160
|
segments
|
|
173
161
|
}),
|
|
174
|
-
redirect,
|
|
162
|
+
redirect: pageServerAdapter.redirect,
|
|
175
163
|
searchParams: Promise.resolve(searchParams)
|
|
176
164
|
});
|
|
177
165
|
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,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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,MAAM,IAAIC,SAASL,QAAQG,kBAAkB,IAAIG,WAAW;gBAC3EN,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,MAAMmC;QACf;QAEA,wEAAwE;QACxE,sEAAsE;QACtE,2DAA2D;QAC3D,MAAMoB,OAAO,MAAMtF,eAAe;YAAEyC;QAAO;QAC3C,MAAMhC,OAAO,MAAMsC,qBAAqB;YACtC6B,YAAY9B;YACZL;YACA6C;YACAf,QAAQ;gBAAErB;YAAS;QACrB;QAEA,OAAO;YACLqC,UAAU;gBACR,GAAG/E,oBAAoBC,KAAK;gBAC5B+E,UAAU1F,mBAAmBwD;YAC/B;YACAoB,UAAU9B,SAAS;YACnB4B;QACF;IACF,EAAE,OAAOiB,KAAK;QACZ,MAAMC,UAAUD,eAAezB,QAAQyB,IAAIC,OAAO,GAAGpE,OAAOmE;QAC5D,IAAIrC,IAAIrB,IAAI,KAAK,cAAc2D,YAAY,aAAa;YACtD,OAAO,MAAMxB;QACf;QACA,IAAId,IAAIrB,IAAI,KAAK,cAAc2D,QAAQC,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAEN,WAAWjC,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 { 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 { initAdminContext } from './initAdminContext.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. Gets the Payload admin context via the shared `renderRoot` orchestrator\n * from `@payloadcms/ui`, passing a TanStack-bound `initAdminContext`. 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 `initAdminContext` 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 boundInitAdminContext: Parameters<typeof renderRoot>[0]['initAdminContext'] = async (\n args,\n ) => {\n const result = await initAdminContext({\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 initAdminContext,\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 initAdminContext: boundInitAdminContext,\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","initAdminContext","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","boundInitAdminContext","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,gBAAgB,QAAQ,+BAA8B;AAC/D,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,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,CAACU,YAC3BA,WACAA,YAAY,OAAOA,aAAa,YAAYX,MAAMC,OAAO,CAACU,SAASG,IAAI,IACrEH,SAASG,IAAI,GACb,EAAE;IACR,MAAMF,QAAQC,SACXX,GAAG,CAAC,CAACY,OACJ,OAAOA,SAAS,WACZ;YAAEC,KAAK;YAAQX,KAAKU;QAAK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C/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"}
|
|
@@ -20,7 +20,7 @@ import * as qs from 'qs-esm';
|
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
22
|
* import { createRouter } from '@tanstack/react-router'
|
|
23
|
-
* import { payloadParseSearch, payloadStringifySearch } from '@payloadcms/tanstack-start'
|
|
23
|
+
* import { payloadParseSearch, payloadStringifySearch } from '@payloadcms/tanstack-start/shared'
|
|
24
24
|
*
|
|
25
25
|
* export function getRouter() {
|
|
26
26
|
* return createRouter({
|
|
@@ -20,7 +20,7 @@ import * as qs from 'qs-esm';
|
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
22
|
* import { createRouter } from '@tanstack/react-router'
|
|
23
|
-
* import { payloadParseSearch, payloadStringifySearch } from '@payloadcms/tanstack-start'
|
|
23
|
+
* import { payloadParseSearch, payloadStringifySearch } from '@payloadcms/tanstack-start/shared'
|
|
24
24
|
*
|
|
25
25
|
* export function getRouter() {
|
|
26
26
|
* return createRouter({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/routerSearch.ts"],"sourcesContent":["import * as qs from 'qs-esm'\n\n/**\n * `parseSearch` for TanStack Router's `createRouter`, required for Payload's\n * admin UI. Pair with {@link payloadStringifySearch}.\n *\n * Payload serializes query state (notably the list-view `where` filter) with\n * `qs` bracket notation — e.g. `?where[or][0][and][0][x][equals]=y`. TanStack\n * Router's default serializer treats each bracketed string as a flat key and\n * JSON-encodes values, so it never round-trips Payload's nested query: every\n * navigation re-encodes the already-encoded value, exponentially nesting it\n * (`[true,\"[true,\\\"[true…\"]`) until the filter is unusable. Parsing and\n * stringifying with `qs` (same options as `payload`/`@payloadcms/ui`) keeps\n * the URL idempotent and the nested `where` intact across navigations.\n *\n * This is a router-global serializer: it applies to every route, not just\n * `/admin`. On your own routes, search values arrive as strings (qs does no\n * JSON type-coercion), so coerce in `validateSearch` (e.g. `Number(...)`) where\n * you need numbers or booleans.\n *\n * @example\n * ```ts\n * import { createRouter } from '@tanstack/react-router'\n * import { payloadParseSearch, payloadStringifySearch } from '@payloadcms/tanstack-start'\n *\n * export function getRouter() {\n * return createRouter({\n * parseSearch: payloadParseSearch,\n * routeTree,\n * stringifySearch: payloadStringifySearch,\n * })\n * }\n * ```\n */\nexport const payloadParseSearch = (searchStr: string) =>\n qs.parse(searchStr, { depth: 10, ignoreQueryPrefix: true })\n\n/**\n * `stringifySearch` for TanStack Router's `createRouter`, required for Payload's\n * admin UI. Pair with {@link payloadParseSearch}; see it for the full rationale.\n */\nexport const payloadStringifySearch = (search: Record<string, unknown>) => {\n const searchStr = qs.stringify(search)\n return searchStr ? `?${searchStr}` : ''\n}\n"],"names":["qs","payloadParseSearch","searchStr","parse","depth","ignoreQueryPrefix","payloadStringifySearch","search","stringify"],"mappings":"AAAA,YAAYA,QAAQ,SAAQ;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,MAAMC,qBAAqB,CAACC,YACjCF,GAAGG,KAAK,CAACD,WAAW;QAAEE,OAAO;QAAIC,mBAAmB;IAAK,GAAE;AAE7D;;;CAGC,GACD,OAAO,MAAMC,yBAAyB,CAACC;IACrC,MAAML,YAAYF,GAAGQ,SAAS,CAACD;IAC/B,OAAOL,YAAY,CAAC,CAAC,EAAEA,WAAW,GAAG;AACvC,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/routerSearch.ts"],"sourcesContent":["import * as qs from 'qs-esm'\n\n/**\n * `parseSearch` for TanStack Router's `createRouter`, required for Payload's\n * admin UI. Pair with {@link payloadStringifySearch}.\n *\n * Payload serializes query state (notably the list-view `where` filter) with\n * `qs` bracket notation — e.g. `?where[or][0][and][0][x][equals]=y`. TanStack\n * Router's default serializer treats each bracketed string as a flat key and\n * JSON-encodes values, so it never round-trips Payload's nested query: every\n * navigation re-encodes the already-encoded value, exponentially nesting it\n * (`[true,\"[true,\\\"[true…\"]`) until the filter is unusable. Parsing and\n * stringifying with `qs` (same options as `payload`/`@payloadcms/ui`) keeps\n * the URL idempotent and the nested `where` intact across navigations.\n *\n * This is a router-global serializer: it applies to every route, not just\n * `/admin`. On your own routes, search values arrive as strings (qs does no\n * JSON type-coercion), so coerce in `validateSearch` (e.g. `Number(...)`) where\n * you need numbers or booleans.\n *\n * @example\n * ```ts\n * import { createRouter } from '@tanstack/react-router'\n * import { payloadParseSearch, payloadStringifySearch } from '@payloadcms/tanstack-start/shared'\n *\n * export function getRouter() {\n * return createRouter({\n * parseSearch: payloadParseSearch,\n * routeTree,\n * stringifySearch: payloadStringifySearch,\n * })\n * }\n * ```\n */\nexport const payloadParseSearch = (searchStr: string) =>\n qs.parse(searchStr, { depth: 10, ignoreQueryPrefix: true })\n\n/**\n * `stringifySearch` for TanStack Router's `createRouter`, required for Payload's\n * admin UI. Pair with {@link payloadParseSearch}; see it for the full rationale.\n */\nexport const payloadStringifySearch = (search: Record<string, unknown>) => {\n const searchStr = qs.stringify(search)\n return searchStr ? `?${searchStr}` : ''\n}\n"],"names":["qs","payloadParseSearch","searchStr","parse","depth","ignoreQueryPrefix","payloadStringifySearch","search","stringify"],"mappings":"AAAA,YAAYA,QAAQ,SAAQ;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,MAAMC,qBAAqB,CAACC,YACjCF,GAAGG,KAAK,CAACD,WAAW;QAAEE,OAAO;QAAIC,mBAAmB;IAAK,GAAE;AAE7D;;;CAGC,GACD,OAAO,MAAMC,yBAAyB,CAACC;IACrC,MAAML,YAAYF,GAAGQ,SAAS,CAACD;IAC/B,OAAOL,YAAY,CAAC,CAAC,EAAEA,WAAW,GAAG;AACvC,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializeForRsc.d.ts","sourceRoot":"","sources":["../../src/utilities/serializeForRsc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializeForRsc.d.ts","sourceRoot":"","sources":["../../src/utilities/serializeForRsc.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE7D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { renderServerComponent } from '@tanstack/react-start/rsc';
|
|
2
|
+
import { setOwnProperty } from 'payload/shared';
|
|
2
3
|
import { createElement, Fragment } from 'react';
|
|
3
4
|
/**
|
|
4
5
|
* Recursively walk a server-function return value and prepare it for transit
|
|
@@ -112,7 +113,11 @@ async function walk(value, cache, ancestors) {
|
|
|
112
113
|
for (const key of Object.keys(obj)){
|
|
113
114
|
const v = await walk(obj[key], cache, ancestors);
|
|
114
115
|
if (v !== undefined) {
|
|
115
|
-
|
|
116
|
+
setOwnProperty({
|
|
117
|
+
key,
|
|
118
|
+
target: result,
|
|
119
|
+
value: v
|
|
120
|
+
});
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
ancestors.delete(obj);
|