@payloadcms/tanstack-start 4.0.0-beta.2 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/adapters/handleServerFunctions.d.ts +2 -1
  2. package/dist/adapters/handleServerFunctions.d.ts.map +1 -1
  3. package/dist/adapters/handleServerFunctions.js +12 -4
  4. package/dist/adapters/handleServerFunctions.js.map +1 -1
  5. package/dist/adapters/layout/RootProviders/index.d.ts +9 -0
  6. package/dist/adapters/layout/RootProviders/index.d.ts.map +1 -0
  7. package/dist/adapters/layout/RootProviders/index.js +21 -0
  8. package/dist/adapters/layout/RootProviders/index.js.map +1 -0
  9. package/dist/adapters/layout/index.d.ts +7 -4
  10. package/dist/adapters/layout/index.d.ts.map +1 -1
  11. package/dist/adapters/layout/index.js +3 -1
  12. package/dist/adapters/layout/index.js.map +1 -1
  13. package/dist/adapters/layout/lazy.d.ts +1 -5
  14. package/dist/adapters/layout/lazy.d.ts.map +1 -1
  15. package/dist/adapters/layout/lazy.js +9 -15
  16. package/dist/adapters/layout/lazy.js.map +1 -1
  17. package/dist/adapters/layout/outlet.d.ts +4 -0
  18. package/dist/adapters/layout/outlet.d.ts.map +1 -0
  19. package/dist/adapters/layout/outlet.js +9 -0
  20. package/dist/adapters/layout/outlet.js.map +1 -0
  21. package/dist/adapters/layout/server.d.ts +7 -13
  22. package/dist/adapters/layout/server.d.ts.map +1 -1
  23. package/dist/adapters/layout/server.js +18 -16
  24. package/dist/adapters/layout/server.js.map +1 -1
  25. package/dist/adapters/views/index.d.ts +5 -2
  26. package/dist/adapters/views/index.d.ts.map +1 -1
  27. package/dist/adapters/views/index.js +10 -4
  28. package/dist/adapters/views/index.js.map +1 -1
  29. package/dist/adapters/views/lazy.js +2 -2
  30. package/dist/adapters/views/lazy.js.map +1 -1
  31. package/dist/adapters/views/server.d.ts +5 -2
  32. package/dist/adapters/views/server.d.ts.map +1 -1
  33. package/dist/adapters/views/server.js +12 -3
  34. package/dist/adapters/views/server.js.map +1 -1
  35. package/dist/exports/client/layout.d.ts +2 -0
  36. package/dist/exports/client/layout.d.ts.map +1 -0
  37. package/dist/exports/client/layout.js +4 -0
  38. package/dist/exports/client/layout.js.map +1 -0
  39. package/dist/exports/client.d.ts +1 -1
  40. package/dist/exports/client.d.ts.map +1 -1
  41. package/dist/exports/client.js +1 -1
  42. package/dist/exports/client.js.map +1 -1
  43. package/dist/exports/server.d.ts +0 -2
  44. package/dist/exports/server.d.ts.map +1 -1
  45. package/dist/exports/server.js +0 -2
  46. package/dist/exports/server.js.map +1 -1
  47. package/dist/utilities/serverFunctionClient.d.ts +2 -23
  48. package/dist/utilities/serverFunctionClient.d.ts.map +1 -1
  49. package/dist/utilities/serverFunctionClient.js +12 -106
  50. package/dist/utilities/serverFunctionClient.js.map +1 -1
  51. package/package.json +16 -16
  52. package/dist/utilities/serializeForRsc.d.ts +0 -26
  53. package/dist/utilities/serializeForRsc.d.ts.map +0 -1
  54. package/dist/utilities/serializeForRsc.js +0 -127
  55. package/dist/utilities/serializeForRsc.js.map +0 -1
  56. package/dist/utilities/toSerializable.d.ts +0 -11
  57. package/dist/utilities/toSerializable.d.ts.map +0 -1
  58. package/dist/utilities/toSerializable.js +0 -127
  59. package/dist/utilities/toSerializable.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { getViewportContent } from '@payloadcms/ui/shared';
2
2
  import { renderServerComponent } from '@tanstack/react-start/rsc';
3
+ import { getRequest } from '@tanstack/react-start/server';
3
4
  import { getRequestI18n } from '../../utilities/getRequestI18n.server.js';
4
5
  import { initAdminContext } from '../../utilities/initAdminContext.server.js';
5
6
  import { toAdminPageMetadata } from '../metadata.js';
@@ -81,7 +82,10 @@ import { createPageRenderServerAdapter } from '../server.js';
81
82
  }),
82
83
  searchParams: Promise.resolve(searchParams)
83
84
  });
84
- const rscPayload = await renderServerComponent(notFoundNode);
85
+ const rscPayload = await renderServerComponent({
86
+ page: notFoundNode,
87
+ routeKey: splat ?? ''
88
+ });
85
89
  return {
86
90
  _notFound: true,
87
91
  routeKey: splat ?? '',
@@ -104,7 +108,10 @@ import { createPageRenderServerAdapter } from '../server.js';
104
108
  redirect: pageServerAdapter.redirect,
105
109
  searchParams: Promise.resolve(searchParams)
106
110
  });
107
- const rscPayload = await renderServerComponent(node);
111
+ const rscPayload = await renderServerComponent({
112
+ page: node,
113
+ routeKey: splat ?? ''
114
+ });
108
115
  // The server-function (client-nav RPC) path returns the flight stream unread —
109
116
  // unlike the router/SSR path, which awaits a decode that drives the render to
110
117
  // completion. So streamed side effects (e.g. DocumentView's autosave-create
@@ -114,7 +121,9 @@ import { createPageRenderServerAdapter } from '../server.js';
114
121
  if (!nav.type) {
115
122
  const wrapper = rscPayload[Symbol.for('tanstack.rsc.stream')];
116
123
  if (typeof wrapper?.createReplayStream === 'function') {
117
- const buffer = await new Response(wrapper.createReplayStream()).arrayBuffer();
124
+ const buffer = await new Response(wrapper.createReplayStream().pipeThrough(new TransformStream(), {
125
+ signal: getRequest().signal
126
+ })).arrayBuffer();
118
127
  wrapper.createReplayStream = ()=>new Response(buffer).body;
119
128
  }
120
129
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapters/views/server.tsx"],"sourcesContent":["import type { RenderableServerComponent } from '@tanstack/react-start/rsc'\nimport type { ImportMap, SanitizedConfig } from 'payload'\n\nimport { getViewportContent } from '@payloadcms/ui/shared'\nimport { renderServerComponent } from '@tanstack/react-start/rsc'\n\nimport type { AdminPageMetadata } from '../metadata.js'\n\nimport { getRequestI18n } from '../../utilities/getRequestI18n.server.js'\nimport { initAdminContext } from '../../utilities/initAdminContext.server.js'\nimport { toAdminPageMetadata } from '../metadata.js'\nimport { createPageRenderServerAdapter } from '../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\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.req.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","toAdminPageMetadata","createPageRenderServerAdapter","loadAdminPage","config","importMap","search","splat","renderRoot","defaultAdminViews","generatePageMetadata","splatSegments","split","filter","Boolean","segments","length","undefined","searchParams","nav","pageServerAdapter","userAgent","boundInitAdminContext","args","result","configPromise","overrides","serverAdapter","req","headers","get","renderNotFound","renderNotFoundPage","notFoundNode","Promise","resolve","params","rscPayload","_notFound","routeKey","node","adminViews","key","notFound","redirect","type","wrapper","Symbol","for","createReplayStream","buffer","Response","arrayBuffer","body","url","_redirect","i18n","meta","metadata","viewport","err","message","Error","String","startsWith","slice"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,wBAAuB;AAC1D,SAASC,qBAAqB,QAAQ,4BAA2B;AAIjE,SAASC,cAAc,QAAQ,2CAA0C;AACzE,SAASC,gBAAgB,QAAQ,6CAA4C;AAC7E,SAASC,mBAAmB,QAAQ,iBAAgB;AACpD,SAASC,6BAA6B,QAAQ,eAAc;AA+B5D;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,eAAeC,cAAc,EAClCC,MAAM,EACNC,SAAS,EACTC,MAAM,EACNC,KAAK,EACa;IAClB,MAAM,EAAEC,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC;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AAEK;QAAO;QAC3C,MAAMqD,OAAO,MAAM/C,qBAAqB;YACtC+B,YAAYhC;YACZL;YACAoD;YACApB,QAAQ;gBAAErB;YAAS;QACrB;QAEA,OAAO;YACL2C,UAAU;gBACR,GAAGzD,oBAAoBwD,KAAK;gBAC5BE,UAAU9D,mBAAmBwB;YAC/B;YACAkB,UAAUhC,SAAS;YACnB8B;QACF;IACF,EAAE,OAAOuB,KAAK;QACZ,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAGE,OAAOH;QAC5D,IAAIzC,IAAI0B,IAAI,KAAK,cAAcgB,YAAY,aAAa;YACtD,OAAO,MAAM9B;QACf;QACA,IAAIZ,IAAI0B,IAAI,KAAK,cAAcgB,QAAQG,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAET,WAAWpC,IAAImC,GAAG,IAAIO,QAAQI,KAAK,CAAC,YAAYjD,MAAM;YAAE;QACnE;QACA,MAAM4C;IACR;AACF"}
1
+ {"version":3,"sources":["../../../src/adapters/views/server.tsx"],"sourcesContent":["import type { RenderableServerComponentBuilder } from '@tanstack/react-start/rsc'\nimport type { ImportMap, SanitizedConfig } from 'payload'\n\nimport { getViewportContent } from '@payloadcms/ui/shared'\nimport { renderServerComponent } from '@tanstack/react-start/rsc'\nimport { getRequest } from '@tanstack/react-start/server'\n\nimport type { AdminPageMetadata } from '../metadata.js'\n\nimport { getRequestI18n } from '../../utilities/getRequestI18n.server.js'\nimport { initAdminContext } from '../../utilities/initAdminContext.server.js'\nimport { toAdminPageMetadata } from '../metadata.js'\nimport { createPageRenderServerAdapter } from '../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 = RenderableServerComponentBuilder<{\n page: React.ReactElement\n routeKey: string\n}>\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\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.req.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({\n page: notFoundNode as React.ReactElement,\n routeKey: splat ?? '',\n })\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({\n page: node as React.ReactElement,\n routeKey: splat ?? '',\n })\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(\n wrapper.createReplayStream().pipeThrough(new TransformStream(), {\n signal: getRequest().signal,\n }),\n ).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","getRequest","getRequestI18n","initAdminContext","toAdminPageMetadata","createPageRenderServerAdapter","loadAdminPage","config","importMap","search","splat","renderRoot","defaultAdminViews","generatePageMetadata","splatSegments","split","filter","Boolean","segments","length","undefined","searchParams","nav","pageServerAdapter","userAgent","boundInitAdminContext","args","result","configPromise","overrides","serverAdapter","req","headers","get","renderNotFound","renderNotFoundPage","notFoundNode","Promise","resolve","params","rscPayload","page","routeKey","_notFound","node","adminViews","key","notFound","redirect","type","wrapper","Symbol","for","createReplayStream","buffer","Response","pipeThrough","TransformStream","signal","arrayBuffer","body","url","_redirect","i18n","meta","metadata","viewport","err","message","Error","String","startsWith","slice"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,wBAAuB;AAC1D,SAASC,qBAAqB,QAAQ,4BAA2B;AACjE,SAASC,UAAU,QAAQ,+BAA8B;AAIzD,SAASC,cAAc,QAAQ,2CAA0C;AACzE,SAASC,gBAAgB,QAAQ,6CAA4C;AAC7E,SAASC,mBAAmB,QAAQ,iBAAgB;AACpD,SAASC,6BAA6B,QAAQ,eAAc;AAkC5D;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,eAAeC,cAAc,EAClCC,MAAM,EACNC,SAAS,EACTC,MAAM,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,IAAIuC,GAAG,EAAE;YACtC,OAAO;gBAAEC,WAAWxC,IAAIuC,GAAG;YAAC;QAC9B;QACA,IAAIvC,IAAI2B,IAAI,KAAK,YAAY;YAC3B,OAAO,MAAMf;QACf;QAEA,wEAAwE;QACxE,sEAAsE;QACtE,2DAA2D;QAC3D,MAAM6B,OAAO,MAAM7D,eAAe;YAAEK;QAAO;QAC3C,MAAMyD,OAAO,MAAMnD,qBAAqB;YACtCgC,YAAYjC;YACZL;YACAwD;YACAxB,QAAQ;gBAAErB;YAAS;QACrB;QAEA,OAAO;YACL+C,UAAU;gBACR,GAAG7D,oBAAoB4D,KAAK;gBAC5BE,UAAUnE,mBAAmByB;YAC/B;YACAkB,UAAUhC,SAAS;YACnB8B;QACF;IACF,EAAE,OAAO2B,KAAK;QACZ,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAGE,OAAOH;QAC5D,IAAI7C,IAAI2B,IAAI,KAAK,cAAcmB,YAAY,aAAa;YACtD,OAAO,MAAMlC;QACf;QACA,IAAIZ,IAAI2B,IAAI,KAAK,cAAcmB,QAAQG,UAAU,CAAC,cAAc;YAC9D,OAAO;gBAAET,WAAWxC,IAAIuC,GAAG,IAAIO,QAAQI,KAAK,CAAC,YAAYrD,MAAM;YAAE;QACnE;QACA,MAAMgD;IACR;AACF"}
@@ -0,0 +1,2 @@
1
+ export { PayloadRootProviders } from '../../adapters/layout/RootProviders/index.js';
2
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/exports/client/layout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAA"}
@@ -0,0 +1,4 @@
1
+ 'use client';
2
+ export { PayloadRootProviders } from '../../adapters/layout/RootProviders/index.js';
3
+
4
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/exports/client/layout.ts"],"sourcesContent":["'use client'\n\nexport { PayloadRootProviders } from '../../adapters/layout/RootProviders/index.js'\n"],"names":["PayloadRootProviders"],"mappings":"AAAA;AAEA,SAASA,oBAAoB,QAAQ,+CAA8C"}
@@ -1,4 +1,4 @@
1
1
  export { type LayoutLoad, PayloadAdminShell, type PayloadAdminShellProps, payloadLayoutRoute, withPayloadRoot, type WithPayloadRootOptions, } from '../adapters/layout/index.js';
2
2
  export { type AdminLoad, payloadAdminIndexRoute, payloadAdminSplatRoute, } from '../adapters/views/index.js';
3
- export { createServerFunctionClient, stripUnserializable, } from '../utilities/serverFunctionClient.js';
3
+ export { createServerFunctionClient } from '../utilities/serverFunctionClient.js';
4
4
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,UAAU,EACf,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,kBAAkB,EAClB,eAAe,EACf,KAAK,sBAAsB,GAC5B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,KAAK,SAAS,EACd,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,sCAAsC,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,UAAU,EACf,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,kBAAkB,EAClB,eAAe,EACf,KAAK,sBAAsB,GAC5B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,KAAK,SAAS,EACd,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAA"}
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  export { PayloadAdminShell, payloadLayoutRoute, withPayloadRoot } from '../adapters/layout/index.js';
3
3
  export { payloadAdminIndexRoute, payloadAdminSplatRoute } from '../adapters/views/index.js';
4
- export { createServerFunctionClient, stripUnserializable } from '../utilities/serverFunctionClient.js';
4
+ export { createServerFunctionClient } from '../utilities/serverFunctionClient.js';
5
5
 
6
6
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["'use client'\n\nexport {\n type LayoutLoad,\n PayloadAdminShell,\n type PayloadAdminShellProps,\n payloadLayoutRoute,\n withPayloadRoot,\n type WithPayloadRootOptions,\n} from '../adapters/layout/index.js'\nexport {\n type AdminLoad,\n payloadAdminIndexRoute,\n payloadAdminSplatRoute,\n} from '../adapters/views/index.js'\nexport {\n createServerFunctionClient,\n stripUnserializable,\n} from '../utilities/serverFunctionClient.js'\n"],"names":["PayloadAdminShell","payloadLayoutRoute","withPayloadRoot","payloadAdminIndexRoute","payloadAdminSplatRoute","createServerFunctionClient","stripUnserializable"],"mappings":"AAAA;AAEA,SAEEA,iBAAiB,EAEjBC,kBAAkB,EAClBC,eAAe,QAEV,8BAA6B;AACpC,SAEEC,sBAAsB,EACtBC,sBAAsB,QACjB,6BAA4B;AACnC,SACEC,0BAA0B,EAC1BC,mBAAmB,QACd,uCAAsC"}
1
+ {"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["'use client'\n\nexport {\n type LayoutLoad,\n PayloadAdminShell,\n type PayloadAdminShellProps,\n payloadLayoutRoute,\n withPayloadRoot,\n type WithPayloadRootOptions,\n} from '../adapters/layout/index.js'\nexport {\n type AdminLoad,\n payloadAdminIndexRoute,\n payloadAdminSplatRoute,\n} from '../adapters/views/index.js'\nexport { createServerFunctionClient } from '../utilities/serverFunctionClient.js'\n"],"names":["PayloadAdminShell","payloadLayoutRoute","withPayloadRoot","payloadAdminIndexRoute","payloadAdminSplatRoute","createServerFunctionClient"],"mappings":"AAAA;AAEA,SAEEA,iBAAiB,EAEjBC,kBAAkB,EAClBC,eAAe,QAEV,8BAA6B;AACpC,SAEEC,sBAAsB,EACtBC,sBAAsB,QACjB,6BAA4B;AACnC,SAASC,0BAA0B,QAAQ,uCAAsC"}
@@ -9,7 +9,5 @@ export { handleGraphQL } from '../routes/graphql/handler.server.js';
9
9
  export { handleAPIRoute } from '../routes/rest/handler.server.js';
10
10
  export { payloadApiHandlers } from '../routes/rest/index.js';
11
11
  export { getRequestI18n } from '../utilities/getRequestI18n.server.js';
12
- export { serializeForRsc } from '../utilities/serializeForRsc.js';
13
- export { type SerializableRecord, toSerializable } from '../utilities/toSerializable.js';
14
12
  export { getRequestTheme } from '@payloadcms/ui/utilities/getRequestTheme';
15
13
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/exports/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,KAAK,iBAAiB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,EACL,6BAA6B,EAC7B,KAAK,aAAa,EAClB,qBAAqB,GACtB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,EAAE,KAAK,kBAAkB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/exports/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,KAAK,iBAAiB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,EACL,6BAA6B,EAC7B,KAAK,aAAa,EAClB,qBAAqB,GACtB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAA"}
@@ -9,8 +9,6 @@ export { handleGraphQL } from '../routes/graphql/handler.server.js';
9
9
  export { handleAPIRoute } from '../routes/rest/handler.server.js';
10
10
  export { payloadApiHandlers } from '../routes/rest/index.js';
11
11
  export { getRequestI18n } from '../utilities/getRequestI18n.server.js';
12
- export { serializeForRsc } from '../utilities/serializeForRsc.js';
13
- export { toSerializable } from '../utilities/toSerializable.js';
14
12
  export { getRequestTheme } from '@payloadcms/ui/utilities/getRequestTheme';
15
13
 
16
14
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/server.ts"],"sourcesContent":["export { handleServerFunctions } from '../adapters/handleServerFunctions.js'\nexport { type AdminPageMetadata, getAdminMeta } from '../adapters/metadata.js'\nexport {\n createPageRenderServerAdapter,\n type PageNavIntent,\n tanstackServerAdapter,\n} from '../adapters/server.js'\nexport {\n loadAdminPage,\n type LoadAdminPageArgs,\n type LoadAdminPageResult,\n} from '../adapters/views/server.js'\nexport { login } from '../auth/login.js'\nexport { logout } from '../auth/logout.js'\nexport { refresh } from '../auth/refresh.js'\nexport { handleGraphQL } from '../routes/graphql/handler.server.js'\nexport { handleAPIRoute } from '../routes/rest/handler.server.js'\nexport { payloadApiHandlers } from '../routes/rest/index.js'\nexport { getRequestI18n } from '../utilities/getRequestI18n.server.js'\nexport { serializeForRsc } from '../utilities/serializeForRsc.js'\nexport { type SerializableRecord, toSerializable } from '../utilities/toSerializable.js'\nexport { getRequestTheme } from '@payloadcms/ui/utilities/getRequestTheme'\n"],"names":["handleServerFunctions","getAdminMeta","createPageRenderServerAdapter","tanstackServerAdapter","loadAdminPage","login","logout","refresh","handleGraphQL","handleAPIRoute","payloadApiHandlers","getRequestI18n","serializeForRsc","toSerializable","getRequestTheme"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,uCAAsC;AAC5E,SAAiCC,YAAY,QAAQ,0BAAyB;AAC9E,SACEC,6BAA6B,EAE7BC,qBAAqB,QAChB,wBAAuB;AAC9B,SACEC,aAAa,QAGR,8BAA6B;AACpC,SAASC,KAAK,QAAQ,mBAAkB;AACxC,SAASC,MAAM,QAAQ,oBAAmB;AAC1C,SAASC,OAAO,QAAQ,qBAAoB;AAC5C,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,cAAc,QAAQ,wCAAuC;AACtE,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAAkCC,cAAc,QAAQ,iCAAgC;AACxF,SAASC,eAAe,QAAQ,2CAA0C"}
1
+ {"version":3,"sources":["../../src/exports/server.ts"],"sourcesContent":["export { handleServerFunctions } from '../adapters/handleServerFunctions.js'\nexport { type AdminPageMetadata, getAdminMeta } from '../adapters/metadata.js'\nexport {\n createPageRenderServerAdapter,\n type PageNavIntent,\n tanstackServerAdapter,\n} from '../adapters/server.js'\nexport {\n loadAdminPage,\n type LoadAdminPageArgs,\n type LoadAdminPageResult,\n} from '../adapters/views/server.js'\nexport { login } from '../auth/login.js'\nexport { logout } from '../auth/logout.js'\nexport { refresh } from '../auth/refresh.js'\nexport { handleGraphQL } from '../routes/graphql/handler.server.js'\nexport { handleAPIRoute } from '../routes/rest/handler.server.js'\nexport { payloadApiHandlers } from '../routes/rest/index.js'\nexport { getRequestI18n } from '../utilities/getRequestI18n.server.js'\nexport { getRequestTheme } from '@payloadcms/ui/utilities/getRequestTheme'\n"],"names":["handleServerFunctions","getAdminMeta","createPageRenderServerAdapter","tanstackServerAdapter","loadAdminPage","login","logout","refresh","handleGraphQL","handleAPIRoute","payloadApiHandlers","getRequestI18n","getRequestTheme"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,uCAAsC;AAC5E,SAAiCC,YAAY,QAAQ,0BAAyB;AAC9E,SACEC,6BAA6B,EAE7BC,qBAAqB,QAChB,wBAAuB;AAC9B,SACEC,aAAa,QAGR,8BAA6B;AACpC,SAASC,KAAK,QAAQ,mBAAkB;AACxC,SAASC,MAAM,QAAQ,oBAAmB;AAC1C,SAASC,OAAO,QAAQ,qBAAoB;AAC5C,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,cAAc,QAAQ,wCAAuC;AACtE,SAASC,eAAe,QAAQ,2CAA0C"}
@@ -1,29 +1,8 @@
1
1
  import type { ServerFunctionClient, ServerFunctionClientArgs } from 'payload';
2
- /**
3
- * Builds the client-side `ServerFunctionClient` wired into
4
- * `RootProvider.serverFunction`, given the app's `createServerFn`-based
5
- * dispatcher (`runServerFn`).
6
- *
7
- * Strips functions / symbols / RegExps / React elements from the args before
8
- * dispatching: the previous `fetch + JSON.stringify` pipeline silently dropped
9
- * those, but TanStack Start's seroval-based wire format errors instead. We
10
- * mirror the relaxed behaviour so existing callers (e.g. `getFormState` in
11
- * `ServerFunctionsProvider`) that may pass the live form state — which can
12
- * carry stray functions — keep working without each call site sanitising.
13
- *
14
- * Delegates to `runServerFn`, so the response (including any RSC handles for
15
- * server-rendered custom components) is decoded by TanStack Start back into
16
- * renderable React nodes on the client.
17
- */
2
+ /** Builds the admin dispatcher with native Flight response decoding. */
18
3
  export declare function createServerFunctionClient({ runServerFn, }: {
19
4
  runServerFn: (input: {
20
5
  data: ServerFunctionClientArgs;
21
- }) => Promise<unknown>;
6
+ }) => Promise<Response>;
22
7
  }): ServerFunctionClient;
23
- /**
24
- * Recursively removes values TanStack Start's seroval wire format cannot
25
- * serialize (functions, symbols, RegExps, React elements, cyclic refs) and
26
- * normalizes `Date` subclasses to plain `Date`.
27
- */
28
- export declare function stripUnserializable(value: unknown, cache?: WeakMap<object, unknown>, ancestors?: WeakSet<object>): unknown;
29
8
  //# sourceMappingURL=serverFunctionClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serverFunctionClient.d.ts","sourceRoot":"","sources":["../../src/utilities/serverFunctionClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAI7E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,wBAAwB,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC7E,GAAG,oBAAoB,CAKvB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAiB,EAC/C,SAAS,GAAE,OAAO,CAAC,MAAM,CAAiB,GACzC,OAAO,CA4FT"}
1
+ {"version":3,"file":"serverFunctionClient.d.ts","sourceRoot":"","sources":["../../src/utilities/serverFunctionClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAE7E,wEAAwE;AACxE,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,wBAAwB,CAAA;KAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC9E,GAAG,oBAAoB,CAoBvB"}
@@ -1,114 +1,20 @@
1
- import { setOwnProperty } from 'payload/shared';
2
- /**
3
- * Builds the client-side `ServerFunctionClient` wired into
4
- * `RootProvider.serverFunction`, given the app's `createServerFn`-based
5
- * dispatcher (`runServerFn`).
6
- *
7
- * Strips functions / symbols / RegExps / React elements from the args before
8
- * dispatching: the previous `fetch + JSON.stringify` pipeline silently dropped
9
- * those, but TanStack Start's seroval-based wire format errors instead. We
10
- * mirror the relaxed behaviour so existing callers (e.g. `getFormState` in
11
- * `ServerFunctionsProvider`) that may pass the live form state — which can
12
- * carry stray functions — keep working without each call site sanitising.
13
- *
14
- * Delegates to `runServerFn`, so the response (including any RSC handles for
15
- * server-rendered custom components) is decoded by TanStack Start back into
16
- * renderable React nodes on the client.
17
- */ export function createServerFunctionClient({ runServerFn }) {
1
+ /** Builds the admin dispatcher with native Flight response decoding. */ export function createServerFunctionClient({ runServerFn }) {
18
2
  return async (args)=>{
19
- const safeArgs = stripUnserializable(args);
20
- return await runServerFn({
21
- data: safeArgs
3
+ const response = await runServerFn({
4
+ data: args
22
5
  });
23
- };
24
- }
25
- /**
26
- * Recursively removes values TanStack Start's seroval wire format cannot
27
- * serialize (functions, symbols, RegExps, React elements, cyclic refs) and
28
- * normalizes `Date` subclasses to plain `Date`.
29
- */ export function stripUnserializable(value, cache = new WeakMap(), ancestors = new WeakSet()) {
30
- if (value === null || value === undefined) {
31
- return value;
32
- }
33
- const t = typeof value;
34
- if (t === 'function' || t === 'symbol') {
35
- return undefined;
36
- }
37
- if (t !== 'object') {
38
- return value;
39
- }
40
- const obj = value;
41
- if (typeof obj.$$typeof === 'symbol') {
42
- return undefined;
43
- }
44
- if (ancestors.has(obj)) {
45
- return undefined;
46
- }
47
- if (cache.has(obj)) {
48
- return cache.get(obj);
49
- }
50
- if (obj instanceof Date) {
51
- // Normalize to a plain `Date`. Subclasses (e.g. `@date-fns/tz`'s `TZDate`,
52
- // used by the schedule-publish drawer) are `instanceof Date` but have a
53
- // different `constructor`, which TanStack Start's seroval serializer
54
- // rejects with "The value [object Date] ... cannot be parsed/serialized".
55
- return new Date(obj.getTime());
56
- }
57
- if (obj instanceof RegExp) {
58
- return undefined;
59
- }
60
- ancestors.add(obj);
61
- if (obj instanceof Map) {
62
- const cleaned = new Map();
63
- cache.set(obj, cleaned);
64
- for (const [k, v] of obj){
65
- const cv = stripUnserializable(v, cache, ancestors);
66
- if (cv !== undefined) {
67
- cleaned.set(k, cv);
68
- }
6
+ if (!response.ok) {
7
+ throw new Error(`Payload server function failed with status ${response.status}`);
69
8
  }
70
- ancestors.delete(obj);
71
- return cleaned;
72
- }
73
- if (obj instanceof Set) {
74
- const cleaned = new Set();
75
- cache.set(obj, cleaned);
76
- for (const v of obj){
77
- const cv = stripUnserializable(v, cache, ancestors);
78
- if (cv !== undefined) {
79
- cleaned.add(cv);
80
- }
9
+ if (response.headers.get('content-type')?.split(';')[0]?.trim() !== 'text/x-component') {
10
+ throw new Error('Expected a React Flight response from the Payload server function');
81
11
  }
82
- ancestors.delete(obj);
83
- return cleaned;
84
- }
85
- if (Array.isArray(obj)) {
86
- const arr = [];
87
- cache.set(obj, arr);
88
- for (const item of obj){
89
- arr.push(stripUnserializable(item, cache, ancestors));
12
+ if (!response.body) {
13
+ throw new Error('The Payload server function returned an empty Flight response');
90
14
  }
91
- ancestors.delete(obj);
92
- return arr;
93
- }
94
- if (ArrayBuffer.isView(obj)) {
95
- ancestors.delete(obj);
96
- return obj;
97
- }
98
- const result = {};
99
- cache.set(obj, result);
100
- for (const key of Object.keys(obj)){
101
- const v = stripUnserializable(obj[key], cache, ancestors);
102
- if (v !== undefined) {
103
- setOwnProperty({
104
- key,
105
- target: result,
106
- value: v
107
- });
108
- }
109
- }
110
- ancestors.delete(obj);
111
- return result;
15
+ const { createFromReadableStream } = await import('@tanstack/react-start/rsc');
16
+ return await createFromReadableStream(response.body);
17
+ };
112
18
  }
113
19
 
114
20
  //# sourceMappingURL=serverFunctionClient.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/serverFunctionClient.ts"],"sourcesContent":["import type { ServerFunctionClient, ServerFunctionClientArgs } from 'payload'\n\nimport { setOwnProperty } from 'payload/shared'\n\n/**\n * Builds the client-side `ServerFunctionClient` wired into\n * `RootProvider.serverFunction`, given the app's `createServerFn`-based\n * dispatcher (`runServerFn`).\n *\n * Strips functions / symbols / RegExps / React elements from the args before\n * dispatching: the previous `fetch + JSON.stringify` pipeline silently dropped\n * those, but TanStack Start's seroval-based wire format errors instead. We\n * mirror the relaxed behaviour so existing callers (e.g. `getFormState` in\n * `ServerFunctionsProvider`) that may pass the live form state — which can\n * carry stray functions — keep working without each call site sanitising.\n *\n * Delegates to `runServerFn`, so the response (including any RSC handles for\n * server-rendered custom components) is decoded by TanStack Start back into\n * renderable React nodes on the client.\n */\nexport function createServerFunctionClient({\n runServerFn,\n}: {\n runServerFn: (input: { data: ServerFunctionClientArgs }) => Promise<unknown>\n}): ServerFunctionClient {\n return (async (args: ServerFunctionClientArgs) => {\n const safeArgs = stripUnserializable(args) as ServerFunctionClientArgs\n return await runServerFn({ data: safeArgs })\n }) as ServerFunctionClient\n}\n\n/**\n * Recursively removes values TanStack Start's seroval wire format cannot\n * serialize (functions, symbols, RegExps, React elements, cyclic refs) and\n * normalizes `Date` subclasses to plain `Date`.\n */\nexport function stripUnserializable(\n value: unknown,\n cache: WeakMap<object, unknown> = new WeakMap(),\n ancestors: WeakSet<object> = new WeakSet(),\n): unknown {\n if (value === null || value === undefined) {\n return value\n }\n\n const t = typeof value\n if (t === 'function' || t === 'symbol') {\n return undefined\n }\n if (t !== 'object') {\n return value\n }\n\n const obj = value as Record<string, unknown>\n\n if (typeof obj.$$typeof === 'symbol') {\n return undefined\n }\n\n if (ancestors.has(obj)) {\n return undefined\n }\n\n if (cache.has(obj)) {\n return cache.get(obj)\n }\n\n if (obj instanceof Date) {\n // Normalize to a plain `Date`. Subclasses (e.g. `@date-fns/tz`'s `TZDate`,\n // used by the schedule-publish drawer) are `instanceof Date` but have a\n // different `constructor`, which TanStack Start's seroval serializer\n // rejects with \"The value [object Date] ... cannot be parsed/serialized\".\n return new Date(obj.getTime())\n }\n\n if (obj instanceof RegExp) {\n return undefined\n }\n\n ancestors.add(obj)\n\n if (obj instanceof Map) {\n const cleaned = new Map()\n cache.set(obj, cleaned)\n for (const [k, v] of obj) {\n const cv = stripUnserializable(v, cache, ancestors)\n if (cv !== undefined) {\n cleaned.set(k, cv)\n }\n }\n ancestors.delete(obj)\n return cleaned\n }\n\n if (obj instanceof Set) {\n const cleaned = new Set()\n cache.set(obj, cleaned)\n for (const v of obj) {\n const cv = stripUnserializable(v, cache, ancestors)\n if (cv !== undefined) {\n cleaned.add(cv)\n }\n }\n ancestors.delete(obj)\n return cleaned\n }\n\n if (Array.isArray(obj)) {\n const arr: unknown[] = []\n cache.set(obj, arr)\n for (const item of obj) {\n arr.push(stripUnserializable(item, cache, ancestors))\n }\n ancestors.delete(obj)\n return arr\n }\n\n if (ArrayBuffer.isView(obj)) {\n ancestors.delete(obj)\n return obj\n }\n\n const result: Record<string, unknown> = {}\n cache.set(obj, result)\n for (const key of Object.keys(obj)) {\n const v = stripUnserializable(obj[key], cache, ancestors)\n if (v !== undefined) {\n setOwnProperty({ key, target: result, value: v })\n }\n }\n ancestors.delete(obj)\n return result\n}\n"],"names":["setOwnProperty","createServerFunctionClient","runServerFn","args","safeArgs","stripUnserializable","data","value","cache","WeakMap","ancestors","WeakSet","undefined","t","obj","$$typeof","has","get","Date","getTime","RegExp","add","Map","cleaned","set","k","v","cv","delete","Set","Array","isArray","arr","item","push","ArrayBuffer","isView","result","key","Object","keys","target"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAE/C;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,2BAA2B,EACzCC,WAAW,EAGZ;IACC,OAAQ,OAAOC;QACb,MAAMC,WAAWC,oBAAoBF;QACrC,OAAO,MAAMD,YAAY;YAAEI,MAAMF;QAAS;IAC5C;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASC,oBACdE,KAAc,EACdC,QAAkC,IAAIC,SAAS,EAC/CC,YAA6B,IAAIC,SAAS;IAE1C,IAAIJ,UAAU,QAAQA,UAAUK,WAAW;QACzC,OAAOL;IACT;IAEA,MAAMM,IAAI,OAAON;IACjB,IAAIM,MAAM,cAAcA,MAAM,UAAU;QACtC,OAAOD;IACT;IACA,IAAIC,MAAM,UAAU;QAClB,OAAON;IACT;IAEA,MAAMO,MAAMP;IAEZ,IAAI,OAAOO,IAAIC,QAAQ,KAAK,UAAU;QACpC,OAAOH;IACT;IAEA,IAAIF,UAAUM,GAAG,CAACF,MAAM;QACtB,OAAOF;IACT;IAEA,IAAIJ,MAAMQ,GAAG,CAACF,MAAM;QAClB,OAAON,MAAMS,GAAG,CAACH;IACnB;IAEA,IAAIA,eAAeI,MAAM;QACvB,2EAA2E;QAC3E,wEAAwE;QACxE,qEAAqE;QACrE,0EAA0E;QAC1E,OAAO,IAAIA,KAAKJ,IAAIK,OAAO;IAC7B;IAEA,IAAIL,eAAeM,QAAQ;QACzB,OAAOR;IACT;IAEAF,UAAUW,GAAG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MAAM,CAACd;IACjB,OAAOuB;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/serverFunctionClient.ts"],"sourcesContent":["import type { ServerFunctionClient, ServerFunctionClientArgs } from 'payload'\n\n/** Builds the admin dispatcher with native Flight response decoding. */\nexport function createServerFunctionClient({\n runServerFn,\n}: {\n runServerFn: (input: { data: ServerFunctionClientArgs }) => Promise<Response>\n}): ServerFunctionClient {\n return (async (args: ServerFunctionClientArgs) => {\n const response = await runServerFn({ data: args })\n\n if (!response.ok) {\n throw new Error(`Payload server function failed with status ${response.status}`)\n }\n\n if (response.headers.get('content-type')?.split(';')[0]?.trim() !== 'text/x-component') {\n throw new Error('Expected a React Flight response from the Payload server function')\n }\n\n if (!response.body) {\n throw new Error('The Payload server function returned an empty Flight response')\n }\n\n const { createFromReadableStream } = await import('@tanstack/react-start/rsc')\n\n return await createFromReadableStream(response.body)\n }) as ServerFunctionClient\n}\n"],"names":["createServerFunctionClient","runServerFn","args","response","data","ok","Error","status","headers","get","split","trim","body","createFromReadableStream"],"mappings":"AAEA,sEAAsE,GACtE,OAAO,SAASA,2BAA2B,EACzCC,WAAW,EAGZ;IACC,OAAQ,OAAOC;QACb,MAAMC,WAAW,MAAMF,YAAY;YAAEG,MAAMF;QAAK;QAEhD,IAAI,CAACC,SAASE,EAAE,EAAE;YAChB,MAAM,IAAIC,MAAM,CAAC,2CAA2C,EAAEH,SAASI,MAAM,EAAE;QACjF;QAEA,IAAIJ,SAASK,OAAO,CAACC,GAAG,CAAC,iBAAiBC,MAAM,IAAI,CAAC,EAAE,EAAEC,WAAW,oBAAoB;YACtF,MAAM,IAAIL,MAAM;QAClB;QAEA,IAAI,CAACH,SAASS,IAAI,EAAE;YAClB,MAAM,IAAIN,MAAM;QAClB;QAEA,MAAM,EAAEO,wBAAwB,EAAE,GAAG,MAAM,MAAM,CAAC;QAElD,OAAO,MAAMA,yBAAyBV,SAASS,IAAI;IACrD;AACF"}
package/package.json CHANGED
@@ -1,13 +1,8 @@
1
1
  {
2
2
  "name": "@payloadcms/tanstack-start",
3
- "version": "4.0.0-beta.2",
3
+ "version": "4.0.0-beta.3",
4
4
  "description": "TanStack Start framework adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/payloadcms/payload.git",
9
- "directory": "packages/tanstack-start"
10
- },
11
6
  "license": "MIT",
12
7
  "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
13
8
  "maintainers": [
@@ -17,7 +12,17 @@
17
12
  "url": "https://payloadcms.com"
18
13
  }
19
14
  ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/payloadcms/payload.git",
18
+ "directory": "packages/tanstack-start"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
20
23
  "type": "module",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
21
26
  "exports": {
22
27
  ".": {
23
28
  "import": "./dist/index.js",
@@ -51,17 +56,12 @@
51
56
  "default": "./dist/exports/rsc.js"
52
57
  }
53
58
  },
54
- "main": "./dist/index.js",
55
- "types": "./dist/index.d.ts",
56
- "files": [
57
- "dist"
58
- ],
59
59
  "dependencies": {
60
60
  "graphql-http": "1.22.4",
61
61
  "qs-esm": "^7.0.2",
62
- "@payloadcms/graphql": "4.0.0-beta.2",
63
- "@payloadcms/translations": "4.0.0-beta.2",
64
- "@payloadcms/ui": "4.0.0-beta.2"
62
+ "@payloadcms/translations": "4.0.0-beta.3",
63
+ "@payloadcms/graphql": "4.0.0-beta.3",
64
+ "@payloadcms/ui": "4.0.0-beta.3"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@tanstack/react-router": "^1.170.44",
@@ -73,7 +73,7 @@
73
73
  "react": "19.3.1",
74
74
  "react-dom": "19.3.1",
75
75
  "vite": ">=8.0.0",
76
- "payload": "4.0.0-beta.2"
76
+ "payload": "4.0.0-beta.3"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@tanstack/react-router": "^1.170.44",
@@ -84,7 +84,7 @@
84
84
  "react": "^19.0.0",
85
85
  "react-dom": "^19.0.0",
86
86
  "vite": ">=8.0.0",
87
- "payload": "4.0.0-beta.2"
87
+ "payload": "4.0.0-beta.3"
88
88
  },
89
89
  "peerDependenciesMeta": {
90
90
  "@vitejs/plugin-react": {
@@ -1,26 +0,0 @@
1
- /**
2
- * Recursively walk a server-function return value and prepare it for transit
3
- * to the client as an RSC payload.
4
- *
5
- * Mirrors `toSerializable`'s walk (Maps, Sets, Dates, typed arrays, circular
6
- * refs) with two key differences:
7
- *
8
- * 1. React elements are NOT stripped. They are passed through
9
- * `renderServerComponent` from `@tanstack/react-start/rsc` to produce a
10
- * "renderable RSC handle". TanStack Start's `$RSC` serialization adapter
11
- * streams the underlying Flight payload to the client, where it is
12
- * decoded back into a renderable React node. This matches the way
13
- * Next.js's RSC payload format ships React elements over server actions
14
- * and lets server-rendered custom field components (e.g. those returned
15
- * by `buildFormState` / `RenderServerComponent`) survive a `form-state`
16
- * round trip.
17
- *
18
- * 2. Functions, Symbols, and RegExps are still stripped — TanStack's seroval
19
- * transport cannot handle them, and Payload doesn't intentionally include
20
- * them in server-function return values.
21
- *
22
- * Use this in `createServerFn` handlers that return Payload form/view state
23
- * containing React elements (e.g. `state[path].customComponents.Field`).
24
- */
25
- export declare function serializeForRsc<T>(value: T): Promise<T>;
26
- //# sourceMappingURL=serializeForRsc.d.ts.map
@@ -1 +0,0 @@
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,127 +0,0 @@
1
- import { renderServerComponent } from '@tanstack/react-start/rsc';
2
- import { setOwnProperty } from 'payload/shared';
3
- import { createElement, Fragment } from 'react';
4
- /**
5
- * Recursively walk a server-function return value and prepare it for transit
6
- * to the client as an RSC payload.
7
- *
8
- * Mirrors `toSerializable`'s walk (Maps, Sets, Dates, typed arrays, circular
9
- * refs) with two key differences:
10
- *
11
- * 1. React elements are NOT stripped. They are passed through
12
- * `renderServerComponent` from `@tanstack/react-start/rsc` to produce a
13
- * "renderable RSC handle". TanStack Start's `$RSC` serialization adapter
14
- * streams the underlying Flight payload to the client, where it is
15
- * decoded back into a renderable React node. This matches the way
16
- * Next.js's RSC payload format ships React elements over server actions
17
- * and lets server-rendered custom field components (e.g. those returned
18
- * by `buildFormState` / `RenderServerComponent`) survive a `form-state`
19
- * round trip.
20
- *
21
- * 2. Functions, Symbols, and RegExps are still stripped — TanStack's seroval
22
- * transport cannot handle them, and Payload doesn't intentionally include
23
- * them in server-function return values.
24
- *
25
- * Use this in `createServerFn` handlers that return Payload form/view state
26
- * containing React elements (e.g. `state[path].customComponents.Field`).
27
- */ export async function serializeForRsc(value) {
28
- return await walk(value, new WeakMap(), new WeakSet());
29
- }
30
- async function walk(value, cache, ancestors) {
31
- if (value === null || value === undefined) {
32
- return value;
33
- }
34
- const t = typeof value;
35
- if (t === 'function' || t === 'symbol') {
36
- return undefined;
37
- }
38
- if (t !== 'object') {
39
- return value;
40
- }
41
- const obj = value;
42
- if (typeof obj.$$typeof === 'symbol') {
43
- return await renderServerComponent(value);
44
- }
45
- if (ancestors.has(obj)) {
46
- return undefined;
47
- }
48
- if (cache.has(obj)) {
49
- return cache.get(obj);
50
- }
51
- if (obj instanceof Date) {
52
- return obj;
53
- }
54
- if (obj instanceof RegExp) {
55
- return undefined;
56
- }
57
- ancestors.add(obj);
58
- if (obj instanceof Map) {
59
- const cleaned = new Map();
60
- cache.set(obj, cleaned);
61
- for (const [k, v] of obj){
62
- const cv = await walk(v, cache, ancestors);
63
- if (cv !== undefined) {
64
- cleaned.set(k, cv);
65
- }
66
- }
67
- ancestors.delete(obj);
68
- return cleaned;
69
- }
70
- if (obj instanceof Set) {
71
- const cleaned = new Set();
72
- cache.set(obj, cleaned);
73
- for (const v of obj){
74
- const cv = await walk(v, cache, ancestors);
75
- if (cv !== undefined) {
76
- cleaned.add(cv);
77
- }
78
- }
79
- ancestors.delete(obj);
80
- return cleaned;
81
- }
82
- if (Array.isArray(obj)) {
83
- // An array consisting entirely of React elements (e.g. a field's
84
- // `beforeInput` / `afterInput` component list, produced by
85
- // `RenderServerComponent`) must be rendered as a SINGLE RSC handle.
86
- // Converting each element individually below turns every item into its own
87
- // `renderServerComponent` handle, which drops the element's React `key` —
88
- // the client then renders `{[handle, handle]}` as unkeyed array children
89
- // and React warns "Each child in a list should have a unique key prop".
90
- // Payload always renders these component arrays wholesale (`{BeforeInput}`),
91
- // so collapsing them into one Fragment-rendered handle is render-equivalent
92
- // and keeps the per-element keys intact inside the single Flight payload.
93
- const items = obj.filter((item)=>item !== null && item !== undefined);
94
- const isReactElementArray = items.length > 0 && items.every((item)=>typeof item === 'object' && typeof item.$$typeof === 'symbol');
95
- if (isReactElementArray) {
96
- ancestors.delete(obj);
97
- return await renderServerComponent(createElement(Fragment, null, ...obj));
98
- }
99
- const arr = [];
100
- cache.set(obj, arr);
101
- for (const item of obj){
102
- arr.push(await walk(item, cache, ancestors));
103
- }
104
- ancestors.delete(obj);
105
- return arr;
106
- }
107
- if (ArrayBuffer.isView(obj)) {
108
- ancestors.delete(obj);
109
- return obj;
110
- }
111
- const result = {};
112
- cache.set(obj, result);
113
- for (const key of Object.keys(obj)){
114
- const v = await walk(obj[key], cache, ancestors);
115
- if (v !== undefined) {
116
- setOwnProperty({
117
- key,
118
- target: result,
119
- value: v
120
- });
121
- }
122
- }
123
- ancestors.delete(obj);
124
- return result;
125
- }
126
-
127
- //# sourceMappingURL=serializeForRsc.js.map