Skip to content

Commit

Permalink
fix(runtime): prevent forceUpdate before first render
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jun 27, 2019
1 parent e5bae1b commit 67b4ae8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
12 changes: 2 additions & 10 deletions src/runtime/bootstrap-lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) => {
Expand Down Expand Up @@ -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() {
Expand Down
14 changes: 3 additions & 11 deletions src/runtime/bootstrap-native.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/runtime/update-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 67b4ae8

Please sign in to comment.