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(router-generator): generator should not infer trailing slash is not necessary for index routes #1597

Merged
merged 1 commit into from
May 16, 2024

Conversation

chorobin
Copy link
Contributor

@chorobin chorobin commented May 15, 2024

Trailing slashes should only be there if the index route has to be uniquely identified by it.

fixes #1596

Copy link

nx-cloud bot commented May 15, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 2e0605e. 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 2 targets

Sent with 💌 from NxCloud.

@@ -123,15 +123,15 @@ declare module '@tanstack/react-router' {
}
'/blog/$slug/': {
id: '/blog/$slug/'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if the id should have a trailing slash or not? But at least this fixes the fullPath and path. TS used to normalize this but its right to move this work to the generator as we don't want the compiler spending time on stuff the generator can do

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this id field meant to be used in Router?

If it is being used in places like useSearch, and hooks that use from, then trailing-slashes should be removed (with the exception to index routes).

For example, in the basic example, from accepts the following options regardless of the trailingSlash setting.

/
/posts
/posts/
/posts/$postId
__root__

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me clarify. These are index routes that I'm removing trailing slashes from. It's index routes without a route.tsx which was causing the problem. Before I guess TS was removing this slash, then I moved it to the generator and fullPath got a trailing slash in this situation.

So do you think id should have a trailing slash or not in this situation? Because TFilePath does have one and I guess always had one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just checked previous versions and id always had a trailing slash in this situation. I'm going to merge

Copy link
Contributor

@TkDodo TkDodo left a comment

Choose a reason for hiding this comment

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

Do we have a test for different trailingSlash settings too?

@chorobin
Copy link
Contributor Author

chorobin commented May 15, 2024

Do we have a test for different trailingSlash settings too?

We have loads at the type level. The problem was the types expect fullPath to not have trailing slashes by default.

https://github.com/TanStack/router/blob/main/packages/react-router/tests/link.test-d.tsx

I think the generator tests should cover that the generated types are correct

@@ -123,15 +123,15 @@ declare module '@tanstack/react-router' {
}
'/blog/$slug/': {
id: '/blog/$slug/'
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this id field meant to be used in Router?

If it is being used in places like useSearch, and hooks that use from, then trailing-slashes should be removed (with the exception to index routes).

For example, in the basic example, from accepts the following options regardless of the trailingSlash setting.

/
/posts
/posts/
/posts/$postId
__root__

@SeanCassiere
Copy link
Contributor

@chorobin looks good on my-side, just left a comment regarding the id value.

@SeanCassiere SeanCassiere changed the title fix: generator should not infer trailing slash is not necessary for index routes fix(router-generator): generator should not infer trailing slash is not necessary for index routes May 16, 2024
@chorobin chorobin merged commit a770c08 into main May 16, 2024
7 checks passed
@chorobin chorobin deleted the fix-trailing-slashes-path-generator branch May 16, 2024 05:31
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.

route.tsx changes whether trailing slashes are required in links to index.tsx
4 participants