Adjust event loop processing model to allow asynchronous layout of frames #3727
Labels
interop
Implementations are not interoperable with each other
topic: agent
The interaction with JavaScript's agent and agent cluster concepts
topic: event loop
Currently, the event loop processing model [1] does not make reference to the concept of
computing style or layout. It is assumed that updates to the DOM are atomic, and it
is an implementation detail whether browsers update style or layout at a later time. This
is true even for cases with multiple documents (frames), meaning that style and layout
are updated atomically for all frames, at least as far as script can observe.
In practice, all browsers update style and layout during rendering frame generation, which
is basically the same as step 3 from [1], "update the rendering". They do this because it
is more efficient to update style and layout lazily than eagerly, in the presence of script
which may make a sequence of style- and layout-inducing DOM mutations in one synchronous
block.
Further, Chromium in particular also updates all frames' style and layout at the same time
(except when cross-domain iframes are "throttled", which concept is referenced in step 7.4 of [1]).
However, even in this situation, Chromium will perform a synchronous style or layout if script references
style- or layout-inducing CSS properties on DOM objects, so from the script point of view,
style and layout for such frames are still atomic w.r.t. the main frame. (*)
The assumption of atomicity starts to break down with the desire to implement cross-domain
iframes in separate processes (Chrome calls this feature Site Isolation [4]), which is
necessary for security and desired for performance.
To avoid unreasonable implementation difficulty and poor performance in this multi-process scenario,
it is necessary to decouple style/layout update of each frame from other frames. This means that in
cases where one frame's size depends on the style or layout of another frame, we do not
necessarily force them to update in lockstep. Consider this example:
a.com frame:
b.com sub-frame:
In this code, b may observe a width that is not 123, until such time as a.com decides to render and then send a message to b.com's rendering process to update its layout.
An edit to the event processing model could be made, perhaps as follows:
The specification for behavior of methods like clientWidth or offsetWidth is part of the CSSOM spec,
but also needs to be edited to make clear that in the presence of multiple Documents, they are not
necessarily updated atomically.
[1] https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model
[2] https://wicg.github.io/ResizeObserver/#html-event-loop
[3] https://drafts.csswg.org/cssom-view/
[4] http://www.chromium.org/Home/chromium-security/site-isolation
(*) With the above spec change, Chrome's behavior could be changed to avoid synchronous style-and-layout in this case also.
The text was updated successfully, but these errors were encountered: