Skip to content

Using route("/", "routes/home.tsx") messes up auto-generated types, creating a type error #13182

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

Closed
alexanderson1993 opened this issue Mar 7, 2025 · 11 comments · Fixed by #13499

Comments

@alexanderson1993
Copy link
Contributor

I'm using React Router as a...

framework

Reproduction

Go to https://stackblitz.com/edit/github-t35rc7ny?file=app%2Froutes.ts
Note the route has been changed from index to route('/'...
In the command line, run npm run typecheck

System Info

System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 104.84 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.6.0 - /opt/homebrew/bin/node
    Yarn: 4.5.3 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 8.15.5 - /opt/homebrew/bin/pnpm
    bun: 1.2.0 - ~/.bun/bin/bun
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 133.0.6943.142
    Safari: 18.1.1
  npmPackages:
    @react-router/dev: ^7.3.0 => 7.3.0 
    @react-router/node: ^7.3.0 => 7.3.0 
    @react-router/serve: ^7.3.0 => 7.3.0 
    react-router: ^7.3.0 => 7.3.0 
    vite: ^5.4.11 => 5.4.14

Used Package Manager

npm

Expected Behavior

It should properly pass type checking without throwing any errors.

Actual Behavior

It throws the following error:

.react-router/types/+register.ts:11:3 - error TS2300: Duplicate identifier '/'.

11   "/": {};
     ~~~
@hakimLyon
Copy link

hakimLyon commented Mar 9, 2025

Same issue:

Image Image Image

@gavinfaux
Copy link

gavinfaux commented Mar 9, 2025

Same issue as title, 7.3.0, using route('/', 'routes/home.tsx') instead of index('routes/home.tsx). #13140 did not resolve.

Switched to using route instead of index due to unrelated issue posting to index (still trying to figure out minimal reproduction for that). Sticking to 7.1.5 for now.

Edit: figured out the index post issue, at least in 7.1.5 have to use /?index - in 7.1.5 we get a 405 method not allowed error and console error describing issue if trying to post to just /, but in 7.2.0/7.3.0 this seems to create a CPU race/memory leak leading to application crash. Will try and provide minimal recreation in a separate issue.

@alexanderson1993
Copy link
Contributor Author

alexanderson1993 commented Mar 10, 2025

Workaround that I'm using for now:

// routes.ts
layout("routes/home.tsx", [
  index("routes/blank.tsx"),
])

// routes/blank.tsx
export default Blank() {
  return null;
}

@kevinbailey25
Copy link

Not sure if my issue is related or not, but I now have missing routes. With 7.2.0 I've updated and am using href everywhere (SOOO NICE)... but as soon as I upgrade to 7.3.0 I have a route or two missing (from the +register.ts). I've been trying to work on reproducing it in a smaller example but no luck so far. I'm using remix-flat-routes.

Just thought I'd throw this out there in case there are others seeing the same. I'll report back if I find more.

@pcattori pcattori self-assigned this Mar 10, 2025
@adam-legge-slimmingworld
Copy link

adam-legge-slimmingworld commented Mar 11, 2025

Fwiw, I've just been trying to debug a duplicate typegen'd identifier for "/" on 7.3 and think I've narrowed it down to the "fullpath" function returning "/" for the root route (since it always starts with a / and then appends the lineage) - which is then duplicated with the "/" path I've got for my top-level layout route. I can see the filtering fix in #13140 is doing its job and filtering out the index route inside my layout route but it doesn't resolve the duplication with the root route.

@wevertoum
Copy link

wevertoum commented Apr 9, 2025

I'm experiencing the same issue.
This solution works for me for now.

Image Image

@pcattori
Copy link
Contributor

Fixed by #13499 , should be available next release

@geemanjs
Copy link

geemanjs commented May 2, 2025

Hey @pcattori

I think this issue is related - albeit slightly different:
kiliman/remix-flat-routes#157

I just tested the nightly build 0.0.0-nightly-7583dc758-20250502 which has the fix from #13499 in on the reproduction I added on remix-flat-routes and there still appears to be some duplicate types.

Heres the route config that is spat out in the routes.ts file for that reproduction:

[
  {
    "id": "routes/$routeParam/layout",
    "file": "routes/$routeParam/layout.tsx",
    "path": ":routeParam",
    "children": [
      {
        "id": "routes/$routeParam/cheeses/layout",
        "file": "routes/$routeParam/cheeses/layout.tsx",
        "path": "cheeses",
        "children": [
          {
            "id": "routes/$routeParam/cheeses/$cheeseId/index",
            "file": "routes/$routeParam/cheeses/$cheeseId/index.tsx",
            "path": ":cheeseId"
          }
        ]
      }
    ]
  },
  {
    "id": "routes/$routeParam_/cheeses/index/index",
    "file": "routes/$routeParam_/cheeses/index/index.tsx",
    "path": ":routeParam/cheeses",
    "index": true
  }
]

There are duplicate types in +register.ts for these entries:

type Params = {
// ...other types...
  "/:routeParam/cheeses": {
    "routeParam": string;
  };
// ...other types...
  "/:routeParam/cheeses": {
    "routeParam": string;
  };
};

@pcattori
Copy link
Contributor

pcattori commented May 2, 2025

@geemanjs I couldn't reproduce your issue. Here's what I did:

  1. Clone https://github.com/geemanjs/remix-flat-routes-reproduction
  2. Change all React Router versions in package.json to 0.0.0-nightly-7583dc758-20250502
  3. Run pnpm i
  4. Run pnpm typecheck

Step (4) runs without any type errors and checking the contents of .react-router/types/+register.ts:

import "react-router";

declare module "react-router" {
  interface Register {
    params: Params;
  }

  interface Future {
    unstable_middleware: false
  }
}

type Params = {
  "/": {};
  "/:routeParam": {
    "routeParam": string;
  };
  "/:routeParam/cheeses": {
    "routeParam": string;
  };
  "/:routeParam/cheeses/:cheeseId": {
    "routeParam": string;
    "cheeseId": string;
  };
  "/home": {};
};

Note that #13501 also refactored the relevant deduplication logic with a simple Set to ensure no duplicates exist. That was already part of the nightly, so not sure why you were getting errors anyway. But like I said, I can't reproduce your case. If you can send me a full reproduction GitHub link with the experimental/nightly release, I'm happy to take a look.

@geemanjs
Copy link

geemanjs commented May 2, 2025

It seems I only updated react-router and not react-router/dev - Can also confirm with both of them updated the issue is gone 👀! Sorry to have wasted some of your time!

Thanks @pcattori for looking either way!

Copy link
Contributor

github-actions bot commented May 8, 2025

🤖 Hello there,

We just published version 7.6.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants