Compare commits

...
1 Commits
Author SHA1 Message Date
Miguel PalhasandClaude Opus 4.6 c2d427691d fix(web): stop tool-group flashing and config-menu closure on updates
Reuse existing tool-group DOM elements in rebuildTranscript instead of
tearing them down — preserves CSS transition state and focus. Defer
config-menu DOM rebuild while the menu is open so <select> dropdowns
survive background state updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-09-08 14:26:14 +01:00
+43 -16
View File
@@ -486,6 +486,7 @@ export function createStructuredConnection(
const liveGroupIds = new Set([...groups.keys()]); const liveGroupIds = new Set([...groups.keys()]);
for (const id of expandedGroupIds) if (!liveGroupIds.has(id)) expandedGroupIds.delete(id); for (const id of expandedGroupIds) if (!liveGroupIds.has(id)) expandedGroupIds.delete(id);
const prevGroupEls = new Map(groupEls);
rowEls.clear(); rowEls.clear();
groupEls.clear(); groupEls.clear();
const children: HTMLElement[] = []; const children: HTMLElement[] = [];
@@ -504,23 +505,37 @@ export function createStructuredConnection(
rowEls.set(memberRow.id, memberEl); rowEls.set(memberRow.id, memberEl);
return [memberEl]; return [memberEl];
}); });
const groupEl = buildToolGroup(
groupId, // Reuse existing group element when possible — avoids tearing down
group.rows, // and recreating the wrapper, which restarts CSS transitions (visible
memberEls, // flash) and destroys keyboard/focus state.
expandedGroupIds.has(groupId), const existing = prevGroupEls.get(groupId);
(expanded) => { if (existing) {
if (expanded) expandedGroupIds.add(groupId); const titleEl = existing.querySelector<HTMLElement>(".st-tool-group-title");
else expandedGroupIds.delete(groupId); if (titleEl) titleEl.textContent = `${group.toolCount} tool calls`;
settleDisclosureLayout(); const inner = existing.querySelector<HTMLElement>(".st-disclosure-inner");
}, if (inner) inner.replaceChildren(...memberEls);
group.toolCount, groupEls.set(groupId, existing);
); children.push(existing);
if (group.rows.some((r) => enteringRowIds.has(r.id))) { } else {
groupEl.classList.add("st-row-enter"); const groupEl = buildToolGroup(
groupId,
group.rows,
memberEls,
expandedGroupIds.has(groupId),
(expanded) => {
if (expanded) expandedGroupIds.add(groupId);
else expandedGroupIds.delete(groupId);
settleDisclosureLayout();
},
group.toolCount,
);
if (group.rows.some((r) => enteringRowIds.has(r.id))) {
groupEl.classList.add("st-row-enter");
}
groupEls.set(groupId, groupEl);
children.push(groupEl);
} }
groupEls.set(groupId, groupEl);
children.push(groupEl);
continue; continue;
} }
// Resolved approvals not absorbed into a tool group are hidden — the // Resolved approvals not absorbed into a tool group are hidden — the
@@ -635,12 +650,14 @@ export function createStructuredConnection(
} }
} }
let configDirty = false;
function renderConfig(): void { function renderConfig(): void {
const options = sessionConfigOptions(); const options = sessionConfigOptions();
configEl.hidden = options.length === 0; configEl.hidden = options.length === 0;
if (options.length === 0) { if (options.length === 0) {
configMenu.hidden = true; configMenu.hidden = true;
configTrigger.setAttribute("aria-expanded", "false"); configTrigger.setAttribute("aria-expanded", "false");
configDirty = false;
return; return;
} }
const ordered = [...options].sort((a, b) => { const ordered = [...options].sort((a, b) => {
@@ -654,6 +671,15 @@ export function createStructuredConnection(
configTrigger.title = summary; configTrigger.title = summary;
configTrigger.setAttribute("aria-label", `Session settings. ${summary.replaceAll("\n", ". ")}`); configTrigger.setAttribute("aria-label", `Session settings. ${summary.replaceAll("\n", ". ")}`);
configTrigger.disabled = configBusy; configTrigger.disabled = configBusy;
// When the menu is open and the user is interacting (not mid-change),
// skip the DOM rebuild so open <select> dropdowns aren't destroyed.
// Mark dirty so the next open rebuilds with fresh data.
if (!configMenu.hidden && !configBusy) {
configDirty = true;
return;
}
configDirty = false;
configMenu.replaceChildren(); configMenu.replaceChildren();
for (const option of ordered) { for (const option of ordered) {
const row = document.createElement("label"); const row = document.createElement("label");
@@ -785,6 +811,7 @@ export function createStructuredConnection(
configTrigger.addEventListener("click", () => { configTrigger.addEventListener("click", () => {
const opening = configMenu.hidden; const opening = configMenu.hidden;
if (opening && configDirty) renderConfig();
configMenu.hidden = !opening; configMenu.hidden = !opening;
configTrigger.setAttribute("aria-expanded", String(opening)); configTrigger.setAttribute("aria-expanded", String(opening));
}); });