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

renderMode mismatch between template/compiler and light/shadow causes console.error but no error #4663

Open
Tracked by #2964
nolanlawson opened this issue Oct 18, 2024 · 0 comments

Comments

@nolanlawson
Copy link
Collaborator

If you mismatch a template in one render mode with a component in another render mode:

<template lwc:render-mode=light>
</template>
export default class extends LightningElement {
  static renderMode = 'shadow'
}

Then you get a console.error but no actual error:

if (vm.renderMode === RenderMode.Light) {
if (template.renderMode !== 'light') {
logError(
`Light DOM components can't render shadow DOM templates. Add an 'lwc:render-mode="light"' directive to the root template tag of ${getComponentTag(
vm
)}.`
);
}
} else {
if (!isUndefined(template.renderMode)) {
logError(
`Shadow DOM components template can't render light DOM templates. Either remove the 'lwc:render-mode' directive from ${getComponentTag(
vm
)} or set it to 'lwc:render-mode="shadow"`
);
}
}

At runtime, the only thing that matters is the component renderMode, not the template renderMode (except for this console.error).

We should make this an actual error. This would allow us to know with 100% confidence whether a template will be treated as light DOM or shadow DOM. This would help with e.g. the @lwc/template-compiler (which has certain restrictions on light vs shadow DOM, e.g. lwc:dom="manual" or scoped slots) as well as the new @lwc/ssr-compiler (it would be easier to know that a <slot> for example is light vs shadow).

Repro: 92d0bdd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant