Skip to content

Commit

Permalink
Fix slot to be transmitted as an attribute, not a property (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade authored Nov 19, 2024
1 parent c917461 commit 017ca02
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/pink-dryers-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@remote-dom/preact': patch
'@remote-dom/core': patch
---

Fix `slot` to be transmitted as an attribute, not a property
2 changes: 1 addition & 1 deletion packages/core/source/elements/RemoteElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ export abstract class RemoteElement<
attribute === 'slot' &&
(this.constructor as typeof RemoteElement).slottable
) {
updateRemoteElementProperty(
updateRemoteElementAttribute(
this,
attribute,
newValue ? String(newValue) : undefined,
Expand Down
26 changes: 26 additions & 0 deletions packages/core/source/tests/elements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,32 @@ describe('RemoteElement', () => {
]);
});

it('automatically serializes the slot attribute without any additional configuration', () => {
const ProductElement = createRemoteElement();

const receiver = new TestRemoteReceiver();

const root = createRemoteRootElement();
const element = createElementFromConstructor(ProductElement);
root.append(element);

const slot = 'aside';
element.setAttribute('slot', slot);

root.connect(receiver.connection);

expect(receiver.connection.mutate).toHaveBeenLastCalledWith([
[
MUTATION_TYPE_INSERT_CHILD,
remoteId(root),
expect.objectContaining({
attributes: {slot},
}),
0,
],
]);
});

it('reflects the value of a remote attribute automatically when the attribute is set', () => {
const ProductElement = createRemoteElement({
attributes: ['name'],
Expand Down
2 changes: 1 addition & 1 deletion packages/preact/source/host/hooks/props-for-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function usePropsForRemoteElement<

for (const child of children.value) {
let slot: string | undefined =
child.type === 1 ? (child.properties.peek().slot as any) : undefined;
child.type === 1 ? (child.attributes.peek().slot as any) : undefined;

if (typeof slot !== 'string') slot = undefined;

Expand Down

0 comments on commit 017ca02

Please sign in to comment.