Routes migration bug with hybrid convention
elledienne opened this issue · comments
I just run the migration script (npx migrate-flat-routes ./app/routes ./app/v2routes --convention=hybrid
) on my project and realized that there seems to be something odd going on. Below are a couple of examples
I'm happy to provide more info/details if helpful
Hmm.... that does seem odd. Thanks for the example.
Hmm... I just tested against your routes, and it looks fine. Are you sure you're on v0.6.1?
❯ tree app/routes-v1
app/routes-v1
└── resources
├── conversations
│ └── $conversationId.messages.tsx
├── offers
│ ├── calendar-modal.tsx
│ ├── cancel.tsx
│ ├── initial-state.tsx
│ ├── new.tsx
│ └── package-selection-grid.tsx
├── onboarding.tsx
├── openings
│ └── new.tsx
├── packages
│ └── $packageId.tsx
├── payment-info.tsx
├── products
│ ├── channel
│ │ └── index.tsx
│ └── product
│ └── index.tsx
└── requests
├── $requestId.accept.tsx
└── $requestId.reject.tsx
❯ tree app/routes-v2
app/routes-v2
└── resources+
├── conversations+
│ └── $conversationId.messages.tsx
├── offers+
│ ├── calendar-modal.tsx
│ ├── cancel.tsx
│ ├── initial-state.tsx
│ ├── new.tsx
│ └── package-selection-grid.tsx
├── onboarding.tsx
├── openings+
│ └── new.tsx
├── packages+
│ └── $packageId.tsx
├── payment-info.tsx
├── products+
│ ├── channel+
│ │ └── _index.tsx
│ └── product+
│ └── _index.tsx
└── requests+
├── $requestId.accept.tsx
└── $requestId.reject.tsx
I'm going to close this out. Reopen if you're still having issues.
Hmm... I just tested against your routes, and it looks fine. Are you sure you're on v0.6.1?
Interesting - I also did some additional tests and realized the issue is related to the pathless layout the resources
folder is in. See the full folder structure (sorry for not including it earlier)
![image](https://private-user-images.githubusercontent.com/3903093/276240889-512b2d05-b449-4ae6-ada3-567a184d38f4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE5NzM5MjUsIm5iZiI6MTcyMTk3MzYyNSwicGF0aCI6Ii8zOTAzMDkzLzI3NjI0MDg4OS01MTJiMmQwNS1iNDQ5LTRhZTYtYWRhMy01NjdhMTg0ZDM4ZjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjZUMDYwMDI1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTM1MDk1OGFhNjgyMjU2MzlkMDU5YWMyMjA2NTFlYzI0NWI3NzMyMDZkMTcyMzNkMjg4ZDg3MDBhMzYyYTkyOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.5nQ2j87KBkiTArEgKftG5u5tT4HbcugliCZJ8uKCDws)
I can confirm that if I move the resources
folder outside the __index
folder the script works as expected
Ok thanks for providing more information. I'll take a look again.
I was able to reproduce it, so should be able to fix the bug.
app/routes-v2
└── __index+
├── _layout.tsx
├── resources_..tsx
├── resources_.conversations.tsx
├── resources_.offers.tsx
├── resources_.openings.tsx
├── resources_.packages.tsx
├── resources_.products.channel.tsx
├── resources_.products.product.tsx
└── resources_.requests.tsx
I was able to reproduce it, so should be able to fix the bug.
app/routes-v2 └── __index+ ├── _layout.tsx ├── resources_..tsx ├── resources_.conversations.tsx ├── resources_.offers.tsx ├── resources_.openings.tsx ├── resources_.packages.tsx ├── resources_.products.channel.tsx ├── resources_.products.product.tsx └── resources_.requests.tsx
I was looking into the migration script and I think 1 of the issue is related to this code
if (parentId && parentId !== 'root') {
if (routePath?.includes('/')) {
// multi-segment route, so need to fixup parent for flat-routes (trailing _)
// strip parent route from route
let currentPath = routeId.substring(parentId.length + 1)
const [first, ...rest] = getRouteSegments(currentPath, index ?? false)
// rewrite id to use trailing _ for parent
routeId = `${parentId}/${first}_.${rest.join('.')}`
}
}
I think the check should be extended to something like parentId && parentId !== 'root' && !parentId.includes('__')
to exclude pathless routes.
@kiliman does that seem reasonable?
The problem is the call to getRouteSegments()
. That function is expecting the flat-routes convention, not the v1
convention, so some of the assumptions are invalid. I need to create a new version for the migration tool. I should have a fix later today.
This has been fixed in v0.6.2