Skip to content

Commit 2f2c63b

Browse files
zeroedinbennypowers
authored andcommitted
fix(core): add isServer to scrollspy controller
Co-authored-by: Steven Spriggs <[email protected]>
1 parent 523f948 commit 2f2c63b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ export class ScrollSpyController implements ReactiveController {
3535
static #instances = new Set<ScrollSpyController>;
3636

3737
static {
38-
addEventListener('scroll', () => {
39-
if (Math.round(window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
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+
addEventListener('hashchange', () => {
4047
this.#instances.forEach(ssc => {
41-
ssc.#setActive(ssc.#linkChildren.at(-1));
48+
ssc.#activateHash();
4249
});
43-
}
44-
}, { passive: true });
45-
addEventListener('hashchange', () => {
46-
this.#instances.forEach(ssc => {
47-
ssc.#activateHash();
4850
});
49-
});
51+
}
5052
}
5153

5254
#tagNames: string[];

0 commit comments

Comments
 (0)