Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): prevent watchers from prematurely firing in custom elements build #2971

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ export interface ConfigExtras {

/**
* When a component is first attached to the DOM, this setting will wait a single tick before
* rendering. This worksaround an Angular issue, where Angular attaches the elements before
* settings their initial state, leading to double renders and unnecesary event dispatchs.
* rendering. This works around an Angular issue, where Angular attaches the elements before
* settings their initial state, leading to double renders and unnecessary event dispatches.
* Defaults to `false`.
*/
initializeNextTick?: boolean;
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/initialize-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const initializeComponent = async (elm: d.HostElement, hostRef: d.HostRef
throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
}
if (BUILD.member && !Cstr.isProxied) {
// we'eve never proxied this Constructor before
// we've never proxied this Constructor before
// let's add the getters/setters to its prototype before
// the first time we create an instance of the implementation
if (BUILD.watchCallback) {
Expand Down Expand Up @@ -68,7 +68,11 @@ export const initializeComponent = async (elm: d.HostElement, hostRef: d.HostRef
} else {
// sync constructor component
Cstr = elm.constructor as any;
hostRef.$flags$ |= HOST_FLAGS.isWatchReady | HOST_FLAGS.hasInitializedComponent;
hostRef.$flags$ |= HOST_FLAGS.hasInitializedComponent;
// wait for the CustomElementRegistry to mark the component as ready before setting `isWatchReady`. Otherwise,
// watchers may fire prematurely if `customElements.get()`/`customElements.whenDefined()` resolves _before_
// Stencil has completed instantiating the component.
customElements.whenDefined(cmpMeta.$tagName$).then(() => hostRef.$flags$ |= HOST_FLAGS.isWatchReady)
}

if (BUILD.style && Cstr.style) {
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const enum PROXY_FLAGS {
}

export const enum PLATFORM_FLAGS {
// designates a node in the DOM as being actively moved by the runtime
isTmpDisconnected = 1 << 0,
appLoaded = 1 << 1,
queueSync = 1 << 2,
Expand Down