diff --git a/src/runtime/bootstrap-lazy.ts b/src/runtime/bootstrap-lazy.ts index 462c48652a0..1e403e23bf9 100644 --- a/src/runtime/bootstrap-lazy.ts +++ b/src/runtime/bootstrap-lazy.ts @@ -8,7 +8,7 @@ import { BUILD } from '@build-conditionals'; import { doc, getHostRef, plt, registerHost, supportsShadowDom, win } from '@platform'; import { hmrStart } from './hmr-component'; import { HYDRATE_ID, PLATFORM_FLAGS, PROXY_FLAGS } from './runtime-constants'; -import { postUpdateComponent, scheduleUpdate } from './update-component'; +import { postUpdateComponent, forceUpdate } from './update-component'; export const bootstrapLazy = (lazyBundles: d.LazyBundlesRuntimeData, options: d.CustomElementsDefineOptions = {}) => { @@ -105,15 +105,7 @@ export const bootstrapLazy = (lazyBundles: d.LazyBundlesRuntimeData, options: d. } forceUpdate() { - if (BUILD.updatable) { - const hostRef = getHostRef(this); - scheduleUpdate( - this, - hostRef, - cmpMeta, - false - ); - } + forceUpdate(this, cmpMeta); } componentOnReady() { diff --git a/src/runtime/bootstrap-native.ts b/src/runtime/bootstrap-native.ts index af7299563b6..2823f0a440f 100644 --- a/src/runtime/bootstrap-native.ts +++ b/src/runtime/bootstrap-native.ts @@ -1,12 +1,12 @@ import * as d from '../declarations'; -import { getHostRef, supportsShadowDom } from '@platform'; +import { supportsShadowDom } from '@platform'; import { BUILD } from '@build-conditionals'; import { CMP_FLAGS } from '@utils'; import { connectedCallback } from './connected-callback'; import { disconnectedCallback } from './disconnected-callback'; import { proxyComponent } from './proxy-component'; import { PROXY_FLAGS } from './runtime-constants'; -import { scheduleUpdate } from './update-component'; +import { forceUpdate } from './update-component'; export const attachShadow = (el: HTMLElement) => { if (supportsShadowDom) { @@ -33,15 +33,7 @@ export const proxyNative = (Cstr: any, compactMeta: d.ComponentRuntimeMetaCompac Object.assign(Cstr.prototype, { forceUpdate() { - if (BUILD.updatable) { - const hostRef = getHostRef(this); - scheduleUpdate( - this, - hostRef, - cmpMeta, - false - ); - } + forceUpdate(this, cmpMeta); }, connectedCallback() { connectedCallback(this, cmpMeta); diff --git a/src/runtime/update-component.ts b/src/runtime/update-component.ts index 86e99f91f08..93b7be99fb3 100644 --- a/src/runtime/update-component.ts +++ b/src/runtime/update-component.ts @@ -216,6 +216,19 @@ export const postUpdateComponent = (elm: d.HostElement, hostRef: d.HostRef, ance } }; +export const forceUpdate = (elm: d.RenderNode, cmpMeta: d.ComponentRuntimeMeta) => { + if (BUILD.updatable) { + const hostRef = getHostRef(this); + if (hostRef.$flags$ & HOST_FLAGS.hasRendered) { + scheduleUpdate( + elm, + hostRef, + cmpMeta, + false + ); + } + } +}; const emitLifecycleEvent = (elm: d.HostElement, lifecycleName: string) => { if (BUILD.lifecycleDOMEvents) {