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

createBrowserHistory only calls transitionTo when it has listen hook, not listenBefore #71

Closed
stevoland opened this issue Sep 27, 2015 · 5 comments

Comments

@stevoland
Copy link
Contributor

This requires the following workaround which seems odd to me:

erikras/react-redux-universal-hot-example#246

Let me know if you want a PR.

@mjackson mjackson changed the title createBrowserHistory only calls transitionTo when it has listen hook, not listenBefore or listenAfter createBrowserHistory only calls transitionTo when it has listen hook, not listenBefore Oct 1, 2015
@mjackson
Copy link
Member

mjackson commented Oct 1, 2015

I modified the issue title because we don't have a listenAfter API.

Eh ... ok. I get it. But why are you rendering in listenBefore? That's your cue that "things might change, we're not sure yet". Seems much safer to run your code in the listen callback.

@stevoland
Copy link
Contributor Author

Apologies for the incorrect title.

You're right, what we're doing in listenBefore in this instance is a hack to maintain use case that was easily achieved with react-router v1.0.0-beta3.

I maintain that it's reasonable to expect a history API that offers a listenBefore hook to fire those callbacks on browser navigation regardless of whether a different listener is also registered. Disagree?

@mjackson
Copy link
Member

mjackson commented Oct 4, 2015

it's reasonable to expect a history API that offers a listenBefore hook to fire those callbacks on browser navigation regardless of whether a different listener is also registered

Ya, that's reasonable. But your use case is still invalid. I'd much prefer to drive further development with valid use cases instead of theory. If there's a good reason why you're using listenBefore instead of listen for rendering, I'd like to know.

EDIT: I should also say that I'm open to fixing this. Just want to know why you're using listenBefore instead of listen.

@stevoland
Copy link
Contributor Author

The linked project uses listenBefore instead of listen in order to fetch the data required for the next routes before the location bar is updated. You say this use case is invalid and I have agreed although I note that there are others who do want this use case: https://twitter.com/gpblv/status/650249197950738432

I didn't create this ticket to drive further development, just to address what I see is an issue with this project. I maintain that listenBefore handlers should always be called, although I don't have a real-world use case.

IMO the code should be changed or a warning added to the docs as neither of the examples here would work without a listen handler also added: https://github.com/rackt/history/blob/master/docs/ConfirmingNavigation.md

Like I say, let me know if you want a PR otherwise I'll close this issue.

@mjackson
Copy link
Member

mjackson commented Oct 6, 2015

You have a great point about the docs. Sure, let's make this change. A PR would be great, thanks for offering :)

In order to make this change you'll need to override listenBefore in both createBrowserHistory and createHashHistory. Currently, both of those implementations override listen to know when they need to setup/teardown DOM event listeners.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants