fix: incorrect route generation for nested layout routes#1272
fix: incorrect route generation for nested layout routes#1272schiller-manuel merged 12 commits intoTanStack:mainfrom SeanCassiere:SeanCassiere/fix-incorrect-layout-generation
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 52946f7. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
| node.isVirtualParentRequired = | ||
| removeGroups(node.path ?? '') | ||
| .split('') | ||
| .filter((char) => char === '/').length >= 2 && // check that the parent route wouldn't be the root route |
There was a problem hiding this comment.
can the "check that the parent route wouldn't be the root route " be simplified to this?
const node.parent?.parentThere was a problem hiding this comment.
The problem is that this condition never comes to pass.
Since a nested layout route (with no .route.tsx configuration file) wouldn't ever be detected as having a parent route because the routeNodes array wouldn't already have a virtual parent route to link it to.
In the next chunk of code below is where a virtual parent route is created, the current route is added as its child, and the newly created parent node is mapped to the current node's .parent prop.
There was a problem hiding this comment.
There's an alternative that works.
const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0
node.isVirtualParentRequired = node.isLayout
? !cleanedPathIsEmpty && !node.parent
: false…riable segment reducing function
I fully acknowledge that this looks jank... there's no escaping this fact.
Most of it stems from having to short-circuit the
handleNodefunction.Fixes #1150