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)

Fixes https://github.com/TanStack/router/issues/5913 where the client TSS_CONTEXT is not deserialized when using formdata

Summary by CodeRabbit

  • New Features

    • Added a FormData context test route with a UI to invoke two server actions and view results.
  • Refactor

    • Improved server-side context deserialization for more reliable context handling (no public API changes).
  • Tests

    • Added end-to-end tests verifying context propagation for FormData and simple server actions.
✏️ Tip: You can customize this high-level summary in your review settings.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-server-core

    2. Walkthrough

      Replaces ad-hoc JSON parsing of a serialized middleware context with seroval plugin-based deserialization in the server handler, and adds a new FormData-driven test route + UI and an e2e test that verifies client middleware context propagation when sending FormData.

      Changes

      Cohort / File(s)Summary
      Context deserialization refactor
      packages/start-server-core/src/server-functions-handler.ts
      Replace JSON.parse + shallow merge with seroval.fromJSON (with plugins) to deserialize serializedContext into deserializedContext, then merge into params.context only if non-null. No public signature changes.
      FormData test route & UI
      e2e/react-start/server-functions/src/routes/formdata-context.tsx
      Add a new route component with client middleware that sends context, two server functions (formDataWithContextFn, simpleTestFn) that read middleware context, and UI controls to invoke and display results.
      Route tree registration
      e2e/react-start/server-functions/src/routeTree.gen.ts
      Register new FormdataContextRoute and wire it into all route mapping exports and TanStack Router module declarations.
      End-to-end test
      e2e/react-start/server-functions/tests/server-functions.spec.ts
      Add E2E test validating that client middleware context is delivered to server middleware when invoking a server function with FormData and when invoking a simple function. (Note: test block appears duplicated in the diff.)

      Sequence Diagram(s)

      sequenceDiagram
        autonumber
        participant Browser
        participant ClientMiddleware
        participant Fetch(FormData)
        participant ServerHandler
        participant Seroval
        participant ServerMiddleware
        participant ServerFunction
      
        Browser->>ClientMiddleware: run client middleware -> sendContext(testString)
        ClientMiddleware->>Fetch(FormData): create FormData + attach serializedContext
        Fetch(FormData)->>ServerHandler: POST with FormData + serializedContext
        ServerHandler->>Seroval: fromJSON(serializedContext, plugins)
        Seroval-->>ServerHandler: deserializedContext
        ServerHandler->>ServerMiddleware: invoke with merged context
        ServerMiddleware->>ServerFunction: call function (context available)
        ServerFunction-->>Browser: JSON response (includes context/testString)

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      • Verify seroval.fromJSON usage and plugin list match serialization encoding.
      • Confirm conditional merge logic doesn't lose falsy-but-valid context values.
      • Review new route typing/declaration additions and module augmentation.
      • Inspect added e2e test for duplication and potential flakiness.
      • TanStack/router#5501 — Modifies payload/context deserialization in server-functions-handler.ts; touches the same deserialization area.
      • TanStack/router#5896 — Integrates serialization adapter wiring into start options/getRouter flow; related to server function serialization handling.
      • TanStack/router#5276 — Also edits handleServerAction in server-functions-handler.ts (raw-response/header handling), overlapping the same handler surface.

      Suggested reviewers

      • schiller-manuel
      • chorobin

      Poem

      🐰 I nibbled bytes and stitched a thread, Seroval woke where JSON fled. FormData carried my small song, Middleware hummed — it wasn’t long. Hops and tests — the fix is strong. 🎉

      Pre-merge checks and finishing touches

      ❌ Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.You can run @coderabbitai generate docstrings to improve docstring coverage.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedTitle accurately describes the core fix: updating deserialization of TSS context for FormData requests in start-server-core.
      Linked Issues check✅ PassedThe PR fixes the linked issue #5913 by updating context deserialization in server-functions-handler.ts to use seroval plugins for proper FormData context handling.
      Out of Scope Changes check✅ PassedChanges include the core fix in server-functions-handler.ts plus comprehensive e2e test coverage (new route, server functions, and test assertions), all aligned with resolving the FormData context issue.
      ✨ Finishing touches
      • 📝 Generate docstrings
        🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment

      📜 Recent review details

      Configuration used: CodeRabbit UI

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between bbce531be34b05ef195ad47af387def7d0eb1946 and 72c64619400586214a76ed6753aa2eda85992c03.

      📒 Files selected for processing (3)
      • e2e/react-start/server-functions/src/routes/formdata-context.tsx (1 hunks)
      • e2e/react-start/server-functions/tests/server-functions.spec.ts (1 hunks)
      • packages/start-server-core/src/server-functions-handler.ts (1 hunks)
      🚧 Files skipped from review as they are similar to previous changes (3)
      • packages/start-server-core/src/server-functions-handler.ts
      • e2e/react-start/server-functions/src/routes/formdata-context.tsx
      • e2e/react-start/server-functions/tests/server-functions.spec.ts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    3. Actionable comments posted: 0

      🧹 Nitpick comments (1)
      packages/start-server-core/src/server-functions-handler.ts (1)

      95-95: Consider logging deserialization errors for debugging.

      The empty catch block silently swallows errors during context deserialization. While this provides fail-safe behavior (falling back to the original context), adding a debug log would aid troubleshooting.

      Apply this diff to add error logging:

      -            } catch {}
      +            } catch (error) {
      +              console.debug('Failed to deserialize FormData context:', error)
      +            }
      📜 Review details

      Configuration used: CodeRabbit UI

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between bc79c9783b86e92f4eb5749c9a96d526f86bd54b and 128800ab96662f5342b79452b14587596741b547.

      📒 Files selected for processing (1)
      • packages/start-server-core/src/server-functions-handler.ts (1 hunks)
      🔇 Additional comments (1)
      packages/start-server-core/src/server-functions-handler.ts (1)

      91-93: LGTM! Proper deserialization with seroval plugins.

      The use of fromJSON with seroval plugins correctly deserializes the context, enabling support for complex types (Dates, Maps, Sets, etc.) that JSON.parse alone cannot handle. This brings the FormData context deserialization in line with the parsePayload function used elsewhere in the code.

    4. thanks! we should also add a testcase to the e2e server functions test

    5. thanks! we should also add a testcase to the e2e server functions test

      Added a test similar to my reproducer and ran it. Seems to work along with the other tests.

    6. View your CI Pipeline Execution ↗ for commit 72c64619400586214a76ed6753aa2eda85992c03

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded7m 18sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded23sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-11-22 00:05:25 UTC

    7. Anything else I need to add?

    8. More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5935

      @tanstack/directive-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5935

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5935

      @tanstack/history

      npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5935

      @tanstack/nitro-v2-vite-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5935

      @tanstack/react-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5935

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5935

      @tanstack/react-router-ssr-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5935

      @tanstack/react-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5935

      @tanstack/react-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5935

      @tanstack/react-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5935

      @tanstack/router-cli

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5935

      @tanstack/router-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5935

      @tanstack/router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5935

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5935

      @tanstack/router-generator

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5935

      @tanstack/router-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5935

      @tanstack/router-ssr-query-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5935

      @tanstack/router-utils

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5935

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5935

      @tanstack/server-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5935

      @tanstack/solid-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5935

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5935

      @tanstack/solid-router-ssr-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5935

      @tanstack/solid-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5935

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5935

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5935

      @tanstack/start-client-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5935

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5935

      @tanstack/start-server-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5935

      @tanstack/start-static-server-functions

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5935

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5935

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5935

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5935

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5935

      commit: 72c6461

Sign in to join this conversation.