Skip to content

Commit b80e83b

Browse files
authored
Fix historical and recent breakage in session history traversal
This fixes several related issues surrounding the "update the session history with the new page" and "traverse the history" algorithms. * A mistaken attempted refactoring in #6039 got the wrong Document for the newDocument variable in "traverse the history". To fix this, we explicitly pass in the new document to the algorithm from all its call sites. (Discussed in #6197.) * As discussed more extensively in #6197, the same-URL and entry update/reload conditions in "update the session history with the new page" were not correctly triggering the new-document clause in "traverse the history", despite replacing the document. This was partially due to #6039, although the phrasing before #6039 was extremely ambiguous, so #6039 was mostly a transition from "unclear" to "clearly wrong". * This fixes the "easy bug" discussed in #6202, where the same-URL case was using the wrong URL to determine sameness. That bug was also introduced in #6039. The harder bug, as well as the action-at-a-distance nature of the same-URL check, remain tracked in #6202. * For years, the spec has required deleting the future session history entries after performing a navigation with history handling of "replace", e.g. via location.replace(). This is not correct; a "replace" navigation does not delete future session history entries. Instead it just replaces the current entry, leaving future entries alone. * The latter point makes the handling of same-URL navigations almost identical to "replace" navigations (including non-same-URL "replace" navigations). This change makes this clear, by using the same text for both, but adding a pointer to #6213 which highlights the fact that some browsers treat them slightly differently (and some treat them the same). * Finally, this adds or modifies a few assertions to check that we're in the "default" history handling behavior, so it's clearer to the reader what the non-exceptional path through the spec is. Closes #6197.
1 parent 07a5b3e commit b80e83b

File tree

1 file changed

+72
-35
lines changed

1 file changed

+72
-35
lines changed

source

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85165,16 +85165,13 @@ new PaymentRequest(…); // Allowed to use
8516585165

8516685166
<p>Some of the sections below, to which the above algorithm defers in certain cases, require the
8516785167
user agent to <dfn>update the session history with the new page</dfn>, given some <span>navigation
85168-
params</span> <var>navigationParams</var>. When a user agent is required to do this, it must
85169-
<span>queue a global task</span> on the <span>networking task source</span>, given the
85170-
<span>relevant global object</span> of the <code>Document</code> object of the <span>current
85171-
entry</span> (not the new one), to run the following steps:</p>
85168+
params</span> <var>navigationParams</var> and a <code>Document</code> <var>newDocument</var>. When
85169+
a user agent is required to do this, it must <span>queue a global task</span> on the
85170+
<span>networking task source</span>, given the <span>relevant global object</span> of the
85171+
<code>Document</code> object of the <span>current entry</span> (not the new one), to run the
85172+
following steps:</p>
8517285173

8517385174
<ol>
85174-
<li><p>Let <var>newDocument</var> be <var>navigationParams</var>'s <span
85175-
data-x="navigation-params-browsing-context">browsing context</span>'s <span>active
85176-
document</span>.</p></li>
85177-
8517885175
<li>
8517985176
<p><span data-x="unload a document">Unload</span> the <span
8518085177
data-x="she-document">document</span> of the <span>current entry</span>.</p>
@@ -85190,38 +85187,76 @@ new PaymentRequest(&hellip;); // Allowed to use
8519085187
<li>
8519185188
<dl>
8519285189
<dt>If <var>navigationParams</var>'s <span data-x="navigation-params-hh">history
85193-
handling</span> is "<code data-x="hh-reload">reload</code>" or "<code
85194-
data-x="hh-entry-update">entry update</code>"</dt>
85190+
handling</span> is "<code data-x="hh-entry-update">entry update</code>" or "<code
85191+
data-x="hh-reload">reload</code>"</dt>
8519585192

8519685193
<dd>
8519785194
<ol>
8519885195
<li><p>Replace the <span data-x="she-document">document</span> of the <span>current
85199-
entry</span>, and any other entries that reference the same <span
85196+
entry</span>, and of any other entries that reference the same <span
8520085197
data-x="she-document">document</span> as that entry, with <var>newDocument</var>.</p></li>
8520185198

85202-
<li><p><span>Traverse the history</span> to the <span>current entry</span>.</p></li>
85199+
<li><p><span>Traverse the history</span> to the <span>current entry</span> with <var
85200+
data-x="traverse-history-hh">historyHandling</var> set to <var>navigationParams</var>'s <span
85201+
data-x="navigation-params-hh">history handling</span>.</p></li>
8520385202
</ol>
8520485203
</dd>
8520585204

85206-
<dt>If the navigation was initiated with a <span>URL</span> that <span
85207-
data-x="concept-url-equals">equals</span> <var>newDocument</var>'s <span
85208-
data-x="concept-document-url">URL</span></dt>
85205+
<dt>Otherwise, if the navigation was initiated with a <span>URL</span> that <span
85206+
data-x="concept-url-equals">equals</span> <var>navigationParams</var>'s <span
85207+
data-x="navigation-params-browsing-context">browsing context</span>'s <span>active
85208+
document</span>'s <span data-x="concept-document-url">URL</span></dt>
8520985209

