salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 393 forks source link

Can't assign templates to slots? #2658

Closed AndrewRayCode closed 2 years ago

AndrewRayCode commented 2 years ago

Description

Steps to Reproduce

<template slot="name"></template>

Expected Results

This should work

Actual Results

The component crashes

Browsers Affected

All

Version

Salesforce

pmdartus commented 2 years ago

In LWC template, <template> elements are considered as container elements should be associated with other directives like for:each or if:*. The <template> elements aren't actually created in the DOM. Since those elements don't have an actual DOM representation, you can't assign standard attributes including slot.

AndrewRayCode commented 2 years ago

Makes sense. This adds some friction to the development process, because:

Maybe I just need to learn the API better. Wanted to share my initial reaction to inconsistent template vs other tag usage

caridy commented 2 years ago

@AndrewRayCode this is interesting. So, you were planning to render a <template>, giving it to some other component via a slot, but it will render no content in the UI. Yes, this is perfectly fine, but my question is: what is the other component supposed to be doing with that template? is the other component LWC? That's probably were the ball drops because receiving a template element in LWC is not super useful since you can't really clone that template and dump into an LWC.

In general, I'm sympathetic with the idea of loosing the restriction of the template elements in HTML files in LWC, and treat them as regular elements. @pmdartus we might have a path forward here without breaking people.