From c85622e44889825213505825d779978c8e2a54cf Mon Sep 17 00:00:00 2001 From: artem-galas Date: Sat, 26 Jul 2025 16:20:03 +0300 Subject: [PATCH] feat: check if Animation exist before load --- package.json | 4 ++-- src/components/Avatar/Avatar.component.tsx | 11 +++++++++-- src/services/Animation.service.ts | 9 ++++++++- src/types/index.ts | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6f7a1a6..3ed71fb 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "npm": ">=8.6.0" }, "volta": { - "node": "18.0.0", + "node": "20.19.4", "npm": "8.6.0" }, "dependencies": { @@ -163,4 +163,4 @@ "jotai": "^2.2.2", "qs": "^6.12.3" } -} \ No newline at end of file +} diff --git a/src/components/Avatar/Avatar.component.tsx b/src/components/Avatar/Avatar.component.tsx index 35fed68..92eeee3 100644 --- a/src/components/Avatar/Avatar.component.tsx +++ b/src/components/Avatar/Avatar.component.tsx @@ -86,7 +86,7 @@ export interface AvatarProps extends LightingProps, EnvironmentProps, Omit = ({ {AvatarModel} {children} {shadows && ( - + )} {background?.src && } {capture && } diff --git a/src/services/Animation.service.ts b/src/services/Animation.service.ts index 75e6831..48eb2dd 100644 --- a/src/services/Animation.service.ts +++ b/src/services/Animation.service.ts @@ -218,7 +218,14 @@ export const useAnimations = (animations: AnimationsT) => await Promise.all( Object.entries(animations).map(async ([name, { key }]) => { - const newClips = await loadAnimationClips(animations[name].source); + const animation = animations[name]; + + if (!animation?.source) { + console.warn(`Could not load animation ${name}`); + return; + } + + const newClips = await loadAnimationClips(animation.source); const newClip = key ? newClips.find((item) => item?.name === key) || newClips[0] : newClips[0]; if (newClip) { diff --git a/src/types/index.ts b/src/types/index.ts index 7297241..5e0ecf9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -199,7 +199,7 @@ export type AnimationsT = Record< string, { key?: string; - source: string; + source?: string; repeat?: number; fadeTime?: number; }