If nsPrefetchService is not initialized before document load, <link rel=prefetch> might never be fetched.
Categories
(Core :: Networking, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox141 | --- | fixed |
People
(Reporter: emilio, Assigned: emilio)
References
Details
(Whiteboard: [necko-triaged])
Attachments
(2 files)
Bug 1968202 was backed out (in bug 1968202 comment 5) because of a failure in prefetch-transfer-size-executor.html.
That test basically loads a page and adds a <link rel=prefetch as=document>, waiting for its load event.
After my patch, the load event didn't arrive. I debugged it a little bit and it turns out that before my patch the prefetch service gets initialized before that page load (due to the built-in accessiblecaret stylesheet).
That means that nsPrefetchService gets initialized, watches the document load, and sets mHaveProcessed = true, which triggers the prefetch here.
If that load doesn't trigger, nsPrefetchService gets initialized lazily after the doc has loaded, so mHaveProcessed is false and never trigger the load (unless some other document loads in that process).
It is extremely weird to have a global service depend on whether any document has loaded to start working... For now I'm preserving the current behavior of initializing the prefetch service, but this should be fixed.
mHaveProcessed comes from bug 372970. It seems a low risk fix may be that mHaveProcessed should be initialized to "is there any ongoing document load"? But also the utility of mHaveProcessed seems very narrow, so maybe the better fix is just removing that member.
Valentin, do you know who may be familiar with the prefetch service? I'm happy to implement either approach but if someone is more familiar with this code than me it'd be appreciated. FWIW mHaveProcessed seems pretty useless to me, it may only be useful during the first load of a document in a given process... which is a weird thing to watch for? :)
| Assignee | ||
Comment 1•1 year ago
|
||
No behavior change. Remove an unused method that does nothing too.
Updated•1 year ago
|
| Assignee | ||
Comment 2•1 year ago
|
||
It's not correct, see comment 0. This in theory can get preload / prefetch
started a bit sooner on the first pageload of a document. But that might
actually be fine? It's the current behavior too if you init the service and an
iframe loads.
Updated•1 year ago
|
Comment 3•1 year ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #0)
Valentin, do you know who may be familiar with the prefetch service? I'm happy to implement either approach but if someone is more familiar with this code than me it'd be appreciated. FWIW mHaveProcessed seems pretty useless to me, it may only be useful during the first load of a document in a given process... which is a weird thing to watch for? :)
I think Dragana was the last one to do any meaningful work on the prefetch service. Since then a few members of the Necko team have fixed minor bugs, but nothing substantial. So I expect your grasp of the code is similar or better than anyone's 🙂
Comment 6•1 year ago
|
||
Backed out for causing xpcshell failures in test_cancelPrefetch.js.
- Backout link
- Push with failures
- Failure Log
- Failure line: TEST-UNEXPECTED-FAIL | dom/base/test/unit/test_cancelPrefetch.js | xpcshell return code: 0
| Assignee | ||
Comment 7•1 year ago
|
||
So this test fails because the prefetch is blocked (since the doc is a DOMParser created document and CSP blocks all loads), and now we try to start the prefetch immediately since there's no document running.
Valentin, what should I do about this? It seems this functionality is already covered by test_link_prefetch.html (this call in particular).
Comment 8•1 year ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #7)
Valentin, what should I do about this? It seems this functionality is already covered by
test_link_prefetch.html(this call in particular).
Thanks, that test seems to cover everything in test_cancelPrefetch.js - so I'm OK with removing the unit test.
Comment 10•1 year ago
|
||
Comment 11•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/c3085b787071
https://hg.mozilla.org/mozilla-central/rev/58a442a2c579
https://hg.mozilla.org/mozilla-central/rev/3674d8e9144b
Updated•1 year ago
|
Description
•