From 7ef536c6c68f60ac94e89f37968ef83ef3d4b35a Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:02:56 -0300 Subject: [PATCH] Decor: Prevent more crashes --- .../decor/lib/stores/UsersDecorationsStore.ts | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/plugins/decor/lib/stores/UsersDecorationsStore.ts b/src/plugins/decor/lib/stores/UsersDecorationsStore.ts index a75115a3f..f47ccbc56 100644 --- a/src/plugins/decor/lib/stores/UsersDecorationsStore.ts +++ b/src/plugins/decor/lib/stores/UsersDecorationsStore.ts @@ -99,19 +99,28 @@ export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | nu 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); + const destructor = (() => { + try { + return useUsersDecorationsStore.subscribe( + state => { + if (!user) return; + const newDecorAvatarDecoration = state.getAsset(user.id); + if (!newDecorAvatarDecoration) return; + if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration); + } + ); + } catch { + return () => { }; } - ); + })(); + + try { + if (user) { + const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState(); + fetchUserDecorAvatarDecoration(user.id); + } + } catch { } - if (user) { - const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState(); - fetchUserDecorAvatarDecoration(user.id); - } return destructor; }, []);