-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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(v2): normalize location for route matching #2393
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 203adee |
Just to add more information about this change: since A location with |
0177cf2
to
106b9d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the location to be part of the state now? I think we just have to normalize it before using it and it should be fine? Putting in state seems redundant.
@yangshun the normalized location is also used in the Let me know what you think, I can always change the PR to call |
@rlamana I would prefer to keep things stateless if possible if they can be derived. You could memoize the values instead of putting them inside state. |
@yangshun makes sense. I updated the PR to memoize the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address comment.
@@ -94,7 +96,7 @@ class PendingNavigation extends React.Component { | |||
this.clearProgressBarTimeout(); | |||
this.progressBarTimeout = setTimeout(() => { | |||
clientLifecyclesDispatcher.onRouteUpdateDelayed({ | |||
location: this.props.location, | |||
location: this.state.location, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no this.state.location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 I missed a reference to the old state value... Now it's fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 😄
Motivation
Fixes #2392
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
The
PendingNavigation
component now uses anormalizeLocation
function. I added a single file for the new function to easily add unit tests and check the proper normalization of the pathname in the location object before it is passed to react-router'sRoute
components for matching: