The route-file transform previously required the exported Route binding to be exactly createFileRoute('/path')({...}), so a route wrapped by a higher-order handler (e.g. wrap('x')(createFileRoute('/path')({...}))) was silently left untouched — no route-id injection, no import management.
This change will recursively locate the single nested createFileRoute(path)(options) call within the exported Route init, regardless of any wrapping calls. The wrapper stays opaque to the generator; only the inner constructor call is rewritten. Malformed wrapped routes now surface the same helpful error.
This is proposed as a first step toward unblocking https://github.com/TanStack/router/discussions/7619
Summary by CodeRabbit#
New Features
- Route generation now works with route definitions wrapped in higher-order expressions, preserving wrapper code while updating the route call inside.
- Lazy route handling is now supported even when the route constructor appears within nested wrappers.
Bug Fixes
- Improved error detection for malformed wrapped route definitions.
- Added clearer failures when a wrapped route call is missing required options or contains multiple route constructor calls.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
85054867-4ada-442a-8296-4022044ab7bd📥 Commits
Reviewing files that changed from the base of the PR and between a3e24c35a58d9ac149a05d6321f68aa5d541b6b4 and 6620e350fc1295ddbf3b3995714eb745362bf317.
📒 Files selected for processing (2)
packages/router-generator/src/transform/transform.tspackages/router-generator/tests/transform.test.ts📝 Walkthrough
Walkthrough#
The route-export analyzer in transform.ts now recursively searches wrapper expressions for nested createFileRoute/createLazyFileRoute calls instead of requiring direct initialization. New helper functions replace the prior direct-call detection, and new tests validate wrapped route id injection, lazy swapping, multiple wrappers, and error cases.
Changes#
Higher-order Route Wrapper Support
packages/router-generator/src/transform/transform.tsgetRouteConstructorInitaccepts wider node types; newfindRouteConstructorInitsandcontainsRouteConstructorCallrecursively walk call-expression trees, replacing removedisDirectRouteConstructorCall.packages/router-generator/src/transform/transform.tsfindExportedRouteCallstraverses the full initializer expression to find nested route-constructor calls and distinguishes malformed calls from unsupported/absent ones using the new helpers.packages/router-generator/tests/transform.test.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Sequence Diagram(s)#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
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