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

Feature: useBeforeUnload by default for browser history #3110

Closed
jamiehodge opened this issue Feb 22, 2016 · 13 comments
Closed

Feature: useBeforeUnload by default for browser history #3110

jamiehodge opened this issue Feb 22, 2016 · 13 comments

Comments

@jamiehodge
Copy link

In order to enable useBeforeUnload, one currently needs to import createHistory and useBeforeUnload from history. If I'm not mistaken, listening for unload events would be a sane default for browser history, so why not change the browserHistory export to some variation of useBeforeUnload(createHistory)()?

@taion
Copy link
Contributor

taion commented Feb 22, 2016

Is there any cost to attaching a no-op unload listener that we don't use?

This would be a breaking change, anyway.

@timdorr
Copy link
Member

timdorr commented Feb 22, 2016

@timdorr
Copy link
Member

timdorr commented Feb 22, 2016

Also, is it a breaking change? It only adds an extra API and doesn't change the original history behavior. In fact, it really looks usable without history at all. useBeforeUnload(() => ({}))() should work just fine.

@taion
Copy link
Contributor

taion commented Feb 22, 2016

The change is that leave hooks will now always trigger on hard-leaving the page, which is not the current behavior.

@timdorr
Copy link
Member

timdorr commented Feb 22, 2016

Oh, I didn't even know we handled that.

I don't think it's a huge change. What are most people using onLeave for? I don't use it myself.

@taion
Copy link
Contributor

taion commented Feb 23, 2016

Route leave hooks, not onLeave.

@timdorr
Copy link
Member

timdorr commented Feb 23, 2016

Well, it looks like our example and this doc are wrong/incomplete without this being added.

I can't think of a reason not to add it by default.

@taion
Copy link
Contributor

taion commented Feb 23, 2016

Well, the example works. It just only works when staying within the router, and not for e.g. hard leaving the page or closing the tab.

@agundermann
Copy link
Contributor

beforeunload isn't totally free of side effects. It disables BFCache (Firefox, IE). This could actually be a good thing though, since BFCache can break the router and it seems like we can't support BFCache in a clean way using pageshow.

@taion
Copy link
Contributor

taion commented Feb 24, 2016

I'd be fine either way, but I'm not convinced we can make this change without a major version bump.

@timdorr
Copy link
Member

timdorr commented Feb 24, 2016

@taurose Thanks for that insight. Yeah, this sounding more like a straight up improvement.

@taion At worst, it's a minor bump. We're simply improving an API to cover more cases of "leaving" a route. There is no backwards incompatible change. Existing leave hooks will continue to fire on the same events as always.

@taion
Copy link
Contributor

taion commented Feb 25, 2016

I'm not totally convinced, but I don't care enough either way.

@timdorr
Copy link
Member

timdorr commented Feb 25, 2016

Closing as per #3118

@timdorr timdorr closed this as completed Feb 25, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 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

No branches or pull requests

4 participants