Skip to content

Commit a127114

Browse files
committed
fix(core): ssr connected callback
1 parent 837f66a commit a127114

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

core/pfe-core/controllers/light-dom-controller.ts

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

33
import { Logger } from './logger.js';
44

@@ -52,9 +52,13 @@ export class LightDOMController implements ReactiveController {
5252
* Returns a boolean statement of whether or not this component contains any light DOM.
5353
*/
5454
hasLightDOM(): boolean {
55-
return !!(
56-
this.host.children.length > 0
57-
|| (this.host.textContent ?? '').trim().length > 0
58-
);
55+
if (isServer) {
56+
return false;
57+
} else {
58+
return !!(
59+
this.host.children.length > 0
60+
|| (this.host.textContent ?? '').trim().length > 0
61+
);
62+
}
5963
}
6064
}

core/pfe-core/controllers/scroll-spy-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class ScrollSpyController implements ReactiveController {
4444
#rootMargin?: string;
4545
#threshold: number | number[];
4646

47-
#getRootNode: () => Node;
47+
#getRootNode: () => Node | null;
4848
#getHash: (el: Element) => string | null;
4949

5050
get #linkChildren(): Element[] {
@@ -92,7 +92,7 @@ export class ScrollSpyController implements ReactiveController {
9292
this.#rootMargin = options.rootMargin;
9393
this.#activeAttribute = options.activeAttribute ?? 'active';
9494
this.#threshold = options.threshold ?? 0.85;
95-
this.#getRootNode = () => options.rootNode ?? host.getRootNode();
95+
this.#getRootNode = () => options.rootNode ?? host.getRootNode?.() ?? null;
9696
this.#getHash = options?.getHash ?? ((el: Element) => el.getAttribute('href'));
9797
}
9898

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ export class SlotController implements ReactiveController {
191191
#getChildrenForSlot<T extends Element = Element>(
192192
name: string | typeof SlotController.default,
193193
): T[] {
194-
const children = Array.from(this.host.children) as T[];
195-
return children.filter(isSlot(name));
194+
if (isServer) {
195+
return [];
196+
} else {
197+
const children = Array.from(this.host.children) as T[];
198+
return children.filter(isSlot(name));
199+
}
196200
}
197201

198202
#initSlot = (slotName: string | null) => {

0 commit comments

Comments
 (0)