8521085210
<dd>
8521185211
<ol>
85212-
<li><p>Replace the <span>current entry</span> with a new <span>session history entry</span>
85213-
whose <span data-x="she-url">URL</span> is <var>newDocument</var>'s <span
85214-
data-x="concept-document-url">URL</span> and <span data-x="she-document">document</span> is
85215-
<var>newDocument</var>.</p></li>
85212+
<li>
85213+
<p>Let <var>newEntry</var> be a new <span>session history entry</span> whose <span
85214+
data-x="she-url">URL</span> is <var>newDocument</var>'s <span
85215+
data-x="concept-document-url">URL</span> and <span data-x="she-document">document</span> is
85216+
<var>newDocument</var>.</p>
85217+
85218+
<p class="XXX">Some browsers copy over the serialized state of <span>current entry</span>,
85219+
but this is inconsistent. See <a href="https://github.com/whatwg/html/issues/6213">issue
85220+
#6213</a> for more discussion on this.</p>
85221+
</li>
85222+
85223+
<li><p>Insert <var>newEntry</var> after the <span>current entry</span> in
85224+
<var>navigationParams</var>'s <span data-x="navigation-params-browsing-context">browsing
85225+
context</span>'s <span>session history</span>.</p></li>
8521685226

85217-
<li><p><span>Traverse the history</span> to the <span>current entry</span>.</p></li>
85227+
<li><p><span>Traverse the history</span> to <var>newEntry</var> with <var
85228+
data-x="traverse-history-hh">historyHandling</var> set to "<code
85229+
data-x="hh-replace">replace</code>".</p></li>
85230+
</ol>
85231+
</dd>
85232+
85233+
<dt>Otherwise, if <var>navigationParams</var>'s <span data-x="navigation-params-hh">history
85234+
handling</span> is "<code data-x="hh-replace">replace</code>"</dt>
85235+
85236+
<dd>
85237+
<ol>
85238+
<li><p>Let <var>newEntry</var> be a new <span>session history entry</span> whose <span
85239+
data-x="she-url">URL</span> is <var>newDocument</var>'s <span
85240+
data-x="concept-document-url">URL</span> and <span data-x="she-document">document</span> is
85241+
<var>newDocument</var>.</p></li>
85242+
85243+
<li><p>Insert <var>newEntry</var> after the <span>current entry</span> in
85244+
<var>navigationParams</var>'s <span data-x="navigation-params-browsing-context">browsing
85245+
context</span>'s <span>session history</span>.</p></li>
85246+
85247+
<li><p><span>Traverse the history</span> to <var>newEntry</var> with
85248+
<var data-x="traverse-history-hh">historyHandling</var> set to "<code
85249+
data-x="hh-replace">replace</code>".</p></li>
8521885250
</ol>
8521985251
</dd>
8522085252

8522185253
<dt>Otherwise</dt>
8522285254

8522385255
<dd>
8522485256
<ol>
85257+
<li><p>Assert: <var>navigationParams</var>'s <span data-x="navigation-params-hh">history
85258+
handling</span> is "<code data-x="hh-default">default</code>".</p></li>
85259+
8522585260
<li>
8522685261
<p>Remove all the entries in the <span>session history</span> after the <span>current
8522785262
entry</span>. If the <span>current entry</span> is the last entry in the session history,
@@ -85236,9 +85271,7 @@ new PaymentRequest(&hellip;); // Allowed to use
8523685271
data-x="concept-document-url">URL</span> and <span data-x="she-document">document</span> is
8523785272
<var>newDocument</var>.</p></li>
8523885273

85239-
<li><p><span>Traverse the history</span> to the new entry, with <var
85240-
data-x="traverse-history-hh">historyHandling</var> set to <var>navigationParams</var>'s <span
85241-
data-x="navigation-params-hh">history handling</span>.</p></li>
85274+
<li><p><span>Traverse the history</span> to the new entry.</p></li>
8524285275
</ol>
8524385276
</dd>
8524485277
</dl>
@@ -85311,7 +85344,8 @@ new PaymentRequest(&hellip;); // Allowed to use
8531185344

8531285345
<p>After creating the <code>Document</code> object, but before any script execution, certainly
8531385346
before the parser <span data-x="stop parsing">stops</span>, the user agent must <span>update the
85314-
session history with the new page</span> given <var>navigationParams</var>.</p>
85347+
session history with the new page</span> given <var>navigationParams</var> and the newly-created
85348+
<code>Document</code>.</p>
8531585349

8531685350

8531785351

@@ -85336,9 +85370,10 @@ new PaymentRequest(&hellip;); // Allowed to use
8533685370
character encoding.</p>
8533785371

