Skip to content

fix forwarded dangling slots#5164

Merged
jhefferman-sfdc merged 6 commits intomasterfrom
jhefferman/slot-forwarding-fix
Jan 27, 2025
Merged

fix forwarded dangling slots#5164
jhefferman-sfdc merged 6 commits intomasterfrom
jhefferman/slot-forwarding-fix

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.

{ }

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.

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


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

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