Decor: Prevent more crashes
This commit is contained in:
parent
69dc4fd594
commit
7ef536c6c6
1 changed files with 20 additions and 11 deletions
|
@ -99,7 +99,9 @@ export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | nu
|
||||||
const [decorAvatarDecoration, setDecorAvatarDecoration] = useState<string | null>(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null);
|
const [decorAvatarDecoration, setDecorAvatarDecoration] = useState<string | null>(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const destructor = useUsersDecorationsStore.subscribe(
|
const destructor = (() => {
|
||||||
|
try {
|
||||||
|
return useUsersDecorationsStore.subscribe(
|
||||||
state => {
|
state => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
const newDecorAvatarDecoration = state.getAsset(user.id);
|
const newDecorAvatarDecoration = state.getAsset(user.id);
|
||||||
|
@ -107,11 +109,18 @@ export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | nu
|
||||||
if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration);
|
if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
} catch {
|
||||||
|
return () => { };
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
if (user) {
|
if (user) {
|
||||||
const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState();
|
const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState();
|
||||||
fetchUserDecorAvatarDecoration(user.id);
|
fetchUserDecorAvatarDecoration(user.id);
|
||||||
}
|
}
|
||||||
|
} catch { }
|
||||||
|
|
||||||
return destructor;
|
return destructor;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue