-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Clarify cases where we would fire the "unload" event, or maybe deprecate it? #6026
Comments
I'd suggest that we approach this in a slightly different order:
|
Sounds reasonable. I have a simple test for iframe unload/pagehide here. That issue seems to talk about other things such as relation with
It looks like the only "wrong" usage currently is just for the
I think we can suggest a pretty simple replacement strategy to web authors. If they are interested in all cases of Do you think that's reasonable? Where's the best place to put these recommendations? Also, two things that I realized I forgot to include in my original post:
The first point is the weirdest one, not sure what we can do about it though :( |
Are browsers consistent on the With a recommendation to web authors I'm mainly worried that we'd be doing it without knowing about all cases. As for naming, maybe it's best if we stop using "unload" altogether and only have it for the names of the events. (Or rename it to the page hide algorithm.) And explain with notes when they fire in relation to other things. |
Currently it seems like there are two separate meanings for "unload" in the spec:
Document
that's currently loaded: Used by "unload a Document" and "unloading document visibility change steps " which called on navigations, history traversal, closing browsing context, and thebeforeunload
event.Document
: used by theunload
event, which is only fired if theDocument
is no longer salvageable (per Make beforeunload not affect 'salvageable' & fire unload event only if document is no longer salvageable #5889).The first definition means that the
Document
does not have to be destroyed if it's unloaded, allowing cases where the back-forward cache keeps theDocument
alive after navigation so that theDocument
can be reused on back navigation, etc.The
unload
event, however, does not fire every time we "unload" (using the first definition), and instead only fires whenever theDocument
turns out to be no longer salvageable, meaning it will get destroyed later. Even using the second definition, though, it's not always fired: notable examples include when we discard a browsing context (per #4611 this is not true in practice though, so this might be a separate issue), and when aDocument
gets destroyed while it's not the "active document" (e.g. when it's saved in bfcache but later destroyed due to memory pressure/timeout/other reasons)So I guess the main problem here is just that the
unload
event has a misleading name, as it won't always fire whenever we're "unloading" as defined by the first definition (aka whenever the term "unload" is used in the spec). Also, we already have thepagehide
event, which will always be fired whenever we're unloading and it covers all cases when theunload
event is fired (+ more!). This means allunload
handlers should be able to be changed into apagehide
handler.Considering the above points, I wonder if it makes sense to deprecate the
unload
event (this does not mean the browsers will stop firing the event entirely immediately - ~66% of page loads still usesunload
handlers). This will remove any confusion of the term "unload".If that seems too drastic, I guess we can just make the different meanings very clear? (and maybe MDN, etc. can help clarify cases where the unload event will fire vs not).
Relevant issues: #5748, #4611
cc @annevk @domenic @cdumez @fergald @altimin @smaug---- @mystor
The text was updated successfully, but these errors were encountered: