From 2ba24b1e109b27daa69a8e9a4571a3a6d0577e70 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 30 Jun 2020 15:03:56 -0500 Subject: [PATCH] fix(treeshaking): update build conditional treeskaking optimization --- src/runtime/update-component.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/runtime/update-component.ts b/src/runtime/update-component.ts index 98e5bf70639..112f0e4a34c 100644 --- a/src/runtime/update-component.ts +++ b/src/runtime/update-component.ts @@ -146,15 +146,23 @@ const updateComponent = (hostRef: d.HostRef, instance: any, isInitialLoad: boole let renderingRef: any = null; const callRender = (hostRef: d.HostRef, instance: any) => { + // in order for bundlers to correctly treeshake the BUILD object + // we need to ensure BUILD is not deoptimized within a try/catch + // https://rollupjs.org/guide/en/#treeshake tryCatchDeoptimization + const allRenderFn = BUILD.allRenderFn ? true : false; + const lazyLoad = BUILD.lazyLoad ? true : false; + const taskQueue = BUILD.taskQueue ? true : false; + const updatable = BUILD.updatable ? true : false; + try { renderingRef = instance; - instance = BUILD.allRenderFn ? instance.render() : instance.render && instance.render(); + instance = allRenderFn ? instance.render() : instance.render && instance.render(); - if (BUILD.updatable && BUILD.taskQueue) { + if (updatable && taskQueue) { hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate; } - if (BUILD.updatable || BUILD.lazyLoad) { + if (updatable || lazyLoad) { hostRef.$flags$ |= HOST_FLAGS.hasRendered; } } catch (e) {