8533885372
<p>Then, with the newly created <code>Document</code>, the user agent must <span>update the
85339-
session history with the new page</span> given <var>navigationParams</var>. User agents may do
85340-
this before the complete document has been parsed (thus achieving <i>incremental rendering</i>),
85341-
and must do this before any scripts are to be executed.</p>
85373+
session history with the new page</span> given <var>navigationParams</var> and the newly-created
85374+
<code>Document</code>. User agents may do this before the complete document has been parsed (thus
85375+
achieving <i>incremental rendering</i>), and must do this before any scripts are to be
85376+
executed.</p>
8534285377

8534385378
<p>Error messages from the parse process (e.g., XML namespace well-formedness errors) may be
8534485379
reported inline by mutating the <code>Document</code>.</p>
@@ -85385,7 +85420,7 @@ new PaymentRequest(&hellip;); // Allowed to use
8538585420

8538685421
<p>After creating the <code>Document</code> object, but potentially before the page has finished
8538785422
parsing, the user agent must <span>update the session history with the new page</span> given
85388-
<var>navigationParams</var>.</p>
85423+
<var>navigationParams</var> and the newly-created <code>Document</code>.</p>
8538985424

8539085425
<p>User agents may add content to the <code>head</code> element of the <code>Document</code>,
8539185426
e.g., linking to a style sheet, providing script, or giving the document a <code>title</code>.</p>
@@ -85473,7 +85508,7 @@ new PaymentRequest(&hellip;); // Allowed to use
8547385508

8547485509
<p>After creating the <code>Document</code> object, but potentially before the page has finished
8547585510
fully loading, the user agent must <span>update the session history with the new page</span> given
85476-
<var>navigationParams</var>.</p>
85511+
<var>navigationParams</var> and the newly-created <code>Document</code>.</p>
8547785512

8547885513
<p>User agents may add content to the <code>head</code> element of the <code>Document</code>, or
8547985514
attributes to the element <var>host element</var>, e.g., to link to a style sheet, to provide a
@@ -85518,7 +85553,7 @@ new PaymentRequest(&hellip;); // Allowed to use
8551885553

8551985554
<p>After creating the <code>Document</code> object, but potentially before the page has finished
8552085555
fully loading, the user agent must <span>update the session history with the new page</span> given
85521-
<var>navigationParams</var>.</p>
85556+
<var>navigationParams</var> and the newly-created <code>Document</code>.</p>
8552285557

8552385558
<p>User agents may add content to the <code>head</code> element of the <code>Document</code>, or
8552485559
attributes to the <code>embed</code> element, e.g. to link to a style sheet or to give the
@@ -85574,7 +85609,7 @@ new PaymentRequest(&hellip;); // Allowed to use
8557485609

8557585610
<p>After creating the <code>Document</code> object, but potentially before the page has been
8557685611
completely set up, the user agent must <span>update the session history with the new page</span>
85577-
given <var>navigationParams</var>.</p>
85612+
given <var>navigationParams</var> and the newly-created <code>Document</code>.</p>
8557885613

8557985614

8558085615

@@ -85754,16 +85789,16 @@ new PaymentRequest(&hellip;); // Allowed to use
8575485789
<p>If <var>entry</var>'s <span data-x="she-document">document</span> is null, then:</p>
8575585790

8575685791
<ol>
85792+
<li><p>Assert: <var>historyHandling</var> is "<code
85793+
data-x="hh-default">default</code>".</p></li>
85794+
8575785795
<li><p>Let <var>request</var> be a new <span data-x="concept-request">request</span> whose
8575885796
<span data-x="concept-request-url">url</span> is <var>entry</var>'s <span
8575985797
data-x="she-url">URL</span>.</p></li>
8576085798

8576185799
<li><p>If <var>explicitHistoryNavigation</var> is true, then set <var>request</var>'s <span
8576285800
data-x="concept-request-history-navigation-flag">history-navigation flag</span>.</p></li>
8576385801

85764-
<li><p>Assert: <var>historyHandling</var> is not "<code
85765-
data-x="hh-replace">replace</code>".</p></li>
85766-
8576785802
<li>
8576885803
<p><span>Navigate</span><!--DONAV history traversal after eviction--> the <span>browsing
8576985804
context</span> to <var>request</var> with <var data-x="navigation-hh">historyHandling</var>
@@ -85796,7 +85831,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8579685831
data-x="she-document">document</span>.</p></li>
8579785832

8579885833
<li><p>If <var>newDocument</var> is different than the <span>current entry</span>'s <span
85799-
data-x="she-document">document</span>, then:</p>
85834+
data-x="she-document">document</span>, or <var>historyHandling</var> is "<code
85835+
data-x="hh-entry-update">entry update</code>" or "<code data-x="hh-reload">reload</code>",
85836+
then:</p>
8580085837

8580185838
<ol>
8580285839
<li><p>Remove any <span data-x="concept-task">tasks</span> queued by the <span>history traversal

0 commit comments

Comments
 (0)