fix: guard auto-channel redirect against stale cross-server channels

The redirect effect used the shared `channels` array which could contain
stale data from a previously viewed server during async loadServerDetail.
Added channelToServerMap ownership check to ensure channels belong to
the target server before redirecting. Also persists last-visited channel
per server in localStorage for better return navigation.
This commit is contained in:
Jannis Braun
2026-03-05 01:57:49 +01:00
parent b642989e6e
commit aef15a7cf7
2 changed files with 38 additions and 2 deletions
+8
View File
@@ -46,6 +46,8 @@ interface UIState {
closeUserProfile: () => void;
addToast: (message: string, type?: 'info' | 'warning' | 'success', duration?: number) => void;
removeToast: (id: string) => void;
lastChannelPerServer: Record<string, string>;
setLastChannel: (serverId: string, channelId: string) => void;
voiceChatOpen: boolean;
voiceFullscreen: boolean;
pipCollapsed: boolean;
@@ -110,6 +112,11 @@ export const useUIStore = create<UIState>()(
},
removeToast: (id) => set((state) => ({ toasts: state.toasts.filter(t => t.id !== id) })),
lastChannelPerServer: {},
setLastChannel: (serverId, channelId) => set((state) => ({
lastChannelPerServer: { ...state.lastChannelPerServer, [serverId]: channelId },
})),
voiceChatOpen: false,
voiceFullscreen: false,
pipCollapsed: false,
@@ -123,6 +130,7 @@ export const useUIStore = create<UIState>()(
storage: createJSONStorage(() => localStorage),
partialize: (state) => ({
memberListOpen: state.memberListOpen,
lastChannelPerServer: state.lastChannelPerServer,
}),
}
)