From 2cf382c52dce4354f0ae345c42564c4ef1758d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20de=20Fran=C3=A7a?= <448801+fernandofranca@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:32:20 +0200 Subject: [PATCH] feat(pie-lottie-player): DSW-2365 replace utility method with isServer --- .../components/pie-lottie-player/src/index.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/components/pie-lottie-player/src/index.ts b/packages/components/pie-lottie-player/src/index.ts index 95184d4a41..803e153622 100644 --- a/packages/components/pie-lottie-player/src/index.ts +++ b/packages/components/pie-lottie-player/src/index.ts @@ -1,4 +1,6 @@ -import { LitElement, html, unsafeCSS } from 'lit'; +import { + LitElement, html, isServer, unsafeCSS, +} from 'lit'; import { property, query } from 'lit/decorators.js'; import { LottiePlayer, AnimationItem } from 'lottie-web'; @@ -29,11 +31,11 @@ export class PieLottiePlayer extends LitElement implements LottiePlayerProps { protected async firstUpdated (): Promise { // Check if the code is running in a browser environment - if (this._canUseDOM()) { - const { default: lottieModule } = await import('lottie-web/build/player/lottie_light_canvas.min.js'); // Dynamically import the 'lottie-web' library to avoid SSR issues - this._lottie = lottieModule; - this._loadAnimation(); - } + if (isServer) return; + + const { default: lottieModule } = await import('lottie-web/build/player/lottie_light_canvas.min.js'); // Dynamically import the 'lottie-web' library to avoid SSR issues + this._lottie = lottieModule; + this._loadAnimation(); } disconnectedCallback () { @@ -41,12 +43,8 @@ export class PieLottiePlayer extends LitElement implements LottiePlayerProps { this._destroyAnimation(); } - private _canUseDOM () { - return typeof window !== 'undefined' && 'document' in window && 'createElement' in window.document; - } - private _loadAnimation (): void { - if (!this._canUseDOM()) return; + if (isServer) return; if (!this._hostElement) return; if (!this._lottie) return;