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

Use forced REPLACE only when both location and state are the same #179

Merged
merged 1 commit into from
Jan 13, 2016

Conversation

Macroz
Copy link
Contributor

@Macroz Macroz commented Dec 7, 2015

Fixes #178

@taion
Copy link
Contributor

taion commented Dec 7, 2015

Please add test coverage here.

@Macroz
Copy link
Contributor Author

Macroz commented Dec 7, 2015

Yes, will add, if this is considered a useful change.

@@ -120,7 +120,7 @@ function createHistory(options={}) {
const prevPath = createPath(location)
const nextPath = createPath(nextLocation)

if (nextPath === prevPath)
if (nextPath === prevPath && deepEqual(location.state, nextLocation.state))
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably make this check w/something that shares code w/locationsAreEqual, possibly prior to calling createPath.

@@ -7,6 +7,7 @@
"docs",
"es6",
"lib",
"modules",
Copy link
Member

Choose a reason for hiding this comment

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

Please omit this line.

@mjackson
Copy link
Member

mjackson commented Jan 3, 2016

Logically, it seems like this PR is on the right track and philosophically compatible with the fix that @taurose made in #43. The idea behind #43 is that when the exact same location is pushed, we should use replace instead of push. But since state is part of a location object (i.e. location.state) we should also consider whether the state is the same when making that decision.

@Macroz Any reason you chose to modify package.json? Otherwise, I'd say this looks good.

@taion
Copy link
Contributor

taion commented Jan 3, 2016

@mjackson

One question I have is where this "replace PUSH with REPLACE" logic should go.

I think transitionTo might be the wrong place. Better would be either push or maybe even upstream in <Link> in React Router.

There's nothing in the HTML5 history API that strictly prevents users from re-pushing the exact same location. The "no extra push" behavior only comes from following <a>s.

Do you think a user might ever legitimately need to push the same location? Or should we just not bother supporting that?

@mjackson
Copy link
Member

mjackson commented Jan 3, 2016

Do you think a user might ever legitimately need to push the same location?

No, I don't think that's a legit use case. You shouldn't have the ability to PUSH to where you already are.

@taion
Copy link
Contributor

taion commented Jan 3, 2016

Fair enough.

- Update tests to include check for changing state
- URL stays the same, but state changes.
@Macroz
Copy link
Contributor Author

Macroz commented Jan 3, 2016

@mjackson I added the modules directory to use the repo as a npm package directly from GitHub, while waiting for the discussion to finish. Now I've removed it, rebased to master and squashed the commits. Does this look good?

I noticed that there are some tests failing in master at the moment.

taion added a commit that referenced this pull request Jan 13, 2016
Use forced REPLACE only when both location and state are the same
@taion taion merged commit f5e6764 into remix-run:master Jan 13, 2016
@Macroz
Copy link
Contributor Author

Macroz commented Jan 14, 2016

Great! Thanks for the fix!

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants