Open History to see the last commit
1import { _tanstackInternalsCookie } from './utils'
2import type { FetchFnCtx } from '@tanstack/start'
3import type { ServerFormState } from './types'
4
5export const initialFormState = {
6 errorMap: {
7 onServer: undefined,
8 },
9 errors: [],
10}
11
12export const getFormData = async (ctx: FetchFnCtx) => {
13 const data = (await _tanstackInternalsCookie.parse(
14 ctx.request.headers.get('Cookie'),
15 )) as undefined | ServerFormState<any>
16 // Delete the cookie before it hits the client again¸
17 ctx.request.headers.delete('Cookie')
18 if (!data) return initialFormState
19 return data
20}