ServerDrawer: guard folder-related store lookups against undefined stores

This commit is contained in:
Ally Founder 2026-08-11 10:20:27 -04:00
parent e07d071d7a
commit d4083734be
2 changed files with 13 additions and 3 deletions

View file

@ -30,7 +30,10 @@ function folderColor(color?: number | null): string {
} }
function FolderBadge({ node }: { node: GuildNode }) { 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], [GuildReadStateStore],
() => { () => {
let sum = 0; let sum = 0;
@ -40,7 +43,7 @@ function FolderBadge({ node }: { node: GuildNode }) {
return sum; return sum;
}, },
[node.children], [node.children],
) ?? 0; ) : 0;
if (total > 0) { if (total > 0) {
return ( return (

View file

@ -13,7 +13,14 @@ export function useTheme() {
} }
export function useFolderExpanded(folderId: string | number): boolean { 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], [ExpandedGuildFolderStore],
() => { () => {
const folders = ExpandedGuildFolderStore?.getExpandedFolders?.(); const folders = ExpandedGuildFolderStore?.getExpandedFolders?.();