-
Notifications
You must be signed in to change notification settings - Fork 396
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
Show compiler warning/error for slot
attribute not at the top level
#4703
Comments
slot
attribute not at the top levelslot
attribute not at the top level
Doing a warning here is up for grabs, but doing an error is trickier so would probably have to be done with API versioning. |
The full list of lwc/packages/@lwc/template-compiler/src/shared/types.ts Lines 321 to 331 in e337b3c
Off the top of my head, the ones that are "valid" to have between the component ( |
@nolanlawson this warning would need to be ignored here due to fixtures added in #4689 right? lwc/packages/@lwc/engine-server/src/__tests__/fixtures.spec.ts Lines 57 to 66 in cd41384
Example: Lines 15 to 19 in cd41384
|
Yes, true. |
In the case above, the developer is probably confused because they seem to be trying to slot something into the
foo
slot of<x-inner>
, but since it's inside a<div>
, the whole<div>
is actually treated as the default slotted content, and theslot
attribute is effectively ignored. This works in all three of native shadow, synthetic shadow, and light DOM slots.There are valid cases where it's not at the top level, e.g.:
In this case, the
<span>
would truly go into thefoo
slot since the<template lwc:if>
is not a "real" element.We should enumerate all the cases where the
slot
attribute is valid or invalid when not at the top level and warn for it. Potentially in the future we could even throw an error to be more explicit.The text was updated successfully, but these errors were encountered: