fix(pilot): wipe full task-lane state on chat switch + extract palette event
All checks were successful
Mirror to GitHub / mirror (push) Successful in 10s

Two fixes from the Phase 5 shakedown:

1. Stale lane data leaking across chats. handleNewChat, sendPrefill, and
   handleResumeNew were each missed when Phase 3/5 added activeFix,
   previewKind, previewData, and scriptPanelOpen — only selectChat reset
   the full set. Result: starting a new chat while a Suggested Fix card
   was active showed the previous session's fix card (and any open
   preview/script panel) until the next backend refresh swept it.
   Consolidated all four entry points behind a single
   resetSessionDerivedState() helper so adding new lane state in future
   phases only requires touching one place.

2. CommandPalette TDZ on cold load. SCRIPTS_INLINE_QUICK_ACTION (line 66)
   referenced PILOT_INLINE_SCRIPT_PATH declared at line 94 — module-level
   evaluation hit the use before the declaration. Browser blanked with
   "Cannot access 'PILOT_INLINE_SCRIPT_PATH' before initialization".
   Moved the path const above its first use; also extracted
   PILOT_INLINE_SCRIPT_EVENT into a tiny @/lib/pilotEvents module so
   AssistantChatPage doesn't import the palette component just to read a
   string — that mixed-export pattern broke Fast Refresh ("consistent
   components exports") and added an unnecessary import edge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-22 01:30:18 -04:00
parent fa61376303
commit ce7c8ac3d5
3 changed files with 45 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
import { useState, useEffect, useRef, useCallback, useMemo } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { PILOT_INLINE_SCRIPT_EVENT } from '@/lib/pilotEvents'
import {
Search, Loader2, ArrowRight, FileText, Clock,
Sparkles, LayoutDashboard, Tag, Plus, BookOpen, Terminal, Zap,
@@ -61,7 +62,11 @@ const QUICK_ACTIONS: PaletteItem[] = [
]
// Phase 5: only surfaced when on a /pilot/:id route. Fires the inline-script
// open event instead of navigating away to /scripts.
// open event instead of navigating away to /scripts. The path is a sentinel
// — handleSelect intercepts it and dispatches a window event rather than
// navigating, so the chat page can toggle its inline panel without coupling
// the global palette to chat-page state.
const PILOT_INLINE_SCRIPT_PATH = '__pilot_inline_script__'
const SCRIPTS_INLINE_QUICK_ACTION: PaletteItem = {
id: 'action-scripts-inline',
group: 'quick-actions',
@@ -86,12 +91,6 @@ function ItemIcon({ icon, className }: { icon: PaletteItem['icon'], className?:
}
}
// Phase 5: sentinel path the palette uses to fire the inline-script-generator
// open event instead of navigating. Listened for by AssistantChatPage when
// the user is in an active session.
export const PILOT_INLINE_SCRIPT_EVENT = 'flowpilot:open-inline-script'
const PILOT_INLINE_SCRIPT_PATH = '__pilot_inline_script__'
export function CommandPalette({ open, onClose }: CommandPaletteProps) {
const navigate = useNavigate()
const location = useLocation()