Closed Bug 2074478 Opened 2 months ago Closed 2 months ago

Speculation Rules prefetches URLs that differ from the current document only by a fragment

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: sning, Assigned: sning)

References

Details

Attachments

(1 external file)

Firefox starts a speculation-rules prefetch when the candidate URL differs
from the current document URL only by its fragment.

Affected WPTs:

  • speculation-rules/prefetch/fragment.https.html
  • speculation-rules/prefetch/document-rules.https.html?include=linkToSelfFragment

Actual result:

The current document URL with a #fragment is prefetched. Both WPTs fail.

Expected result:

A fragment-only URL for the current document should not be prefetched. In
fragment.https.html, the other candidate—which points to a different
document and also has a fragment—should still be prefetched.

Implementation analysis:

SpeculationRules::InnerConsiderLoads builds and groups the candidates, and
EnactCandidates forwards them to SpeculationRulesManager::StartPrefetch.
There does not appear to be a final exclusion for a candidate whose URL has
a fragment and equals the current document URL when fragments are ignored.

This is separate from bug 2070879. That bug’s description specifically notes
that linkToSelfFragment remains after fixing document-rule link/frame
evaluation.

Current WPT:
https://searchfox.org/firefox-main/rev/f1cfb0e0b987d324d7513011ecad2f40f89bb9b2/testing/web-platform/tests/speculation-rules/prefetch/fragment.https.html#8-32

Relevant Gecko path:
https://searchfox.org/firefox-main/rev/f1cfb0e0b987d324d7513011ecad2f40f89bb9b2/dom/base/SpeculationRules.cpp#150-235

Pushed by avandolder@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/6543439deea5 https://hg.mozilla.org/integration/autoland/rev/454cd8b14b21 Don't prefetch for speculative candidate whose URI differs from the current document only by the fragment. r=dom-core-reviewers,jjaschke
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
QA Whiteboard: [qa-triage-done-c159/b158]

The check that landed here skips more than fragment-only candidates.

SpeculationRules::EnactCandidates uses documentUri->EqualsExceptRef(candidateUri) (https://searchfox.org/firefox-main/rev/b4b9efb6ee130740a94caf46ffff0625af1d51db/dom/base/SpeculationRules.cpp#216), which is also true when the candidate is identical to the document URL with no fragment. Navigating to that URL is a regular navigation, not a fragment navigation, so it should still be prefetched. comment 0 scopes the exclusion to a candidate that "has a fragment", and the upstream WPT for this came from a Chromium change dropping "self-referential fragment URLs" (wpt PR 41686).

Two WPTs that prefetch the document's own URL now never start a prefetch:

  • speculation-rules/prefetch/prefetch-traverse-reload.sub.html, "prefetches can be used for reload navigations": prefetches location.href, then calls location.reload().
  • speculation-rules/prefetch/navigation-timing-delivery-type.https.html?prefetch=true&bypass_cache=false: prefetches and navigates to the page's own URL.

On central these were already expected to fail, because the no-store executor page couldn't be served from the prefetch. With bug 2070841, which lets an activated navigation use a no-store prefetch, both pass without this check and fail with it. Chromium (Edge on wpt.fyi) passes both.

Suggested fix: only skip candidates that have a fragment, e.g. also require candidateUri->GetHasRef() before the EqualsExceptRef comparison. That keeps fragment.https.html and document-rules.https.html?include=linkToSelfFragment passing.

https://wpt.fyi/results/speculation-rules/prefetch?label=master&label=experimental&aligned&q=prefetch-traverse-reload.sub.html
https://wpt.fyi/results/speculation-rules/prefetch?label=master&label=experimental&aligned&q=navigation-timing-delivery-type.https.html

See Also: → 2089272
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: