fix: channel deletion navigates to space root instead of @me
Add stale-channel guard in AppLayout that redirects to the space root
when the URL's channelId no longer exists in the channel list. Remove
the hardcoded navigate('/channels/@me') from ChannelSettingsModal and
the redundant setCurrentChannel fallback from the WS channel_deleted
handler — AppLayout's guard now handles all cases uniformly.
This commit is contained in:
@@ -240,6 +240,20 @@ export function AppLayout() {
|
||||
}
|
||||
}, [spaceId, channelId, channels, navigate]);
|
||||
|
||||
// Guard: redirect when URL channelId no longer exists (deleted, permission revoked, etc.)
|
||||
useEffect(() => {
|
||||
if (!spaceId || spaceId === '@me' || !channelId) return;
|
||||
if (channels.length === 0) return;
|
||||
|
||||
const { channelToSpaceMap } = useSpaceStore.getState();
|
||||
const firstCh = channels[0];
|
||||
if (!firstCh || channelToSpaceMap.get(firstCh.id) !== spaceId) return;
|
||||
|
||||
if (!channels.some(c => c.id === channelId)) {
|
||||
navigate(`/channels/${spaceId}`, { replace: true });
|
||||
}
|
||||
}, [spaceId, channelId, channels, navigate]);
|
||||
|
||||
if (isLoading || !user) {
|
||||
return (
|
||||
<div className="h-screen flex items-center justify-center bg-surface-chat">
|
||||
|
||||
Reference in New Issue
Block a user