-
Notifications
You must be signed in to change notification settings - Fork 959
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
Only handle hashes with a '/' when using createHashHistory #131
Conversation
Can you speak a little to the use case you're trying to handle here? |
Our Redux-Application runs within another single-page application (GWT) that handles history via hashes itself. In our setup the outer application only handles specific hashes that start with '!'. When a user of the inner application clicks on a link with a '!' at the beginning to reach a page of the outer application, the hashChangeListener prepends the '/' by calling ensureSlash() and destroys the hash for the outer application. |
Huh. This seems a little odd to me. By the same reasoning, if you were using two separate HTML5 routers, would you also want to ignore certain paths? I'm not sure it makes sense to add something unintuitive like this for supporting multiple routers trying to work off the same global Or rather, this change in this place does not seem to match the use case you describe. |
You're right, I would prefer to have one global history handler and I guess its not a common use case. |
So, you want a way for hash history to ignore all changes? Or just some changes? i.e. Is there ever going to be a case when you: function ignorePath() {
return true
} ? |
I want the hashHistory to ignore all hashes that don't start with a '/'. For all other hashes I would return true. |
This comes up in the context of social auth as well - some providers will use hash to provide auth information to the client application. Would it make more sense to have I don't think we ever intentionally generate hashes that don't start with |
It would definitely match our use case, but it might destroy 404-handling for others I guess? But prepending a '/' on history-change might as well. I think just removing the ensureSlash-call on historyChange might work for both use cases as well? |
I feel like if all of our paths start with |
@cwrs What do you want to do here? Do you think it'd be too intrusive to always ignore paths that don't start with |
I think its the right thing to do. I could update my pull-request next week. Sorry for answering so late, I'm on vacation right now. |
No worries, just wanted to follow up. |
4b18a43
to
8cf549e
Compare
I changed my pull-request, but I'm not sure, how to test the new behaviour... |
Listen to the hash history with a spy, and count how many times that spy gets called. |
I tried to write a test and integrated SinonJs for the spy. Testing the behavour directly in the browser works, but my test will not work. Am I calling the wrong methods? |
A little confusingly, |
Specifically: https://github.com/mjackson/expect#createspy |
Thx, that was unexpected :). Much easier than integrating sinon. |
The tests work fine for me in Chrome... Do you have an idea what's wrong? |
I have a similar problem with oauth. When auth0 is using the provided callback, it usually looks something like this: react-router interpret that as Is there any way around that yet? |
@cwrs The failures were in non-Chrome browsers on BrowserStack. At a glance, looks like not a false positive. |
@taion thx, and sorry for answering so late. I will update my patch to the current version and see, if I can reproduce the errors on other browsers. |
7315bb9
to
ea7521a
Compare
My tests are now working, but I didn't change a thing since. |
@@ -133,7 +133,7 @@ function createHashHistory(options={}) { | |||
|
|||
function listenBefore(listener) { | |||
if (++listenerCount === 1) | |||
stopHashChangeListener = startHashChangeListener(history) |
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.
Are these and other changes needed?
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 mean, the ones of history
-> this
.
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 changes are only needed for tests, to use a spy to check of transitionTo is called.
This is actually not enough to fix e.g. remix-run/react-router#2776. The problem is that We might have to handle this some other way. |
Seems like we should only handle changes that came from our API. history.push(...)
// internally
handlingWithHistory = true
// then in the hashchange listener
if (handlingWithHistory)
doStuff()
// then switch it back
handlingWithHistory = false Then we'd be ignoring any hash changes not initiated by the library. I think paths shouldn't matter, but how the change was initiated that matters. |
We need to deal with The PR actually gets us a good part of the way there – the problem is that in the case of getting redirected to e.g. |
would it be possible to merge my PR if I update it to master? Or should I try to handle the initial location issue? |
@cwrs Do you have a good idea for handling the initial position issue? My initial thought is that it'd be better handled by the router than by history. |
@cwrs Actually, does it help your use case at all if we just drop the |
I'm currently testing a history-version without the ensureSlash() in our app. I was about to ask, if we can't drop the ensureSlash myself. All history-tests run well. So I'm totally fine with that. |
432c402
to
680f7e8
Compare
- dropped ensureSlash from createHashHistory Change-Id: Ibed14c8acde9c1ea022508c29be8b04df175d466
The version without emsureSlash is running in production for us now for about 4 weeks without problems. I rebased my patch to the current master. |
ping @mjackson |
I guess with the new hashType option (6be82b0) this pull-request is now obsolete. |
Thanks for putting up this PR. |
Thx for all your great work! |
This PR adds the ability to ignore hash changes when using createHashHistory().
Example:
We have the issue, that the hashChangeListener calls ensureSlash for hashes, not handled by the history.