From 795c6161814a5e152ce9a2ab08315170d41f0c11 Mon Sep 17 00:00:00 2001 From: Alan Orozco Date: Fri, 16 Nov 2018 12:58:47 -0800 Subject: [PATCH 1/2] Trick Closure compiler to maintain reflow codepath --- .../amp-gwd-animation/0.1/amp-gwd-animation-impl.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js b/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js index fca7dababee8..d9580ea84208 100644 --- a/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js +++ b/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js @@ -498,5 +498,11 @@ export class AmpGwdRuntimeService { * @param {!Element} element */ function reflow(element) { - return element./*OK*/offsetWidth; + const value = element./*OK*/offsetWidth; + // exporting global to trick Closure into thinking this function has side + // effects. + const globalRef = '__AMP_TEMP'; + self[globalRef] = value; + delete self[globalRef]; + return value; } From 3e62193ed691140a40690b8d08955e75fda8fc9b Mon Sep 17 00:00:00 2001 From: Alan Orozco Date: Fri, 16 Nov 2018 13:21:04 -0800 Subject: [PATCH 2/2] Address review --- extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js b/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js index d9580ea84208..923cc4d3c2c4 100644 --- a/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js +++ b/extensions/amp-gwd-animation/0.1/amp-gwd-animation-impl.js @@ -498,11 +498,10 @@ export class AmpGwdRuntimeService { * @param {!Element} element */ function reflow(element) { - const value = element./*OK*/offsetWidth; // exporting global to trick Closure into thinking this function has side // effects. - const globalRef = '__AMP_TEMP'; - self[globalRef] = value; + const globalRef = '__AMP_GWD_TEMP'; + // Reading `offsetWidth` is what actually causes reflow. + self[globalRef] = element./*OK*/offsetWidth; delete self[globalRef]; - return value; }