Skip to content

Commit

Permalink
Change beforeunload, unload, and bfcache interaction
Browse files Browse the repository at this point in the history
Per #5748 (comment),
removes the requirement that beforeunload event listeners being fired
cause a document to become unsalveagable (i.e., ineligible for bfcache).
Instead, unsalveagability is left more explicitly up to the user agent.

Additionally, changes navigation to no longer dispatch unload events for
documents which are kept alive in the session history (bfcache).

Closes #5748.
  • Loading branch information
rakina authored Oct 12, 2020
1 parent 1076db6 commit b3b7add
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -85167,8 +85167,8 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
<p>Things that can cause the page to be unsalvageable include:</p>

<ul class="brief">
<li>Listening for <code data-x="event-beforeunload">beforeunload</code> events
<li>Listening for <code data-x="event-unload">unload</code> events
<li>The user agent decided to not keep the <code>Document</code> alive in a <span>session
history entry</span> after <span data-x="unload a document">unload</span>
<li>Having <code>iframe</code>s that are not salvageable
<li>Active <code>WebSocket</code> objects
<li><span data-x="abort a document">Aborting a <code>Document</code></span>
Expand Down Expand Up @@ -85220,12 +85220,12 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {

<p>A <code>Document</code> has a <dfn
data-x="concept-document-salvageable"><i>salvageable</i></dfn> state, which must initially be
true, a <dfn>fired unload</dfn> flag, which must initially be false, and a <dfn>page showing</dfn>
flag, which must initially be false. The <span>page showing</span> flag is used to ensure that
scripts receive <code data-x="event-pageshow">pageshow</code> and <code
data-x="event-pagehide">pagehide</code> events in a consistent manner (e.g. that they never
receive two <code data-x="event-pagehide">pagehide</code> events in a row without an intervening
<code data-x="event-pageshow">pageshow</code>, or vice versa).</p>
true, and a <dfn>page showing</dfn> flag, which must initially be false. The <span>page
showing</span> flag is used to ensure that scripts receive <code
data-x="event-pageshow">pageshow</code> and <code data-x="event-pagehide">pagehide</code> events
in a consistent manner (e.g. that they never receive two <code
data-x="event-pagehide">pagehide</code> events in a row without an intervening <code
data-x="event-pageshow">pageshow</code>, or vice versa).</p>

<p><span data-x="event loop">Event loops</span> have a <dfn>termination nesting level</dfn>
counter, which must initially be 0.</p>
Expand Down Expand Up @@ -85253,10 +85253,6 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
<li><p>Decrease the <span>event loop</span>'s <span>termination nesting level</span> by
1.</p></li>

<li><p>If any event listeners were triggered by the earlier <i>dispatch</i> step, then set
<var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state to
false.</p></li>

<li>
<p>If <var>document</var>'s <span>active sandboxing flag set</span> does not have its
<span>sandboxed modals flag</span> set, and the <code
Expand Down Expand Up @@ -85292,15 +85288,11 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {

<ol>
<li><p><span>Prompt to unload</span> <var>browsingContext</var>'s <span>active
document</span> with the <var>recursiveFlag</var> set. If the user <span>refused to allow
the document to be unloaded</span>, then the user implicitly also <span data-x="refused to
allow the document to be unloaded">refused to allow <var>document</var> to be
unloaded</span>; <span>break</span>.</p></li>

<li><p>If the <i data-x="concept-document-salvageable">salvageable</i> state of
<var>browsingContext</var>'s <span>active document</span> is false, then set the <i
data-x="concept-document-salvageable">salvageable</i> state of <var>document</var> to
false.</p></li>
document</span> with the <var>recursiveFlag</var> set.</p></li>

<li><p>If the user <span>refused to allow the document to be unloaded</span>, then the user
implicitly also <span data-x="refused to allow the document to be unloaded">refused to allow
<var>document</var> to be unloaded</span>; <span>break</span>.</p></li>
</ol>
</li>
</ol>
Expand All @@ -85327,6 +85319,11 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {

<li><p>Set <var>document</var>'s <span>page showing</span> flag to false.</p></li>

<li><p>If the user agent does not intend to keep <var>document</var> alive
in a <span>session history entry</span> (such that it can be reused later on <span
data-x="traverse the history">history traversal</span>), set <var>document</var>'s
<i data-x="concept-document-salvageable">salvageable</i> state to false.</p></li>

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-pagehide">pagehide</code> at <var>document</var>'s <span>relevant global
object</span>, using <code>PageTransitionEvent</code>, with the <code
Expand All @@ -85342,18 +85339,15 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
<ref spec=PAGEVIS></p>
</li>

<li><p><i>Unload event</i>: If <var>document</var>'s <span>fired unload</span> flag is
false, then <span data-x="concept-event-fire">fire an event</span> named <code
data-x="event-unload">unload</code> at <var>document</var>'s <span>relevant global object</span>,
with <var>legacy target override flag</var> set.</p></li>
<li><p><i>Unload event</i>: If <var>document</var>'s <i
data-x="concept-document-salvageable">salvageable</i> state is false, then <span
data-x="concept-event-fire">fire an event</span> named <code data-x="event-unload">unload</code>
at <var>document</var>'s <span>relevant global object</span>, with <var>legacy target override
flag</var> set.</p></li>

<li><p>Decrease the <span>event loop</span>'s <span>termination nesting level</span> by
one.</p></li>

<li><p>If any event listeners were triggered by the earlier <i>unload event</i> step, then set
<var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state
to false and set <var>document</var>'s <span>fired unload</span> flag to true.</p></li>

<li><p>Run any <span>unloading document cleanup steps</span> for <var>document</var> that are
defined by this specification and <span>other applicable specifications</span>.</p></li>

Expand Down

0 comments on commit b3b7add

Please sign in to comment.