ServerDrawer: guard folder-related store lookups against undefined stores
This commit is contained in:
parent
e07d071d7a
commit
d4083734be
2 changed files with 13 additions and 3 deletions
|
|
@ -30,7 +30,10 @@ function folderColor(color?: number | null): string {
|
|||
}
|
||||
|
||||
function FolderBadge({ node }: { node: GuildNode }) {
|
||||
const total = Flux?.useStateFromStores?.(
|
||||
// Same guard as useFolderExpanded in utils/theme.ts - GuildReadStateStore is a one-shot lookup
|
||||
// with no retry, and passing an undefined store into useStateFromStores throws instead of
|
||||
// failing safely, which would take the whole drawer down, not just this badge.
|
||||
const total = (Flux?.useStateFromStores && GuildReadStateStore) ? Flux.useStateFromStores(
|
||||
[GuildReadStateStore],
|
||||
() => {
|
||||
let sum = 0;
|
||||
|
|
@ -40,7 +43,7 @@ function FolderBadge({ node }: { node: GuildNode }) {
|
|||
return sum;
|
||||
},
|
||||
[node.children],
|
||||
) ?? 0;
|
||||
) : 0;
|
||||
|
||||
if (total > 0) {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -13,7 +13,14 @@ export function useTheme() {
|
|||
}
|
||||
|
||||
export function useFolderExpanded(folderId: string | number): boolean {
|
||||
return Flux?.useStateFromStores?.(
|
||||
// Confirmed live: an account with folders and one without exercise different code paths (this
|
||||
// hook is only ever called by FolderItem, which only exists when there's a folder to render) -
|
||||
// an account with no folders rendered fine while one with folders showed nothing at all.
|
||||
// ExpandedGuildFolderStore is a one-shot findByStoreName at module-eval time with no retry, so
|
||||
// if it hadn't registered yet, this passed [undefined] into useStateFromStores - which throws
|
||||
// rather than returning safely, taking down the whole drawer render, not just this one folder.
|
||||
if (!Flux?.useStateFromStores || !ExpandedGuildFolderStore) return false;
|
||||
return Flux.useStateFromStores(
|
||||
[ExpandedGuildFolderStore],
|
||||
() => {
|
||||
const folders = ExpandedGuildFolderStore?.getExpandedFolders?.();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue