-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
performance: no reactivity on the server #6497
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
Changes from all commits
c413b04
3cc2a4f
af6a1d5
bbd0562
db465e1
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,18 @@ | ||
| import { batch as storeBatch } from '@tanstack/store' | ||
|
|
||
| import { isServer } from '@tanstack/router-core/isServer' | ||
|
|
||
| // `@tanstack/store`'s `batch` is for reactive notification batching. | ||
| // On the server we don't subscribe/render reactively, so a lightweight | ||
| // implementation that just executes is enough. | ||
| export function batch<T>(fn: () => T): T { | ||
| if (isServer) { | ||
| return fn() | ||
| } | ||
|
|
||
| let result!: T | ||
| storeBatch(() => { | ||
| result = fn() | ||
| }) | ||
|
Comment on lines
+5
to
+16
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: fd -a -t f 'isServer\.(ts|tsx|js|mjs|cjs)$' | head -n 20Repository: TanStack/router Length of output: 41 🏁 Script executed: rg -t ts -t tsx 'isServer' packages/router-core/src/utils/batch.ts -B 10 -A 5Repository: TanStack/router Length of output: 86 🏁 Script executed: rg 'isServer' packages/router-core/src/utils/batch.ts -B 10 -A 5Repository: TanStack/router Length of output: 482 🏁 Script executed: rg -l 'isServer' packages/router-core/src --type ts | head -20Repository: TanStack/router Length of output: 426 🏁 Script executed: fd -t f . packages/router-core/src/isServer | sortRepository: TanStack/router Length of output: 195 🏁 Script executed: cat packages/router-core/src/utils.ts | head -100Repository: TanStack/router Length of output: 2732 🏁 Script executed: rg 'export.*isServer' packages/router-core/src/isServer/Repository: TanStack/router Length of output: 309 🏁 Script executed: rg 'options.*isServer|isServer.*option' packages/router-core/src --type ts -B 3 -A 3Repository: TanStack/router Length of output: 956 🏁 Script executed: rg 'batch\(' packages/router-core/src --type ts -B 3 -A 3 | head -60Repository: TanStack/router Length of output: 3336 🏁 Script executed: cat packages/router-core/package.json | rg -A 20 'exports' | head -40Repository: TanStack/router Length of output: 584 🏁 Script executed: rg 'isServer' packages/router-core/package.jsonRepository: TanStack/router Length of output: 1818 🏁 Script executed: rg -A 50 '"./isServer"' packages/router-core/package.json | head -80Repository: TanStack/router Length of output: 1628 🏁 Script executed: rg 'new Router\|createRouter' packages/router-core/src --type ts -B 3 -A 5 | head -40Repository: TanStack/router Length of output: 41 🏁 Script executed: rg 'options\.isServer\s*[=:]|isServer\s*:\s*' packages/router-core/src --type ts -B 2 -A 2Repository: TanStack/router Length of output: 295 🏁 Script executed: rg 'isServer.*undefined|development' packages/router-core/src -B 2 -A 2 | head -30Repository: TanStack/router Length of output: 1697 🏁 Script executed: rg 'batch\(' packages/router-core/src -B 5 -A 5 | grep -A 5 -B 5 'this\.isServer\|router\.'Repository: TanStack/router Length of output: 3417 Verify that
🤖 Prompt for AI Agents |
||
| return result | ||
| } | ||
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: 41
🏁 Script executed:
Repository: TanStack/router
Length of output: 5763
🏁 Script executed:
Repository: TanStack/router
Length of output: 667
🏁 Script executed:
Repository: TanStack/router
Length of output: 1499
🏁 Script executed:
Repository: TanStack/router
Length of output: 41
🏁 Script executed:
Repository: TanStack/router
Length of output: 230
🏁 Script executed:
Repository: TanStack/router
Length of output: 41
🏁 Script executed:
Repository: TanStack/router
Length of output: 417
🏁 Script executed:
Repository: TanStack/router
Length of output: 1183
🏁 Script executed:
Repository: TanStack/router
Length of output: 1191
🏁 Script executed:
Repository: TanStack/router
Length of output: 720
Unsound Store cast weakens type safety for the server store.
createServerStorereturnsRouterStateStore<TState>but is coerced toStore<any>via cast, which hides the type mismatch and violates TypeScript strict mode requirements. While current usage only calls.stateand.setState()(both implemented inRouterStateStore), the cast removes compiler protections. Per coding guidelines requiring extensive type safety, change__storetoRouterStateStore<RouterState<TRouteTree>>and remove the cast.♻️ Proposed refactor
🤖 Prompt for AI Agents