-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(start): align request handler types with registered server context #7428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9335105
f8692b7
5f68486
088cf49
d3a6b50
ebebc9c
d6b0635
714d5e2
73a9c6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@tanstack/start-client-core': patch | ||
| '@tanstack/start-server-core': patch | ||
| '@tanstack/react-start': patch | ||
| '@tanstack/solid-start': patch | ||
| '@tanstack/vue-start': patch | ||
| --- | ||
|
|
||
| fix(start): align request handler types with registered server context |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,5 @@ | ||
| --- | ||
| ref: docs/start/framework/react/guide/server-entry-point.md | ||
| replace: | ||
| { | ||
| '@tanstack/react-start': '@tanstack/solid-start', | ||
| '@tanstack/react-router': '@tanstack/solid-router', | ||
| 'React': 'SolidJS', | ||
| } | ||
| { '@tanstack/react-start': '@tanstack/solid-start', 'React': 'SolidJS' } | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ import type { | |
| SessionUpdate, | ||
| } from './session' | ||
| import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
| import type { Register } from '@tanstack/start-client-core' | ||
| import type { RequestHandler } from './request-handler' | ||
|
|
||
| interface StartEvent { | ||
|
|
@@ -118,10 +119,13 @@ function attachResponseHeaders<T>( | |
| return value | ||
| } | ||
|
|
||
| export function requestHandler<TRegister = unknown>( | ||
| export function requestHandler<TRegister extends Register = Register>( | ||
| handler: RequestHandler<TRegister>, | ||
| ) { | ||
| return (request: Request, requestOpts: any): Promise<Response> | Response => { | ||
| return (( | ||
| request: Request, | ||
| requestOpts?: any, | ||
| ): Promise<Response> | Response => { | ||
|
Comment on lines
+125
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify unsafe typing in wrapper signatures
rg -n -C2 'requestOpts\?: any|as RequestHandler<|RequestHandlerParameters<' packages/start-server-core/src/request-response.tsRepository: TanStack/router Length of output: 342
In 🤖 Prompt for AI Agents |
||
| let h3Event: H3Event | ||
| try { | ||
| h3Event = new H3Event(request) | ||
|
|
@@ -139,7 +143,7 @@ export function requestHandler<TRegister = unknown>( | |
| handler(request, requestOpts), | ||
| ) | ||
| return h3_toResponse(attachResponseHeaders(response, h3Event), h3Event) | ||
| } | ||
| }) as RequestHandler<TRegister> | ||
| } | ||
|
|
||
| function getH3Event() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/router
Length of output: 398
🏁 Script executed:
Repository: TanStack/router
Length of output: 179
🏁 Script executed:
Repository: TanStack/router
Length of output: 7191
🏁 Script executed:
Repository: TanStack/router
Length of output: 5904
🏁 Script executed:
Repository: TanStack/router
Length of output: 13081
🏁 Script executed:
Repository: TanStack/router
Length of output: 41
🏁 Script executed:
Repository: TanStack/router
Length of output: 1991
🏁 Script executed:
Repository: TanStack/router
Length of output: 6008
Avoid casting
RequestHandler<Register>toRequestHandler<TRegister>increateStartHandlerstartRequestResolveris typed asRequestHandler<Register>withrequestOpts?: RequestOptions<Register>(325-327), butRequestOptions<TRegister>can requirecontextwhenTRegisterdefinesserver.requestContext. Casting the result toRequestHandler<TRegister>(588) masks that constraint from callers.Proposed type-safe fix
🤖 Prompt for AI Agents