diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index d0c5003f908..d578fac7832 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -1203,6 +1203,21 @@ impl Constellation { for frame in self.current_frame_tree_iter(self.root_frame_id) { let pipeline = self.pipeline(frame.current); + // Check to see if there are any webfonts still loading. + // + // If GetWebFontLoadState returns false, either there are no + // webfonts loading, or there's a WebFontLoaded message waiting in + // script_chan's message queue. Therefore, we need to check this + // before we check whether the document is ready; otherwise, + // there's a race condition where a webfont has finished loading, + // but hasn't yet notified the document. + let (sender, receiver) = ipc::channel().unwrap(); + let msg = LayoutControlMsg::GetWebFontLoadState(sender); + pipeline.layout_chan.0.send(msg).unwrap(); + if receiver.recv().unwrap() { + return false; + } + // Synchronously query the script task for this pipeline // to see if it is idle. let (sender, receiver) = channel(); @@ -1213,13 +1228,6 @@ impl Constellation { return false; } - let (sender, receiver) = ipc::channel().unwrap(); - let msg = LayoutControlMsg::GetWebFontLoadState(sender); - pipeline.layout_chan.0.send(msg).unwrap(); - if receiver.recv().unwrap() { - return false; - } - // Check the visible rectangle for this pipeline. If the constellation has received a // size for the pipeline, then its painting should be up to date. If the constellation // *hasn't* received a size, it could be that the layer was hidden by script before the