Skip to content

Commit 701f33f

Browse files
committed
fix(core): add isServer to scrollspy controller
1 parent 7d1546d commit 701f33f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ReactiveController, ReactiveControllerHost } from 'lit';
22

3+
import { isServer } from 'lit';
4+
35
export interface ScrollSpyControllerOptions extends IntersectionObserverInit {
46
/**
57
* Tag names of legal link children.
@@ -33,13 +35,15 @@ export class ScrollSpyController implements ReactiveController {
3335
static #instances = new Set<ScrollSpyController>;
3436

3537
static {
36-
addEventListener('scroll', () => {
37-
if (Math.round(window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
38-
this.#instances.forEach(ssc => {
39-
ssc.#setActive(ssc.#linkChildren.at(-1));
40-
});
41-
}
42-
}, { passive: true });
38+
if (!isServer) {
39+
addEventListener('scroll', () => {
40+
if (Math.round(window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
41+
this.#instances.forEach(ssc => {
42+
ssc.#setActive(ssc.#linkChildren.at(-1));
43+
});
44+
}
45+
}, { passive: true });
46+
}
4347
}
4448

4549
#tagNames: string[];

0 commit comments

Comments
 (0)