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

Issue with layouts conflicting #29

Closed
JClackett opened this issue Dec 20, 2022 · 5 comments
Closed

Issue with layouts conflicting #29

JClackett opened this issue Dec 20, 2022 · 5 comments

Comments

@JClackett
Copy link

JClackett commented Dec 20, 2022

Hey,

Mentioned this in a discussion but thought it would be best to create a separate issue.

After upgrading to 0.5.2 from 0.4.8, and using remix 1.9.0, my routes aren't valid apparently anymore

Here is my file structure, have removed a load to show the problem ones:

├── admin._index.tsx
├── admin.artists.$id._profile._index.tsx
├── admin.artists.$id._profile.episodes
├── admin.artists.$id._profile.shows.tsx
├── admin.artists.$id._profile.ts    <-layout
├── admin.artists.$id.episodes.new.tsx
├── admin.artists.$id.episodes.tsx    <-layout
├── admin.artists.$id.shows.$showId._profile._index.tsx
├── admin.artists.$id.shows.$showId._profile.tsx   <-layout
├── admin.artists.$id.shows.$showId.tsx    <-layout
├── admin.artists.$id.shows.tsx
├── admin.artists.$id.tsx   <-layout
├── admin.tsx

1.
Error: Path "/admin/artists/:id" defined by route "pages/admin.artists.$id._profile" conflicts with route "pages/admin.artists.$id"

2.
Error: Path "/admin/artists/:id/shows/:showId" defined by route "pages/admin.artists.$id.shows.$showId._profile" conflicts with route "pages/admin.artists.$id.shows.$showId"

3.
Error: Path "/admin/artists/:id/episodes" defined by route "pages/admin.artists.$id.episodes" conflicts with route "pages/admin.artists.$id._profile.episodes"

4.
Error: Path "/admin/artists/:id/shows" defined by route "pages/admin.artists.$id.shows" conflicts with route "pages/admin.artists.$id._profile.shows"

As mentioned this was working before, so wondering what's changed and what I would need to do to fix?

Thanks!

@JClackett JClackett changed the title Issue with two layouts conflicting Issue with layouts conflicting Dec 20, 2022
@kiliman
Copy link
Owner

kiliman commented Dec 20, 2022

Ok, I reorganized your routes to make it easier to visualize.

├── admin.tsx <- layout
├── admin._index.tsx.   /admin/ 

├── admin.artists.$id.tsx   <-layout
├── admin.artists.$id._profile.ts    <-layout
├── admin.artists.$id._profile._index.tsx. /admin/artists/:id
├── admin.artists.$id._profile.episodes.   /admin/artists/:id/episodes
├── admin.artists.$id._profile.shows.tsx.  /admin/artists/:id/shows

├── admin.artists.$id.episodes.tsx    <-layout 
├── admin.artists.$id.episodes.new.tsx.    /admin/artists/:id/episodes/new

├── admin.artists.$id.shows.tsx
├── admin.artists.$id.shows.$showId.tsx    <-layout
├── admin.artists.$id.shows.$showId._profile.tsx   <-layout
├── admin.artists.$id.shows.$showId._profile._index.tsx /admin/artists/:id/shows/:showId/

I think your routes are getting messed up due to this new uniqueness check that I copied over from the Remix default convention.

let index = childRoute.index
let fullPath = childRoute.path
let uniqueRouteId = (fullPath || '') + (index ? '?index' : '')

if (uniqueRouteId) {
  if (uniqueRoutes.has(uniqueRouteId)) {
    throw new Error(
      `Path ${JSON.stringify(fullPath)} defined by route ${JSON.stringify(
        childRoute.id,
      )} conflicts with route ${JSON.stringify(
        uniqueRoutes.get(uniqueRouteId),
      )}`,
    )
  } else {
    uniqueRoutes.set(uniqueRouteId, childRoute.id)
  }
}

Once I comment out that code, it works correctly

<Routes>
  <Route file="root.tsx">
    <Route path="admin" file="routes-29/admin.tsx">
      <Route path="artists/:id" file="routes-29/admin.artists.$id.tsx">
        <Route file="routes-29/admin.artists.$id._profile.tsx">
          <Route path="episodes" file="routes-29/admin.artists.$id._profile.episodes.tsx" />
          <Route path="shows" file="routes-29/admin.artists.$id._profile.shows.tsx" />
          <Route index file="routes-29/admin.artists.$id._profile._index.tsx" />
        </Route>
        <Route path="episodes" file="routes-29/admin.artists.$id.episodes.tsx">
          <Route path="new" file="routes-29/admin.artists.$id.episodes.new.tsx" />
        </Route>
        <Route path="shows" file="routes-29/admin.artists.$id.shows.tsx">
          <Route path=":showId" file="routes-29/admin.artists.$id.shows.$showId.tsx">
            <Route file="routes-29/admin.artists.$id.shows.$showId._profile.tsx">
              <Route index file="routes-29/admin.artists.$id.shows.$showId._profile._index.tsx" />
            </Route>
          </Route>
        </Route>
      </Route>
      <Route index file="routes-29/admin._index.tsx" />
    </Route>
  </Route>
</Routes>

So I need to decide whether I should include that code or get rid of it.

@kiliman
Copy link
Owner

kiliman commented Dec 20, 2022

I think for now, until I know better what that code is supposed to do, I'll add an option to disable uniqueness checking... at least it will unblock you.

@kiliman
Copy link
Owner

kiliman commented Dec 20, 2022

This has been deployed as v0.5.3

To opt out of the uniqueness check, set enableUniqueIdCheck false.

module.exports = {
  ignoredRouteFiles: ['**/*'],
  routes: async defineRoutes => {
    return flatRoutes('routes', defineRoutes, {
      enableUniqueIdCheck: false,
    })
  },
}

@JClackett
Copy link
Author

Legend, thanks man

@JClackett
Copy link
Author

JClackett commented Jan 2, 2023

Hey @kiliman, going back to this, I noticed that if I try and nest all those admin routes into a admin+ folder, the "_profile" layout is now not picked up (let me know if I should create a separate issue for this)

I see that the files nested under _profile have been moved up to the above "layout", assuming its because _profile uses the _ prefix or something?

File structure

app/pages/admin+
├── _index.tsx
├── _layout.tsx
├── artists.$id._profile._index.tsx
├── artists.$id._profile.episodes.tsx
├── artists.$id._profile.shows.tsx
├── artists.$id._profile.tsx
├── artists.$id.episodes.$episodeId.tsx
├── artists.$id.episodes.new.tsx
├── artists.$id.episodes.tsx
├── artists.$id.shows.$showId._profile._index.tsx
├── artists.$id.shows.$showId._profile.episodes.tsx
├── artists.$id.shows.$showId._profile.tsx
├── artists.$id.shows.$showId.episodes.$episodeId.tsx
├── artists.$id.shows.$showId.episodes.new.tsx
├── artists.$id.shows.$showId.episodes.tsx
├── artists.$id.shows.$showId.tsx
├── artists.$id.shows.new.tsx
├── artists.$id.shows.tsx
├── artists.$id.tsx
├── artists._index.tsx
├── artists.new.tsx
└── episodes.tsx

Remix Routes

<Route path="admin" file="pages/admin+/_layout.tsx">
	<Route path="artists/:id" file="pages/admin+/artists.$id._profile.tsx" />
	<Route path="artists/:id" file="pages/admin+/artists.$id.tsx">
		<Route path="episodes" file="pages/admin+/artists.$id._profile.episodes.tsx" />
		<Route path="shows" file="pages/admin+/artists.$id._profile.shows.tsx" />
		<Route path="episodes" file="pages/admin+/artists.$id.episodes.tsx">
			<Route path=":episodeId" file="pages/admin+/artists.$id.episodes.$episodeId.tsx" />
			<Route path="new" file="pages/admin+/artists.$id.episodes.new.tsx" />
		</Route>
		<Route path="shows" file="pages/admin+/artists.$id.shows.tsx">
			<Route path=":showId" file="pages/admin+/artists.$id.shows.$showId._profile.tsx" />
			<Route path=":showId" file="pages/admin+/artists.$id.shows.$showId.tsx">
				<Route path="episodes" file="pages/admin+/artists.$id.shows.$showId._profile.episodes.tsx" />
				<Route path="episodes" file="pages/admin+/artists.$id.shows.$showId.episodes.tsx">
					<Route path=":episodeId" file="pages/admin+/artists.$id.shows.$showId.episodes.$episodeId.tsx" />
					<Route path="new" file="pages/admin+/artists.$id.shows.$showId.episodes.new.tsx" />
				</Route>
				<Route index file="pages/admin+/artists.$id.shows.$showId._profile._index.tsx" />
			</Route>
			<Route path="new" file="pages/admin+/artists.$id.shows.new.tsx" />
		</Route>
		<Route index file="pages/admin+/artists.$id._profile._index.tsx" />
	</Route>
	<Route path="artists/new" file="pages/admin+/artists.new.tsx" />
	<Route path="episodes" file="pages/admin+/episodes.tsx" />
	<Route index file="pages/admin+/_index.tsx" />
	<Route path="artists/" index file="pages/admin+/artists._index.tsx" />
</Route>

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

No branches or pull requests

2 participants