Skip to content
Source
Sign inSign up
TanStack/router

fix(start-server-core): deserialize tss context when using formdata #5935

Mergedempotts(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/5935/headmerged by schiller-manuel(GitHub profile, opens in a new tab)

Showing 4 changed files with 207 additions and 2 deletions.

x
0 of 4 viewed, 4 left
147 additions and 0 deletionse2e/react-start/server-functions/src/routes/formdata-context.tsxAdded
View file
@@ -0,0 +1,147 @@
+import { createFileRoute } from '@tanstack/react-router'
+import { createMiddleware, createServerFn } from '@tanstack/react-start'
+import React from 'react'
+import { z } from 'zod'
+​
+// Middleware that creates context on client and sends it to server
+const testMiddleware = createMiddleware({ type: 'function' })
+ .client(async ({ next }) => {
+ const testString = 'context-from-middleware-' + Date.now()
+ return next({
+ sendContext: { testString },
+ })
+ })
+ .server(async ({ next, context }) => {
+ if (!context.testString) {
+ throw new Error(
+ 'BUG: testString is missing from server middleware context!',
+ )
+ }
+ return await next({ context: { ...context } })
+ })
+​
+// Server function with FormData
+export const formDataWithContextFn = createServerFn({ method: 'POST' })
+ .middleware([testMiddleware])
+ .inputValidator((data: unknown) => {
+ const formData = z.instanceof(FormData).parse(data)