Speculation Rules prefetches URLs that differ from the current document only by a fragment
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
| 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.
Relevant Gecko path:
https://searchfox.org/firefox-main/rev/f1cfb0e0b987d324d7513011ecad2f40f89bb9b2/dom/base/SpeculationRules.cpp#150-235
Comment 1•2 months ago
|
||
Updated•2 months ago
|
Comment 4•2 months ago
|
||
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": prefetcheslocation.href, then callslocation.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
Description
•