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

fix forwarded dangling slots #5164

Merged
merged 6 commits into from
Jan 27, 2025
Merged

Conversation

jhefferman-sfdc
Copy link
Contributor

Details

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

GUS work item

W-17587763

@jhefferman-sfdc jhefferman-sfdc requested a review from a team as a code owner January 24, 2025 18:06
Comment on lines +35 to +36
// This will get overridden but requires initialization.
const slotAttributeValue = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it get overridden if it's const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ }

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what "dangling" means here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what "dangling" means here?

Copy link
Contributor Author

@jhefferman-sfdc jhefferman-sfdc Jan 24, 2025

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add that to the code comment 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If a slotAttributeValue is present, it is dangling and should be assigned to any slotted content. This behavior aligns with v1 and engine-dom.
If `slotAttributeValue` is set, it references a slot that does not exist, and the `slot` attribute should be set in the DOM. This behavior aligns with engine-server and engine-dom.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, much clearer

@@ -263,6 +275,7 @@ export const Element: Transformer<IrElement | IrExternalComponent | IrSlot> = fu

return [
bYield(b.literal(`<${node.name}`)),
...[bConditionallyYieldDanglingSlotName()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...[bConditionallyYieldDanglingSlotName()],
bConditionallyYieldDanglingSlotName(),

Creating and then spreading an array with one element is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thx

Comment on lines 127 to 133
const bConditionallyYieldDanglingSlotName = esTemplateWithYield`
{
if (slotAttributeValue) {
yield \` slot="\${slotAttributeValue}"\`;
}
}
`<EsBlockStatement>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const bConditionallyYieldDanglingSlotName = esTemplateWithYield`
{
if (slotAttributeValue) {
yield \` slot="\${slotAttributeValue}"\`;
}
}
`<EsBlockStatement>;
const bConditionallyYieldDanglingSlotName = esTemplateWithYield`
if (slotAttributeValue) {
yield \` slot="\${slotAttributeValue}"\`;
}
`<EsIfStatement>;

We don't need to use a block statement wrapper here, because there's no new variables being declared.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, copy paste error

@@ -32,6 +32,9 @@ const bExportTemplate = esTemplate`
let textContentBuffer = '';
let didBufferTextContent = false;

// This will get overridden but requires initialization.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This will get overridden but requires initialization.
// This gets shadowed in slotted content generators, but needs to be initialized for top-level slots

Is that right?

@jhefferman-sfdc jhefferman-sfdc merged commit 7556d0c into master Jan 27, 2025
11 checks passed
@jhefferman-sfdc jhefferman-sfdc deleted the jhefferman/slot-forwarding-fix branch January 27, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants