From e69eb50bb2887de6e40befd12231ebdd3c25babc Mon Sep 17 00:00:00 2001 From: Daniel Macak Date: Mon, 11 Nov 2024 22:51:38 +0100 Subject: [PATCH] fix(gallery): exclude browser APIs from SSR in thumbs --- .../lib/components/thumbs/thumbs.component.ts | 2 +- .../lib/components/viewer/viewer.component.ts | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libs/gallery/src/lib/components/thumbs/thumbs.component.ts b/libs/gallery/src/lib/components/thumbs/thumbs.component.ts index 5b085444..495109fa 100644 --- a/libs/gallery/src/lib/components/thumbs/thumbs.component.ts +++ b/libs/gallery/src/lib/components/thumbs/thumbs.component.ts @@ -261,7 +261,7 @@ export class ThumbsComponent implements OnChanges, OnDestroy { }; private observeArrows() { - if (this.thumbsEmpty) return; + if (this.thumbsEmpty || !isBrowser) return; if (!this.arrowObserver) { this.arrowObserver = new IntersectionObserver(this.onArrowsObserved, { diff --git a/libs/gallery/src/lib/components/viewer/viewer.component.ts b/libs/gallery/src/lib/components/viewer/viewer.component.ts index 008ef27f..08632585 100644 --- a/libs/gallery/src/lib/components/viewer/viewer.component.ts +++ b/libs/gallery/src/lib/components/viewer/viewer.component.ts @@ -173,18 +173,20 @@ export class ViewerComponent implements OnChanges, OnInit, AfterViewInit { } ngOnInit() { - if (isBrowser) { - this.handleResizes(); + if (!isBrowser) { + return; + } - if (this.mouseGestures) { - this.handleMouseSlides(); - } + this.handleResizes(); - if (this.touchGestures) { - this.handleTouchSlides(); - } - this._destroyRef.onDestroy(() => this.fringeObserver?.disconnect()); + if (this.mouseGestures) { + this.handleMouseSlides(); + } + + if (this.touchGestures) { + this.handleTouchSlides(); } + this._destroyRef.onDestroy(() => this.fringeObserver?.disconnect()); } ngAfterViewInit() {