-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tanstackstart-react): Auto-instrument server function middleware #19001
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: develop
Are you sure you want to change the base?
feat(tanstackstart-react): Auto-instrument server function middleware #19001
Conversation
| } | ||
| default: | ||
| break; | ||
| } |
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.
Switch statement skips server function middleware in start files
Medium Severity
The switch (true) statement treats file types as mutually exclusive. If a file is both a "start file" (isStartFile) AND contains createServerFn().middleware([...]) (isServerFnFile), the case isStartFile: branch matches first and breaks, preventing the server function middleware from being wrapped. The server function middleware in such files would silently fail to be auto-instrumented.
e856eba to
a910011
Compare
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| * Wraps route middleware arrays in createFileRoute() files. | ||
| */ | ||
| export function wrapRouteMiddleware(code: string, id: string, debug: boolean): WrapResult { | ||
| return wrapMiddlewareArrays(code, id, debug, /(middleware)\s*:\s*\[([^\]]*)\]/g); |
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.
Route regex matches destructuring patterns causing invalid output
Low Severity
The wrapRouteMiddleware regex /(middleware)\s*:\s*\[([^\]]*)\]/g matches any middleware: [...] pattern, including JavaScript destructuring assignments. If a route file contains destructuring like const { middleware: [first] } = config;, it gets transformed to const { middleware: wrapMiddlewaresWithSentry({ first }) } = config; which is syntactically invalid JavaScript (function calls cannot appear on the left side of destructuring). This would cause a build failure.
Depends on: #18989 (i.e. no need to review until that is merged)
Follow up to #18844
Extending auto-instrumentation to non-global server function middleware.
TSS function middleware docs
Closes #18847