refactor(btw): read the promoted flag from the panel state, not a second subscription
`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.
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
|||||||
import type { AttachedFile } from '@/stores/types/sessionTypes';
|
import type { AttachedFile } from '@/stores/types/sessionTypes';
|
||||||
import * as sessionActions from '@/sync/session-actions';
|
import * as sessionActions from '@/sync/session-actions';
|
||||||
import { buildLinkedIssue } from '@/lib/linkedIssues';
|
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 { getInlineCommentDraftKey, useInlineCommentDraftStore, type InlineCommentDraft, type InlineCommentDraftTarget } from '@/stores/useInlineCommentDraftStore';
|
||||||
import { useSnippetsStore } from '@/stores/useSnippetsStore';
|
import { useSnippetsStore } from '@/stores/useSnippetsStore';
|
||||||
import { renderMagicPrompt } from '@/lib/magicPrompts';
|
import { renderMagicPrompt } from '@/lib/magicPrompts';
|
||||||
@@ -342,11 +342,7 @@ const ChatInputComponent: React.FC<ChatInputProps> = ({
|
|||||||
// A session promoted out of `/btw` keeps the boundary instructions in its
|
// 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
|
// transcript — there is no way to delete a message part — so it has to say
|
||||||
// they no longer apply.
|
// they no longer apply.
|
||||||
const currentSessionRecord = useSession(
|
const isPromotedBtwSession = wasPromotedBtwSession(btwPanel.parentSession);
|
||||||
currentSessionId,
|
|
||||||
currentSessionDirectoryForSync ?? currentDirectory ?? undefined,
|
|
||||||
);
|
|
||||||
const isPromotedBtwSession = wasPromotedBtwSession(currentSessionRecord);
|
|
||||||
const activeRuntimeKey = getRuntimeKey();
|
const activeRuntimeKey = getRuntimeKey();
|
||||||
const chatDraftIdentity = React.useMemo(
|
const chatDraftIdentity = React.useMemo(
|
||||||
() => createChatDraftIdentity(
|
() => createChatDraftIdentity(
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { getBtwBoundaryMessageID, getBtwSessionID } from '@/lib/sessionBtwMetada
|
|||||||
import { useBtwStore } from '@/stores/useBtwStore';
|
import { useBtwStore } from '@/stores/useBtwStore';
|
||||||
|
|
||||||
export type BtwPanelState = {
|
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. */
|
/** The active fork for this parent, or null when no panel should exist. */
|
||||||
btwSessionId: string | null;
|
btwSessionId: string | null;
|
||||||
btwSession: Session | null;
|
btwSession: Session | null;
|
||||||
@@ -40,6 +42,7 @@ export function useBtwPanelState(
|
|||||||
const destroying = Boolean(uiState?.destroying);
|
const destroying = Boolean(uiState?.destroying);
|
||||||
const btwSessionId = btwSession && !destroying ? linkedBtwSessionId : null;
|
const btwSessionId = btwSession && !destroying ? linkedBtwSessionId : null;
|
||||||
return {
|
return {
|
||||||
|
parentSession: parentSession ?? null,
|
||||||
btwSessionId,
|
btwSessionId,
|
||||||
btwSession: btwSessionId ? btwSession : null,
|
btwSession: btwSessionId ? btwSession : null,
|
||||||
// SAFETY: the SDK Session type omits the server's `directory` field; this
|
// SAFETY: the SDK Session type omits the server's `directory` field; this
|
||||||
|
|||||||
Reference in New Issue
Block a user