From 0389af6cb385a8246ff8c8bed324c6cdc60677b4 Mon Sep 17 00:00:00 2001 From: dibanez Date: Thu, 27 Aug 2026 14:04:12 +0200 Subject: [PATCH] refactor(btw): read the promoted flag from the panel state, not a second subscription MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `useBtwPanelState` already subscribes to the composer's own session — it is what the fork link is derived from — so asking `useSession` for the same session and directory a second time in `ChatInput` was a duplicate subscription for a value already in hand. Expose it as `parentSession` and read the promoted flag from there. No behavior change. --- packages/ui/src/components/chat/ChatInput.tsx | 8 ++------ packages/ui/src/components/chat/btw/useBtwPanelState.ts | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/chat/ChatInput.tsx b/packages/ui/src/components/chat/ChatInput.tsx index a3de3395..65634b05 100644 --- a/packages/ui/src/components/chat/ChatInput.tsx +++ b/packages/ui/src/components/chat/ChatInput.tsx @@ -18,7 +18,7 @@ import { import type { AttachedFile } from '@/stores/types/sessionTypes'; import * as sessionActions from '@/sync/session-actions'; import { buildLinkedIssue } from '@/lib/linkedIssues'; -import { useSession, useUserMessageHistory } from "@/sync/sync-context"; +import { useUserMessageHistory } from "@/sync/sync-context"; import { getInlineCommentDraftKey, useInlineCommentDraftStore, type InlineCommentDraft, type InlineCommentDraftTarget } from '@/stores/useInlineCommentDraftStore'; import { useSnippetsStore } from '@/stores/useSnippetsStore'; import { renderMagicPrompt } from '@/lib/magicPrompts'; @@ -342,11 +342,7 @@ const ChatInputComponent: React.FC = ({ // A session promoted out of `/btw` keeps the boundary instructions in its // transcript — there is no way to delete a message part — so it has to say // they no longer apply. - const currentSessionRecord = useSession( - currentSessionId, - currentSessionDirectoryForSync ?? currentDirectory ?? undefined, - ); - const isPromotedBtwSession = wasPromotedBtwSession(currentSessionRecord); + const isPromotedBtwSession = wasPromotedBtwSession(btwPanel.parentSession); const activeRuntimeKey = getRuntimeKey(); const chatDraftIdentity = React.useMemo( () => createChatDraftIdentity( diff --git a/packages/ui/src/components/chat/btw/useBtwPanelState.ts b/packages/ui/src/components/chat/btw/useBtwPanelState.ts index 6d36f060..9807e70e 100644 --- a/packages/ui/src/components/chat/btw/useBtwPanelState.ts +++ b/packages/ui/src/components/chat/btw/useBtwPanelState.ts @@ -5,6 +5,8 @@ import { getBtwBoundaryMessageID, getBtwSessionID } from '@/lib/sessionBtwMetada import { useBtwStore } from '@/stores/useBtwStore'; export type BtwPanelState = { + /** The session the composer is in — the one `/btw` would fork. */ + parentSession: Session | null; /** The active fork for this parent, or null when no panel should exist. */ btwSessionId: string | null; btwSession: Session | null; @@ -40,6 +42,7 @@ export function useBtwPanelState( const destroying = Boolean(uiState?.destroying); const btwSessionId = btwSession && !destroying ? linkedBtwSessionId : null; return { + parentSession: parentSession ?? null, btwSessionId, btwSession: btwSessionId ? btwSession : null, // SAFETY: the SDK Session type omits the server's `directory` field; this