From 1fe7912ec14fd5873d41ea8114d4f23914c283f1 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:23:07 -0300 Subject: [PATCH] Decor: Prevent crashing from useUserDecorAvatarDecoration --- .../decor/lib/stores/UsersDecorationsStore.ts | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/plugins/decor/lib/stores/UsersDecorationsStore.ts b/src/plugins/decor/lib/stores/UsersDecorationsStore.ts index 53aa33e63..a75115a3f 100644 --- a/src/plugins/decor/lib/stores/UsersDecorationsStore.ts +++ b/src/plugins/decor/lib/stores/UsersDecorationsStore.ts @@ -95,24 +95,30 @@ export const useUsersDecorationsStore = proxyLazy(() => zustandCreate((set: any, } as UsersDecorationsState))); export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | null | undefined { - const [decorAvatarDecoration, setDecorAvatarDecoration] = useState(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null); + try { + const [decorAvatarDecoration, setDecorAvatarDecoration] = useState(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null); - useEffect(() => { - const destructor = useUsersDecorationsStore.subscribe( - state => { - if (!user) return; - const newDecorAvatarDecoration = state.getAsset(user.id); - if (!newDecorAvatarDecoration) return; - if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration); + useEffect(() => { + const destructor = useUsersDecorationsStore.subscribe( + state => { + if (!user) return; + const newDecorAvatarDecoration = state.getAsset(user.id); + if (!newDecorAvatarDecoration) return; + if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration); + } + ); + + if (user) { + const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState(); + fetchUserDecorAvatarDecoration(user.id); } - ); + return destructor; + }, []); - if (user) { - const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState(); - fetchUserDecorAvatarDecoration(user.id); - } - return destructor; - }, []); + return decorAvatarDecoration ? { asset: decorAvatarDecoration, skuId: SKU_ID } : null; + } catch (e) { + console.error(e); + } - return decorAvatarDecoration ? { asset: decorAvatarDecoration, skuId: SKU_ID } : null; + return null; }