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

chore(runtime): provide better error message for edge case where multiple runtimes are being used #5738

Merged
merged 5 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/runtime/set-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ export const getValue = (ref: d.RuntimeRef, propName: string) => getHostRef(ref)
export const setValue = (ref: d.RuntimeRef, propName: string, newVal: any, cmpMeta: d.ComponentRuntimeMeta) => {
// check our new property value against our internal value
const hostRef = getHostRef(ref);

/**
* If the host element is not found, let's fail with a better error message and provide
* details on why this may happen. In certain cases, e.g. see https://github.com/ionic-team/stencil/issues/5457,
* users might import a component through e.g. a loader script, which causes confusions in runtime
* as there are multiple runtimes being loaded and/or different components used with different
* loading strategies, e.g. lazy vs implicitly loaded.
*
* Todo(STENCIL-1308): remove, once a solution for this was identified and implemented
*/
if (BUILD.lazyLoad && !hostRef) {
throw new Error(
`Couldn't find host element for "${cmpMeta.$tagName$}" as it is ` +
'unknown to this Stencil runtime. This usually happens when integrating ' +
'a 3rd party Stencil component with another Stencil component or application. ' +
'Please reach out to the maintainers of the 3rd party Stencil component or report ' +
'this on the Stencil Discord server (https://chat.stenciljs.com) or comment ' +
'on this similar [GitHub issue](https://github.com/ionic-team/stencil/issues/5457).',
);
}

const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : (ref as d.HostElement);
const oldVal = hostRef.$instanceValues$.get(propName);
const flags = hostRef.$flags$;
Expand Down