fix(skills): clear the auto-read guard when the selection leaves the list
`autoReadKey` cached the manifest key of the entry it had read for. When the selected entry left `skills` — a refresh in flight, a disconnect — the render emptied the preview but the ref kept the key. An identical entry reappearing therefore matched the cache, the automatic read was skipped, and the viewer stayed blank with no recovery short of reselecting. Clearing the guard while no entry is selected is what lets the reappearance re-read. Also corrects the guard's stated scope. It cannot survive a `ScreenStage` remount — a remount mints a fresh ref — so the round-11 comment claiming it did was wrong. That read is correct behavior rather than a gap: `previewState` is local state and dies with the same unmount, so on return the viewer is empty and the read is what refills it. Suppressing it would mean hoisting the preview bytes above `ScreenStage` and showing bytes fetched under a connection that may no longer exist. The reappearance test is a real regression guard: restoring the defect fails it while the older one-read-per-selection test still passes, so it is both detecting and non-redundant. That older test remains a specification, for the reason it already states, and now points at this one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4441JdNLZerCVM7mDDSfB Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
ede9658d62
commit
25255c3499
1 changed files with 86 additions and 27 deletions
|
|
@ -908,19 +908,33 @@ export function SkillsScreen({
|
|||
|
||||
// Which manifest the automatic read has already been issued for.
|
||||
//
|
||||
// A ref rather than state, because this must not itself cause a render — and
|
||||
// it is what stops the read being issued twice for one selection. React
|
||||
// StrictMode deliberately replays effects (`main.tsx` renders under it), and
|
||||
// `ScreenStage` remounts this screen while the selected-skill UI state
|
||||
// persists, so without a guard both paths fire a second identical
|
||||
// `resources/read`. In an app whose whole purpose is showing people the
|
||||
// protocol traffic, an extra request in the Protocol panel that the user's
|
||||
// own client would never send is worse than a wasted round trip: it is the
|
||||
// Inspector misreporting the conversation.
|
||||
// A ref rather than state, because this must not itself cause a render. Its
|
||||
// scope is ONE MOUNT, and that is the whole of what it can promise: React
|
||||
// StrictMode deliberately replays effects (`main.tsx` renders under it), so
|
||||
// without a guard a single selection fires two identical `resources/read`
|
||||
// calls. In an app whose whole purpose is showing people the protocol
|
||||
// traffic, an extra request in the Protocol panel that the user's own client
|
||||
// would never send is worse than a wasted round trip — it is the Inspector
|
||||
// misreporting the conversation.
|
||||
//
|
||||
// It deliberately does NOT suppress the read after a `ScreenStage` remount,
|
||||
// and could not: a remount mints a fresh ref. That is the correct behavior
|
||||
// rather than a gap, because `previewState` is local state too and dies with
|
||||
// the same unmount — so on return the viewer is empty and the read is what
|
||||
// refills it. Suppressing it would need the preview bytes hoisted above
|
||||
// `ScreenStage`, which would trade a legitimate request for a cache.
|
||||
const autoReadKey = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedUri === undefined) return;
|
||||
if (selectedUri === undefined) {
|
||||
// The entry left `skills` — a refresh in flight, or a disconnect.
|
||||
// `useValueChange` has already emptied the viewer, so if the IDENTICAL
|
||||
// entry reappears its `manifestKey` matches what this ref still holds
|
||||
// and the read would be skipped, stranding the viewer permanently
|
||||
// blank. Clearing the guard is what lets that reappearance re-read.
|
||||
autoReadKey.current = null;
|
||||
return;
|
||||
}
|
||||
if (autoReadKey.current === manifestKey) return;
|
||||
autoReadKey.current = manifestKey;
|
||||
showResource(selectedUri, manifestKey);
|
||||
|
|
|
|||
Loading…
Reference in a new issue