-
Notifications
You must be signed in to change notification settings - Fork 401
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 forwarded dangling slots #5164
Changes from 2 commits
cbe6460
c166486
7460711
721e063
572884c
66efe27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<template lwc:render-mode="light"> | ||
<x-slot> | ||
<h1 slot="top">top content</h1> | ||
<h1 slot="bottom">bottom content</h1> | ||
<h2 slot="bottom">bottom content</h2> | ||
</x-slot> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<template lwc:render-mode="light"> | ||
<slot name="top" slot="bottom"></slot> | ||
<slot name="bottom"></slot> | ||
<slot name="leafTop" slot="dangling"></slot> | ||
<slot name="leafBottom"></slot> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<template lwc:render-mode="light"> | ||
<x-leaf> | ||
<slot name="top" slot="bottom"></slot> | ||
<slot name="bottom" slot="top"></slot> | ||
<slot name="top" slot="leafTop"></slot> | ||
<slot name="bottom" slot="leafBottom"></slot> | ||
</x-leaf> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ const bExportTemplate = esTemplate` | |
let textContentBuffer = ''; | ||
let didBufferTextContent = false; | ||
// This will get overridden but requires initialization. | ||
const slotAttributeValue = null; | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does it get overridden if it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. { } |
||
// Establishes a contextual relationship between two components for ContextProviders. | ||
// This variable will typically get overridden (shadowed) within slotted content. | ||
const contextfulParent = instance; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,13 @@ const bYieldFromChildGenerator = esTemplateWithYield` | |
{ | ||
const childProps = ${/* child props */ is.objectExpression}; | ||
const childAttrs = ${/* child attrs */ is.objectExpression}; | ||
/* | ||
If a slotAttributeValue is present, it is dangling and should be assigned to any slotted content. This behavior aligns with v1 and engine-dom. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify what "dangling" means here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
See: engine-server/src/__tests__/fixtures/slot-forwarding/slots/dangling/ for example case. | ||
*/ | ||
if (slotAttributeValue) { | ||
childAttrs.slot = slotAttributeValue; | ||
} | ||
${ | ||
/* | ||
Slotted content is inserted here. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,6 +25,13 @@ const bYieldFromDynamicComponentConstructorGenerator = esTemplateWithYield` | |||||
} | ||||||
const childProps = ${/* child props */ is.objectExpression}; | ||||||
const childAttrs = ${/* child attrs */ is.objectExpression}; | ||||||
/* | ||||||
If a slotAttributeValue is present, it is dangling and should be assigned to any slotted content. This behavior aligns with v1 and engine-dom. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify what "dangling" means here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A slot that is referenced but does not exist (see example fixture on the line below) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add that to the code comment 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, much clearer |
||||||
See: engine-server/src/__tests__/fixtures/slot-forwarding/slots/dangling/ for example case. | ||||||
*/ | ||||||
if (slotAttributeValue) { | ||||||
childAttrs.slot = slotAttributeValue; | ||||||
} | ||||||
${ | ||||||
/* | ||||||
Slotted content is inserted here. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -120,6 +120,18 @@ const bConditionallyYieldScopeTokenClass = esTemplateWithYield` | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
`<EsIfStatement>; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||
If a slotAttributeValue is present, it is dangling and should be assigned to any slotted content. This behavior aligns with v1 and engine-dom. | ||||||||||||||||||||||||||
See: engine-server/src/__tests__/fixtures/slot-forwarding/slots/dangling/ for example case. | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
const bConditionallyYieldDanglingSlotName = esTemplateWithYield` | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
if (slotAttributeValue) { | ||||||||||||||||||||||||||
yield \` slot="\${slotAttributeValue}"\`; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
`<EsBlockStatement>; | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We don't need to use a block statement wrapper here, because there's no new variables being declared. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, copy paste error |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const bYieldSanitizedHtml = esTemplateWithYield` | ||||||||||||||||||||||||||
yield sanitizeHtmlContent(${/* lwc:inner-html content */ is.expression}) | ||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||
|
@@ -263,6 +275,7 @@ export const Element: Transformer<IrElement | IrExternalComponent | IrSlot> = fu | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return [ | ||||||||||||||||||||||||||
bYield(b.literal(`<${node.name}`)), | ||||||||||||||||||||||||||
...[bConditionallyYieldDanglingSlotName()], | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Creating and then spreading an array with one element is unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thx |
||||||||||||||||||||||||||
// If we haven't already prefixed the scope token to an existing class, add an explicit class here | ||||||||||||||||||||||||||
...(hasClassAttribute ? [] : [bConditionallyYieldScopeTokenClass()]), | ||||||||||||||||||||||||||
...yieldAttrsAndProps, | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that right?