Skip to content
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

fix: incorrect route generation for nested layout routes #1272

Merged
merged 12 commits into from
Mar 8, 2024
Merged

fix: incorrect route generation for nested layout routes #1272

merged 12 commits into from
Mar 8, 2024

Conversation

SeanCassiere
Copy link
Member

@SeanCassiere SeanCassiere commented Mar 7, 2024

I fully acknowledge that this looks jank... there's no escaping this fact.
Most of it stems from having to short-circuit the handleNode function.

Fixes #1150

Copy link

nx-cloud bot commented Mar 7, 2024

☁️ Nx Cloud Report

CI 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 target

Sent 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the "check that the parent route wouldn't be the root route " be simplified to this?

const node.parent?.parent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

@SeanCassiere SeanCassiere Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an alternative that works.

const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0
node.isVirtualParentRequired = node.isLayout
      ? !cleanedPathIsEmpty && !node.parent
      : false

@schiller-manuel schiller-manuel marked this pull request as ready for review March 8, 2024 09:42
@schiller-manuel schiller-manuel merged commit 52afeee into TanStack:main Mar 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Layout in folder doesn't work
2 participants