-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Redirect on props update (#5003) #5162
Redirect on props update (#5003) #5162
Conversation
.gitignore
Outdated
# Editors stuff | ||
.idea | ||
.project | ||
.vscode |
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 don't add to the gitignore file. This should be in your global .gitignore file for your machine.
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.
Good point, removed.
There is a warning test at the bottom of #5151 |
@timdorr Update:
|
Two ideas:
I don't know why to isn't required. We're not hardcore PropType-ers around here. It's fine to test |
@timdorr The warning itself has a stack trace, but you can't find the component that included the bad I think I'm done. |
@timdorr Merge it while it's hot (and passing build/tests) ;-) |
LGTM. Needs a second, though. (Only @ryanflorence or @mjackson can do a solo merge) |
I'm tempted to just put an |
It's not that it's necessarily persisting the same exact render() {
return (
!loggedIn ? <Redirect to="/login"/> :
!admin ? <Redirect to="/denied"/> :
<Admin/>
)
} You've got two |
Fixed conflict, but the build was canceled, no apparent reason. |
It auto-cancels if another build comes in on top of it. But you should rebase against master because @mjackson just fixed all the testing and building infra. |
b36c736
to
51c414e
Compare
51c414e
to
2d6e1f6
Compare
@timdorr Had some issues, but managed to do it eventually. |
@alexilyaev Squashing yourself isn't completely necessary since GitHub allows the maintainers to do it when merging, but I generally like to do so anyways (especially if something I do in one commit gets reverted in another). For reference, this article goes over the details very nicely: https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request. |
Guys, please merge this. |
Needs another 👍 from someone. |
nextTo = typeof nextTo === 'string' ? { pathname: nextTo } : nextTo | ||
|
||
if (locationsAreEqual(prevTo, nextTo)) | ||
return warning( |
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 would prefer if this was two statements.
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.
@pshrmn Can you share exactly what you'd expect?
I think interpolating inside the template string didn't break well.
Unless you mean to ditch the %s%s
and do a string concatenation?
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.
The current code is essentially the same as return console.error(...)
. While that is legal, I think that it would be better to separate the call expression and return statement.
if (...) {
warning(...)
return
}
let prevTo = prevProps.to | ||
let nextTo = this.props.to | ||
|
||
prevTo = typeof prevTo === 'string' ? { pathname: prevTo } : prevTo |
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 think that this should use createLocation
because it wouldn't work for <Redirect to='/somewhere?test=ing' />
.
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.
@pshrmn Turns out createLocation
was exactly what I needed, thanks!
Added a test for this use case.
@pshrmn Done with requested changes. |
In it goes. It'll be in the next minor release. Lots of goodies lined up, so hopefully that will be soon. |
Fixes #5003
Is it ok I've addedis-equal
dependency? It's used byexpect
already.I needed it because checking if we are redirecting to the same route is not so trivial.
to
can be a String or an Object, and the Object variant can havepathname
,search
andstate
, each of which could be a valid new route to redirect to.e.g. I might want to redirect to my own route with a different
search
string orstate
data.Other PR Questions:
warning
?In this case if we try to redirect to the same route we call
warning
to notify the user.