Bug 202434

Summary: XMLHttpRequest sometimes prevents pages from entering the back/forward cache
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Page LoadingAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, beidson, commit-queue, ggaren, thorton, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 202293    
Attachments:
Description Flags
Patch none

Description Chris Dumez 2019-10-01 14:37:12 PDT
XMLHttpRequest sometimes prevents pages from entering the back/forward cache.
Comment 1 Radar WebKit Bug Importer 2019-10-01 14:37:38 PDT
<rdar://problem/55890340>
Comment 2 Chris Dumez 2019-10-01 15:44:32 PDT
Created attachment 379958 [details]
Patch
Comment 3 Geoffrey Garen 2019-10-03 13:44:29 PDT
Comment on attachment 379958 [details]
Patch

r=me

Isn't it also the case that the document refuses to cache if it has not fired the load event yet? It seems like tight coupling for an XHR object to maintain invariants on behalf of the document.
Comment 4 Chris Dumez 2019-10-03 13:46:02 PDT
(In reply to Geoffrey Garen from comment #3)
> Comment on attachment 379958 [details]
> Patch
> 
> r=me
> 
> Isn't it also the case that the document refuses to cache if it has not
> fired the load event yet? It seems like tight coupling for an XHR object to
> maintain invariants on behalf of the document.

It is true for the main frame but not necessarily true for subframes (that were added later on, after the load event had fired in the main frame).
Comment 5 Geoffrey Garen 2019-10-03 13:48:49 PDT
> > Isn't it also the case that the document refuses to cache if it has not
> > fired the load event yet? It seems like tight coupling for an XHR object to
> > maintain invariants on behalf of the document.
> 
> It is true for the main frame but not necessarily true for subframes (that
> were added later on, after the load event had fired in the main frame).

If a subframe has not loaded yet, and we cancel its loads in order to enter the page cache, doesn't that present the same concern -- that the subframe document will fire its load event while in the page cache?
Comment 6 Chris Dumez 2019-10-03 13:51:37 PDT
(In reply to Geoffrey Garen from comment #5)
> > > Isn't it also the case that the document refuses to cache if it has not
> > > fired the load event yet? It seems like tight coupling for an XHR object to
> > > maintain invariants on behalf of the document.
> > 
> > It is true for the main frame but not necessarily true for subframes (that
> > were added later on, after the load event had fired in the main frame).
> 
> If a subframe has not loaded yet, and we cancel its loads in order to enter
> the page cache, doesn't that present the same concern -- that the subframe
> document will fire its load event while in the page cache?

No, the load event would fire before entering PageCache, which is when we stop the loads. The issue here is that XMLHttpRequest stops its load in the "suspend" function (where script is not allowed to run). This can be refactored further so that XMLHttpRequest no longer stops its loads in suspend though. I can look into it in a follow-up.
Comment 7 Geoffrey Garen 2019-10-03 13:57:58 PDT
Sounds good.
Comment 8 WebKit Commit Bot 2019-10-03 14:29:50 PDT
Comment on attachment 379958 [details]
Patch

Clearing flags on attachment: 379958

Committed r250678: <https://trac.webkit.org/changeset/250678>
Comment 9 WebKit Commit Bot 2019-10-03 14:29:51 PDT
All reviewed patches have been landed.  Closing bug.