Skip to content

Conversation

fernandojbf
Copy link

Description

Since React Router’s type generator skips any route located outside the app directory, adding such a route to the +routes.ts RouteModule type will cause a type error.

Because it’s possible to include files from outside the app folder using file paths, I believe the type generator should at least fall back to unknown for those routes.

Copy link

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: 58f0964

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@fernandojbf fernandojbf force-pushed the typegen-in-directory-filter branch from 711bff3 to 4784e7a Compare October 10, 2025 09:42
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Oct 10, 2025

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@fernandojbf
Copy link
Author

This is especially important for routes that are shared through node_modules. I know that, for now, the framework does not officially support this use case, but it’s still possible to reference them using file system paths.

I believe the RouteModule type should remain valid even when the route type file is not generated. In my opinion, adding unknown is the recommended approach — it allows us to later decide whether we want to support type definitions for routes outside the project.

Comment on lines +208 to +216
isInAppDirectory(ctx, route.file)
? t.tsTypeQuery(
t.tsImportType(
t.stringLiteral(
`./${Path.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`,
),
),
)
: t.tsUnknownKeyword(),

Choose a reason for hiding this comment

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

You might need to add a test to ensure this works properly, don't conflict with anything else and is not removed in the future

Copy link
Author

@fernandojbf fernandojbf Oct 13, 2025

Choose a reason for hiding this comment

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

Yes, i did not had time to add it, but i will add it now :)
Thanks

Copy link
Author

Choose a reason for hiding this comment

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

Integration test added

@fernandojbf fernandojbf force-pushed the typegen-in-directory-filter branch from 7370b3d to 838343f Compare October 13, 2025 10:30
@fernandojbf fernandojbf force-pushed the typegen-in-directory-filter branch from 838343f to 58f0964 Compare October 13, 2025 17:52
@fernandojbf
Copy link
Author

I believe PR (Full) / 👀 Integration Test / macos-latest / node@22 / webkit (pull_request) timeout. Can anyone retry this job?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants