Skip to content

Commit 453280b

Browse files
committed
fix: keep isServer in client-side slot controller
pending later PR
1 parent dd752d5 commit 453280b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

core/pfe-core/controllers/slot-controller.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ReactiveController, type ReactiveElement } from 'lit';
1+
import { isServer, type ReactiveController, type ReactiveElement } from 'lit';
22

33
interface AnonymousSlot {
44
hasContent: boolean;
@@ -113,24 +113,32 @@ export class SlotController implements ReactiveController {
113113
const elements = this.#getChildrenForSlot(slotId);
114114
const slot = this.#getSlotElement(slotId);
115115
const hasContent =
116-
!!elements.length || !!slot?.assignedNodes?.()?.filter(x => x.textContent?.trim()).length;
116+
!isServer
117+
&& !!elements.length
118+
|| !!slot?.assignedNodes?.()?.filter(x => x.textContent?.trim()).length;
117119
this.#nodes.set(slotId, { elements, name, hasContent, slot });
118120
}
119121
this.host.requestUpdate();
120122
this.#slotMapInitialized = true;
121123
}
122124

123125
#getSlotElement(slotId: string | symbol) {
124-
const selector =
126+
if (isServer) {
127+
return null;
128+
} else {
129+
const selector =
125130
slotId === SlotController.default ? 'slot:not([name])' : `slot[name="${slotId as string}"]`;
126-
return this.host.shadowRoot?.querySelector<HTMLSlotElement>(selector) ?? null;
131+
return this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;
132+
}
127133
}
128134

129135
#getChildrenForSlot<T extends Element = Element>(
130136
name: string | typeof SlotController.default,
131137
): T[] {
132-
if (this.#nodes.has(name)) {
133-
return (this.#nodes.get(name)!.slot?.assignedElements() ?? []) as T[];
138+
if (isServer) {
139+
return [];
140+
} else if (this.#nodes.has(name)) {
141+
return (this.#nodes.get(name)!.slot?.assignedElements?.() ?? []) as T[];
134142
} else {
135143
const children = Array.from(this.host.children) as T[];
136144
return children.filter(isSlot(name));

core/pfe-core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"./controllers/roving-tabindex-controller.js": "./controllers/roving-tabindex-controller.js",
3434
"./controllers/scroll-spy-controller.js": "./controllers/scroll-spy-controller.js",
3535
"./controllers/slot-controller.js": {
36-
"node": "./controllers/slot-controller-server.js",
3736
"import": "./controllers/slot-controller.js",
3837
"default": "./controllers/slot-controller.js"
3938
},

0 commit comments

Comments
 (0)