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
Comments
Is there any cost to attaching a no-op unload listener that we don't use? This would be a breaking change, anyway. |
It doesn't attach the listener until the first |
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. |
The change is that leave hooks will now always trigger on hard-leaving the page, which is not the current behavior. |
Oh, I didn't even know we handled that. I don't think it's a huge change. What are most people using |
Route leave hooks, not |
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. |
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. |
|
I'd be fine either way, but I'm not convinced we can make this change without a major version bump. |
@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. |
I'm not totally convinced, but I don't care enough either way. |
Closing as per #3118 |
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)()
?The text was updated successfully, but these errors were encountered: