Skip to content

Conversation

@empotts
Copy link
Contributor

@empotts empotts commented Nov 21, 2025

Fixes #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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

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)
Loading

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.

Possibly related PRs

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 name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring 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 name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately describes the core fix: updating deserialization of TSS context for FormData requests in start-server-core.
Linked Issues check ✅ Passed The 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 ✅ Passed Changes 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 bbce531 and 72c6461.

📒 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bc79c97 and 128800a.

📒 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.

@schiller-manuel
Copy link
Contributor

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

@empotts
Copy link
Contributor Author

empotts commented Nov 21, 2025

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.

@schiller-manuel schiller-manuel changed the title fix(start-server-core) deserialize tss context when using formdata fix(start-server-core): deserialize tss context when using formdata Nov 21, 2025
@nx-cloud
Copy link

nx-cloud bot commented Nov 21, 2025

View your CI Pipeline Execution ↗ for commit 72c6461

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 7m 18s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 23s View ↗

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

@empotts
Copy link
Contributor Author

empotts commented Nov 21, 2025

Anything else I need to add?

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 21, 2025

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

@schiller-manuel schiller-manuel merged commit 2df807e into TanStack:main Nov 22, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client middleware context (sendContext) is not passed to server middleware when a server function accepts FormData.

2 participants