This repository was archived by the owner on Jul 18, 2022. It is now read-only.

Description
The current ordering of pagehide and visibilitychange during a page unload complicates our proposed flow of Lifecycle states for the Lifecycle API.
The reason is the ordering of pagehide and visibilitychange events can be inverted, depending on what the user does. Consider these two examples:
-
The user loads a page in Tab A and then switches to a new tab B. Later, they close tab A without refocusing it. In this case the ordering of events fired on tab A is visibilitychange → pagehide.
-
The user loads a page in Tab A and then navigates to a new page from a link. In this case the ordering of events fired on tab A is pagehide → visibilitychange.
Wouldn't it make more sense if visibilitychange always fired before pagehide?
Since pagehide is associated with the FROZEN state (for bfcache supporting browsers), and visiblitychange is associated with the HIDDEN state, the current ordering of events suggests that the lifecycle state of a page can transition from ACTIVE to FROZEN to HIDDEN, which doesn't make sense since we only want to freeze hidden tabs.
Does anyone here remember why this ordering was chosen? Would anyone object to changing the ordering in the spec?
https://html.spec.whatwg.org/multipage/browsing-the-web.html#unloading-documents
(Related dicussion WICG/page-lifecycle#7).