mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-27 23:05:30 +08:00
fix(chat): preserve rehydrated permission prompts
Session navigation restores pending approvals through chat.subscribe. Provider synchronization could clear that restored state afterward. This made banner visibility depend on response timing. Keep cleanup session-scoped and match acknowledgments against the current view.
This commit is contained in:
@@ -114,7 +114,6 @@ export function useChatProviderState({ selectedSession, selectedProject }: UseCh
|
|||||||
const [providerModelsLoading, setProviderModelsLoading] = useState(true);
|
const [providerModelsLoading, setProviderModelsLoading] = useState(true);
|
||||||
const [providerModelsRefreshing, setProviderModelsRefreshing] = useState(false);
|
const [providerModelsRefreshing, setProviderModelsRefreshing] = useState(false);
|
||||||
|
|
||||||
const lastProviderRef = useRef(provider);
|
|
||||||
const providerModelsRequestIdRef = useRef(0);
|
const providerModelsRequestIdRef = useRef(0);
|
||||||
|
|
||||||
const setStoredProviderModel = useCallback((targetProvider: LLMProvider, model: string) => {
|
const setStoredProviderModel = useCallback((targetProvider: LLMProvider, model: string) => {
|
||||||
@@ -344,14 +343,8 @@ export function useChatProviderState({ selectedSession, selectedProject }: UseCh
|
|||||||
localStorage.setItem('selected-provider', selectedSession.__provider);
|
localStorage.setItem('selected-provider', selectedSession.__provider);
|
||||||
}, [provider, selectedSession]);
|
}, [provider, selectedSession]);
|
||||||
|
|
||||||
useEffect(() => {
|
// Permission prompts belong to a session, not to the transient provider
|
||||||
if (lastProviderRef.current === provider) {
|
// selection that is synchronized after navigation.
|
||||||
return;
|
|
||||||
}
|
|
||||||
setPendingPermissionRequests([]);
|
|
||||||
lastProviderRef.current = provider;
|
|
||||||
}, [provider]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPendingPermissionRequests((previous) =>
|
setPendingPermissionRequests((previous) =>
|
||||||
previous.filter((request) => !request.sessionId || request.sessionId === selectedSession?.id),
|
previous.filter((request) => !request.sessionId || request.sessionId === selectedSession?.id),
|
||||||
|
|||||||
@@ -72,6 +72,13 @@ export function useChatRealtimeHandlers({
|
|||||||
onWebSocketReconnect,
|
onWebSocketReconnect,
|
||||||
sessionStore,
|
sessionStore,
|
||||||
}: UseChatRealtimeHandlersArgs) {
|
}: UseChatRealtimeHandlersArgs) {
|
||||||
|
// Session switches can send `chat.subscribe` before this effect has a chance
|
||||||
|
// to rebind the websocket listener. Read the visible session id from a ref
|
||||||
|
// so a fast `chat_subscribed` ack is matched against the current view, not
|
||||||
|
// the previous render's closed-over selection.
|
||||||
|
const activeViewSessionIdRef = useRef<string | null>(selectedSession?.id || currentSessionId || null);
|
||||||
|
activeViewSessionIdRef.current = selectedSession?.id || currentSessionId || null;
|
||||||
|
|
||||||
// Keep the latest pending-permission snapshot available to the websocket
|
// Keep the latest pending-permission snapshot available to the websocket
|
||||||
// listener so back-to-back permission events can dedupe and re-arm the
|
// listener so back-to-back permission events can dedupe and re-arm the
|
||||||
// notification sound before React finishes a rerender.
|
// notification sound before React finishes a rerender.
|
||||||
@@ -87,7 +94,7 @@ export function useChatRealtimeHandlers({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeViewSessionId = selectedSession?.id || currentSessionId || null;
|
const activeViewSessionId = activeViewSessionIdRef.current;
|
||||||
const sid = (typeof msg.sessionId === 'string' && msg.sessionId) || activeViewSessionId;
|
const sid = (typeof msg.sessionId === 'string' && msg.sessionId) || activeViewSessionId;
|
||||||
|
|
||||||
// Record replay progress for every sequenced live event.
|
// Record replay progress for every sequenced live event.
|
||||||
|
|||||||
Reference in New Issue
Block a user