From 894f147252004df51ab0980807e15b92cfe12e24 Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Wed, 19 Oct 2016 14:03:46 -0700 Subject: [PATCH] Fix order of layout application. (#5694) The old code potentially ran layout before initializing all custom elements leading to measurement errors. The fix is simple: The nesting that led to this wasn't actually needed at all. For the future: `pass.js` should actually schedule a chunk for immediate execution. --- src/amp.js | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/amp.js b/src/amp.js index 48e2a7bcb182..97dab3120256 100644 --- a/src/amp.js +++ b/src/amp.js @@ -75,29 +75,24 @@ chunk(self.document, function initial() { installBuiltins(self); }); chunk(self.document, function adoptWindow() { - try { - adopt(self); - } finally { - // Everything from here is nested because adopt itself - // may add additional chunks that should run first. - chunk(self.document, function stub() { - stubElements(self); - }); - chunk(self.document, function final() { - installPullToRefreshBlocker(self); - installGlobalClickListenerForDoc(ampdoc); + adopt(self); + }); + chunk(self.document, function stub() { + stubElements(self); + }); + chunk(self.document, function final() { + installPullToRefreshBlocker(self); + installGlobalClickListenerForDoc(ampdoc); - maybeValidate(self); - makeBodyVisible(self.document, /* waitForServices */ true); - installCacheServiceWorker(self); - }); - chunk(self.document, function finalTick() { - perf.tick('e_is'); - // TODO(erwinm): move invocation of the `flush` method when we have the - // new ticks in place to batch the ticks properly. - perf.flush(); - }); - } + maybeValidate(self); + makeBodyVisible(self.document, /* waitForServices */ true); + installCacheServiceWorker(self); + }); + chunk(self.document, function finalTick() { + perf.tick('e_is'); + // TODO(erwinm): move invocation of the `flush` method when we have the + // new ticks in place to batch the ticks properly. + perf.flush(); }); }, /* opt_isRuntimeCss */ true, /* opt_ext */ 'amp-runtime'); });