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(react): make wrapCreateBrowserRouter generic #6862

Merged
merged 6 commits into from
Jan 19, 2023

Conversation

h3rmanj
Copy link
Contributor

@h3rmanj h3rmanj commented Jan 19, 2023

Reduces the Router and RouterState to the minimal internal usage, and makes the wrapper accept a generic which extends the minimal types. This allows for react-router to make changes to their Router types, without breaking our types.

Fixes #6861

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

Reduces the Router and RouterState to the minimal internal usage,
and makes the wrapper accept a generic which extends the minimal types.
This allows for react-router to make changes to their Router types,
without breaking our types.
@h3rmanj
Copy link
Contributor Author

h3rmanj commented Jan 19, 2023

So, I tried to make the internal types as minimal as possible, to only include the properties that are used in @sentry/react. Then I made the wrapCreateBrowserRouter accept generic types which extends the minimal types, meaning the type returned should be from the consumers react-router-dom version.

This works fine when I link the package up and try it out in a project. However the test suite fails, which I assume to be because this project uses TypeScript v3, while what I do most likely only works with v4.

Edit:

Nevermind, I think I got it to work after all. I'm not too happy typing things with as x, but it was done before. With typescript v4 the as can be removed entirely, which is what confused me.

@h3rmanj h3rmanj mentioned this pull request Jan 19, 2023
3 tasks
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Thanks! Opened #6865 so we can make sure we catch this before users do.

@h3rmanj
Copy link
Contributor Author

h3rmanj commented Jan 19, 2023

@AbhiPrasad do note that this changes CreateRouterFunction, so if anyone imports it in their project the type might break for them.

I'll try to add a default to the generic args to fix it.

Copy link
Collaborator

@onurtemizkan onurtemizkan left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks @h3rmanj.

@AbhiPrasad AbhiPrasad merged commit 868c20b into getsentry:master Jan 19, 2023
@AbhiPrasad
Copy link
Member

@h3rmanj we'll try and get a release out with this fix early next week!

@h3rmanj
Copy link
Contributor Author

h3rmanj commented Jan 20, 2023

Sounds good, thanks!

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.

Type mismatch with react-router 6.7
3 participants