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

draft: typesafety #12752

Closed
wants to merge 6 commits into from
Closed

draft: typesafety #12752

wants to merge 6 commits into from

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Jan 15, 2025

Fixes #12373

This PR refactors typegen to be "route ID centric" based on the route manifest produced by routes.ts.
This architecture better supports the fixes/features also added in this PR:

  • Fix: matches are typed to be precise for child routes
  • Feature: Type-safe paths viahref
  • Feature: Type-safe access for other routes via useRoute

TODO

  • decide if requiring {} for paths that have only optional params is good or bad
  • clean up the old route-modules, register.ts, etc.
  • support custom app dir (no hardcoded app/)
  • type-safe handle within matches
  • loaderData with hydrate = true respects HydrateFallback set in parent routes
  • try it with a huge app (1000+ routes)
  • tests
  • changeset

href

Construct type-safe paths for navigation with href:

import { href } from "react-router"

const home = href("/home")
const productUrl = href("/products/:id", { id: "asdf" })
<Link to={href("/foo/:bar/", { bar: "baz" })

since paths do not uniquely identify routes when layout routes are used
Copy link

changeset-bot bot commented Jan 15, 2025

⚠️ No Changeset found

Latest commit: 759a11a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pcattori pcattori mentioned this pull request Jan 15, 2025
@pcattori
Copy link
Contributor Author

Note: need to update test fixtures to include *.ts (not just *.d.ts) from .react-router/types

@pcattori
Copy link
Contributor Author

Type-safe href merged in #12994

@pcattori pcattori closed this Feb 12, 2025
@pcattori pcattori deleted the pedro/typesafety branch February 12, 2025 19:07
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.

1 participant