fix: use createServerFn().validator() instead of deprecated inputValidator#101
Conversation
…dator TanStack Start deprecated createServerFn().inputValidator() in favor of .validator(); the alias emits a compiler warning in consumers' Vite dev. Switch all server functions and actions to .validator(). .validator() only exists from react-start 1.168.25 (start-client-core 1.170.12 / start-plugin-core 1.171.17), so bump the dev deps and raise the peer floor to match. - Switch 9 inputValidator call sites in actions.ts / server-functions.ts - Update createServerFn mocks across the test suite to match - Bump @tanstack/react-start ^1.168.25, react-router ^1.170.15, start-server-core ^1.169.14 (root + example) - Raise peerDependencies @tanstack/react-start to >=1.168.25 - Drop the example's TanStackRouterDevtools panel: the bumped router-core@1.171.13 removed routerState.cachedMatches, which all current router-devtools-core versions still read (crashes the panel) BREAKING CHANGE: requires @tanstack/react-start >=1.168.25, where createServerFn().validator() exists. Consumers on older TanStack Start versions must upgrade. Closes #100
Greptile SummaryThis PR migrates all 9
Confidence Score: 5/5Safe to merge — the change is a straightforward API rename with no logic changes to authentication or session handling. All 9 validator call sites are updated consistently, the test mocks across three spec files are aligned with the new builder shape, and the typecheck + full test suite have passed. The peer dep bump is accurate and well-documented. The only minor gap is that the @tanstack/react-router peer floor was not raised in sync with react-start, but this does not affect the correctness of the library itself. package.json — the @tanstack/react-router peer dep minimum could be tightened to match the implicit floor imposed by @tanstack/react-start@1.168.25. Important Files Changed
|
Defining a startInstance with a custom requestMiddleware list opts an app out of the CSRF middleware TanStack Start applies to server functions by default (createStartHandler only injects defaultCsrfMiddleware when no startInstance exists). Because this SDK requires consumers to register authkitMiddleware in requestMiddleware, every consumer was silently opted out, leaving server-fn RPC endpoints unprotected from cross-site requests (this is the "server functions are not protected by the CSRF middleware" dev warning). - example/src/start.ts: add createCsrfMiddleware (filtered to serverFn, ordered before authkitMiddleware) to restore the protection - README: show createCsrfMiddleware in the setup step and explain why the startInstance opt-out makes it the consumer's responsibility createCsrfMiddleware is a pure header check (Sec-Fetch-Site / Origin / Referer) with no token plumbing and no interaction with the AuthKit session cookie; it's an isomorphic fn that no-ops on the client. Verified: example typecheck + build clean, bundle-leak guard clean, and a fresh dev server's first server-fn RPC request no longer emits the warning.
Summary
Two related fixes for consumers on current TanStack Start (1.168.x+):
#100— switch all server functions/actions off the deprecatedcreateServerFn().inputValidator()to.validator(), which TanStack now flags with a compiler warning in consumers' Vite dev.1.
inputValidator→validator(#100)The deprecation warning consumers see:
All 9 server-function/action call sites now use
.validator().Why this needs a dependency bump
.validator()doesn't exist in the builder until react-start 1.168.25 (which bundlesstart-client-core@1.170.12+start-plugin-core@1.171.17); earlier versions only have.inputValidator(). The deprecation warning consumers see is emitted by their newer TanStack compiler transforming our shippeddist/server/*.js, so the fix has to land in source → dist, and our pinned TanStack had to move so.validator()typechecks.Raises the peer floor to
@tanstack/react-start >=1.168.25. Consumers on older TanStack Start will hit.validator is not a functionat runtime and must upgrade. This is the accurate floor —.validator()simply doesn't exist before it.2. CSRF protection on server functions
TanStack Start protects server-function RPC endpoints with a default CSRF middleware — but only when an app doesn't define its own
startInstance(createStartHandlerinjectsdefaultCsrfMiddlewareonly in the no-startInstancebranch). This SDK requires consumers to registerauthkitMiddlewareincreateStart(() => ({ requestMiddleware: [...] })), which means every consumer takes over the middleware list and is silently opted out of that default — leaving server-fn endpoints unprotected from cross-site requests. That's the source of the dev warning:The warning is accurate, and it's the SDK's own required pattern that triggers it — so we address it rather than suppress it.
createCsrfMiddleware({ filter: (ctx) => ctx.handlerType === 'serverFn' })torequestMiddleware, ordered beforeauthkitMiddleware().authkitMiddlewaremakes CSRF the consumer's responsibility.createCsrfMiddlewareis a pure header check (Sec-Fetch-Site/Origin/Referer) — no token plumbing, no interaction with the AuthKit session cookie, and an isomorphic fn that no-ops on the client. TheserverFnfilter keeps cross-site flows like the WorkOS OAuth callback navigation working.Changes
.inputValidator()→.validator()inactions.ts/server-functions.tscreateServerFnmocks in the test suite to match (4 spots)@tanstack/react-start^1.168.25,react-router^1.170.15,start-server-core^1.169.14(root + example)peerDependencies["@tanstack/react-start"]to>=1.168.25createCsrfMiddlewareto the example'sstart.ts+ document it in the READMETanStackRouterDevtoolspanel (see note below)Note: example devtools removed (unrelated upstream bug)
The router bump pulls
@tanstack/router-core@1.171.13, which removedrouterState.cachedMatches. Every available@tanstack/router-devtools-core(≤1.168.0) still reads that field, so<TanStackRouterDevtools>crashes withcachedMatches is not iterable(client console only — the app works). No devtools version is currently compatible with this router-core (TanStack's ownstart-workosexample is broken the same way). The panel is removed from the example with a comment; the dependency is kept so it can be re-enabled in a 2-line uncomment once upstream catches up.Verification
pnpm typecheck✓pnpm build✓ — shippeddistemits.validator(), zeroinputValidatorpnpm test✓ — 222/222cd example && pnpm typecheck && pnpm build✓ — no deprecation/leak warnings;createCsrfMiddlewareimport +ctx.handlerTypetypecheck cleanpnpm run build:check(bundle-leak guard) ✓ — no server fingerprints in client bundlepnpm lint/pnpm format:check✓distto RPC (.validator(...).handler(createSsrRpc(...)))Closes #100