Repository navigation
refactor(studio): move the last two hand-rolled disclosures to Collapsible - #2367
Conversation
…ible Before the last two hand-rolled disclosures move to the Collapsible primitive, pin what they do today, against roles, names and state, so the same tests hold on both implementations: - each suggested change's "Show current values" opens and closes on its own by click, Enter and Space, shows the kept and merged-in values, and keeps its closed values in the document; - in Chromium, window.find reaches a change's closed values, and a text-fragment navigation (the browser's find-in-page match) reveals the matched change and only that one; - a turn's tool-call toggle is one button named by its summary, opens and closes from the pointer and the keyboard, keeps the closed rows in the document but hidden, and keeps the tool names findable; - neither disclosure adds a heading or a region. Refs #2340 Refs #2201 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`CollapsibleContent hiddenUntilFound` keeps closed content in the document as `hidden="until-found"` instead of unmounting it, so the browser's find-in-page searches it, and opens the collapsible on the `beforematch` event the browser fires before revealing a match. This is what `<details>` gives for free. Radix offers no hook into its open state, so `Collapsible` now keeps the open state itself (uncontrolled through `defaultOpen`, or controlled through `open` and `onOpenChange`, exactly as before) and shares it with the content. Radix renders closed children only when the content is force-mounted, and React writes `hidden` as a boolean only, so the attribute and the listener go on the node directly. Refs #2340 Refs #2201 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each suggested change's "Show current values" `<details>` becomes a Collapsible, as kantord asked on #2334: one disclosure, so no Accordion heading or region per change. The closed values stay in the page, hidden until found, so find-in-page still reaches them and opens the change. The trigger draws the same disclosure triangle `<summary>` drew, from an empty inside list item, so the text, the marker and the spacing are unchanged. The card test named the `<details>` element; it now reads the content the trigger controls, with the same four assertions. Refs #2340 Refs #2201 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The hand-rolled `aria-expanded` toggle over a `hidden` list becomes a controlled Collapsible, with no heading per tool group. The closed list still stays in the page: it is now hidden until found rather than hidden, so find-in-page also reaches a call's arguments and result, not only the names in the toggle, and a match opens the list. The gap above the list applies only when open, since closed hidden-until-found content keeps its own box. Refs #2340 Refs #2201 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
kantord
left a comment
There was a problem hiding this comment.
Thanks for taking the Collapsible and hidden="until-found" route after #2334, and for the care in the wrapper: the three existing consumers (failed-turn-card, reasoning-disclosure, proposal-row) are unaffected, since open and onOpenChange are destructured so the later {...props} can't override them and asChild still flows through. I'm requesting changes for one thing in the shared primitive, plus a design question.
Requested change: the beforematch listener has no target check
The listener is attached to the content node and calls setOpen(true) (collapsible.tsx L86-L92). beforematch bubbles (the unit test dispatches it with bubbles: true, collapsible.test.tsx L74). If a closed hiddenUntilFound Collapsible ever sits inside an open one, a match in the inner one reaches the outer listener and calls the outer setOpen(true).
For the tool-call list that is worse than a no-op: it passes onOpenChange={toggleExpanded} (tool-call-list.tsx L186), and toggleExpanded flips state and ignores its argument (use-details-open.ts L25-L27). The bubbled event would close an already-open list, hiding the text the user just searched for. Nothing nests hiddenUntilFound content today, so this is latent, but it is a trap in a shared primitive.
Suggested change: if (event.target !== node) return; in the listener. A closely related fix is in setOpen itself (L21-L28): it calls onOpenChange even when the value doesn't change, which Radix's own state would not. An if (next === open) return; keeps toggle-style callers safe. A unit test for the nested case would pin it.
Question for the author (not a request)
The wrapper is about 60 lines, plus a CSS list-marker hack on the Memory trigger (consolidate-memory-card.tsx L408-L416), all to recover find-in-page that a native <details> already gave for free, and only in browsers that support hidden="until-found". Given the repo's "simplest thing that solves the problem" guidance, what does moving the Memory card off <details> buy beyond a uniform primitive? I'm asking, not asserting, because I don't think it's a defect, but I'd like the reasoning written down.
Smaller points, not blocking
- If a controlled owner ignores
setOpen(true), the browser has already removedhidden,openstays false, and the layout effect (L79-L84) never re-appliesuntil-found. The result is visible content witharia-expanded=false. Probably fine as a documented contract; worth a line in the JSDoc. - The Memory trigger hard-codes
text-left(L409), where<summary>aligned to the start.text-startwould keep RTL behaviour; I found no RTL support in the app, so this is minor. - The unit test only proves the wiring with a synthetic event. The real find-in-page coverage is Playwright, and the configured projects are Chromium only (playwright.config.ts), so Firefox and WebKit behaviour is untested. The
window.findplus#:~:text=approach may be flaky; I did not run it. - The PR body says
aria-controlsappears "when open"; I believe Radix emits it unconditionally, and with force-mount the id always resolves, so the code is fine and the sentence is just inaccurate. - The "pixel-identical" and "closed content is out of the accessibility tree" claims rest on the author's captures; I couldn't check them.
I read the code and CI only and didn't run the app or the tests.
Fully or partially written by an AI agent.
`beforematch` bubbles, so a find-in-page match inside a nested hidden-until-found Collapsible also reached the outer listener and asked the outer one to open. With a toggle-style `onOpenChange`, such as the tool-call list's, that closed an already open list. The listener now ignores events whose target is not its own content node, and `setOpen` no longer reports a request that changes nothing, as Radix's own state does. The JSDoc documents that a controlled owner must accept the `onOpenChange(true)` a match sends. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`<summary>` aligned to the start of the line; `text-start` keeps that for right-to-left text, where `text-left` would not. Left-to-right rendering is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
kantord
left a comment
There was a problem hiding this comment.
Thanks for the quick follow-up. I read the new commits against my requests and they are resolved:
beforematchnow ignores events from nested content (event.target !== node), andsetOpenonly reports real changes, so a toggle-styleonOpenChangecan't flip on a no-op.- The controlled-owner contract is now written in the JSDoc.
- The Memory trigger uses
text-start.
Approving. My one open question, what moving the Memory card off native <details> buys beyond a uniform primitive, is still unanswered, so a line in the PR description would be good, but it doesn't block. I read the diff and CI only and did not run the app or the tests.
Fully or partially written by an AI agent.
Summary
Moves the last two hand-rolled disclosures to the Collapsible primitive that #2352 added: the Memory card's "Show current values"
<details>, and a turn's tool-call toggle in the transcript. Neither gains a heading or a region (the reason kantord gave on #2334 for Collapsible over Accordion). Both keep their closed content findable with the browser's find-in-page. Every captured state is pixel-identical tomain.Part of #2340
Part of #2201
Part of #2210
What changed
components/ui/collapsible.tsx:CollapsibleContent hiddenUntilFound. Closed content stays in the document ashidden="until-found"instead of unmounting, and abeforematchevent (fired by the browser just before it reveals a find-in-page match) opens the collapsible. Three things in the stack made this need code rather than a prop:Collapsiblenow keeps the state itself (uncontrolled throughdefaultOpen, or controlled throughopenandonOpenChange, the same API as before) and shares it with the content.hiddenUntilFoundforcesforceMount.hiddenas a boolean (hidden=""for any truthy value), so the attribute and the listener are set on the node.Closed
until-foundcontent still lays out its own box (content-visibility: hidden), so margins and padding go on its children.memory/consolidate-memory-card.tsx. The<details>becomesCollapsible,CollapsibleTriggerandCollapsibleContent hiddenUntilFound. The trigger draws the same disclosure triangle<summary>drew, from an empty inside list item (list-style: disclosure-closed/disclosure-open), so the text, the marker and the spacing are unchanged.chat/tool-call-list.tsx. The button with hand-setaria-expandedover ahiddenlist becomes a controlledCollapsible, still driven byuseDetailsOpenand still held open while a call carries an ask or an authorization. The<ol>is the content (asChild) and is hidden until found. Its top margin applies only when open.Behaviour differences
main, the closed list washidden, so find-in-page reached only the tool names in the toggle. Now it also reaches each call's arguments and result, and a match opens the list. This is intended: it is what refactor(studio): use Label for the settings switch labels (#2201 group B) #2359 kept the hand-rolled list for.<button>, not a<summary>. It is reached and operated the same way (Tab, Enter, Space, pointer), and now reportsaria-expanded. It also reportsaria-controls, but only while open: Radix's trigger (@radix-ui/react-collapsible1.1.21) sets"aria-controls": context.open ? context.contentId : undefined, even though the force-mounted content keeps itsidwhile closed.aria-controlswhile open (Radix omits it while closed, as above), plus Radix'sdata-stateon the toggle and the list.hidden="until-found"content out of its accessibility tree, as it does a closed<details>(checked withAccessibility.getFullAXTree).No visible difference.
No regression
Pins first (
11a1d5468), passing on the old code and on the head:consolidate-memory-card.pinning.test.tsx(5), reusing the Memory pins from the earlier refactor(studio): use the Tabs and Toggle primitives in two hand-rolled controls #2334 branch: each change has its own closed disclosure; click opens and closes it with the kept and merged-in values; placeholders for an unnamed or empty memory; the closed values stay in the document; no heading or region, closed or open.tool-call-list.pinning.test.tsx(4): one button named by its summary; the closed rows stay in the document but hidden, with the names in the toggle; pointer, Enter and Space toggle it; no heading or region.e2e/memory-consolidation.spec.ts(3 × desktop and 390px): keyboard reach and toggling; find-in-page:window.findreaches three closed values, and a text-fragment navigation (#:~:text=, which runs the browser's own find-in-page match and firesbeforematch) reveals the matched change and only that one, after which one press of its trigger closes it; no heading or region.e2e/tool-call-list.spec.ts(3 × 2): keyboard toggling; the tool names stay findable withwindow.find; no heading or region.New behaviour, failing on the old code:
e2e/tool-call-list.spec.ts: "find-in-page reaches a closed list's arguments and opens the list". Against the hand-rolled list,window.findreturns false.collapsible.test.tsx(+2): closed content ishidden="until-found"and opens onbeforematch; a controlled owner is asked to open.Modified test, justified: one test in
consolidate-memory-card.test.tsxfound the content throughclosest("details"). It now finds it through the trigger'saria-controls, after checkingaria-expanded, with the same four content assertions. No assertion was removed or weakened.transcript-alignment.test.tsxpasses unmodified.Mutation proof, each mutation applied alone:
hiddenUntilFound(Radix unmounts it)hiddenUntilFoundbeforematchlistenerhiddeninstead ofuntil-foundwindow.findfalse)onOpenChangePixels: 20 states (Memory closed, open and focused; tool calls closed, open and focused, at desktop and 390px, light and dark), each captured twice per tree. All 20 are identical to
main, or differ only inside the noise floor of a secondmaincapture (6 px of the top bar on a phone, 13 px of focus-ring corner antialiasing). Box geometry matches too.pixel-report.txthas the counts.Screenshots
Before is
origin/main(8cc7c2347), After is this branch (8b2328ce3), and Prototype isstack-08. Red boxes would mark Before/After differences; there are none.Memory, two suggested changes, values closed (identical to Before; matches the prototype's Consolidate memory card styling; the prototype has no suggestion fixture, so its column is the Memory page)
Memory, two suggested changes, values closed: desktop dark and 390px, light and dark
memory-closed-desktop-dark:
memory-closed-mobile-light:
memory-closed-mobile-dark:
Memory, first change's current values open (identical to Before; prototype column as above)
Memory, first change's current values open: desktop dark and 390px, light and dark
memory-open-desktop-dark:
memory-open-mobile-light:
memory-open-mobile-dark:
Memory, keyboard focus on Show current values (desktop) (identical to Before; same focus ring as
<summary>)Memory, keyboard focus on Show current values (desktop): desktop dark
memory-focus-desktop-dark:
Transcript, tool-call group closed (identical to Before; matches the prototype's closed Activity row)
Transcript, tool-call group closed: desktop dark and 390px, light and dark
tools-closed-desktop-dark:
tools-closed-mobile-light:
tools-closed-mobile-dark:
Transcript, tool-call group open (identical to Before; matches the prototype's open Activity rows)
Transcript, tool-call group open: desktop dark and 390px, light and dark
tools-open-desktop-dark:
tools-open-mobile-light:
tools-open-mobile-dark:
Transcript, keyboard focus on the Activity toggle (desktop) (identical to Before; prototype column is the closed transcript)
Transcript, keyboard focus on the Activity toggle (desktop): desktop dark
tools-focus-desktop-dark:
Gates
On the head rebased onto
main(43c1a02c8;mainhas since gained only #2357, in an unrelated learning file):task studio:check: passed. Web 1624 tests in 190 files, server 252 tests in 27 files.task studio:browser: passed. 150 passed, 38 skipped.Before the rebase, on #2352's head, the same gates passed with web 1514 in 177 files (#2352 reported 1503 in 175; +11 here) and browser 138 passed (124 on #2352; +14 here).
Review changes
Addresses kantord's review of
8b2328ce3. Two commits on top, no rebase:7966befd0fix(studio): open a Collapsible only for a match in its own content. Incomponents/ui/collapsible.tsx:beforematchlistener returns unlessevent.targetis its own content node.beforematchbubbles, so a match inside a nested hidden-until-found Collapsible used to ask the outer one to open too, and a toggle-style owner such as the tool-call list (onOpenChange={toggleExpanded}) would close an already open list.setOpenreturns when the requested value equals the current one, soonOpenChangeis never called for a no-op, as with Radix's own state.CollapsibleContentJSDoc states the controlled-owner contract: an owner must accept theonOpenChange(true)a match sends, because the browser has already removedhidden; an owner that keepsopenfalse leaves the content visible witharia-expanded="false".51e66b09cfix(studio): align the Memory change trigger to the start.text-leftbecomestext-start, as<summary>aligned. Left-to-right rendering is unchanged (0 changed pixels below).aria-controlssentences now say what Radix 1.1.21 emits: the trigger setsaria-controlsonly while open. The earlier "when open" wording was accurate; it now cites the source.No consumer changes behaviour: failed-turn-card, reasoning-disclosure and proposal-row call neither path with a no-op value, and the tool-call list's trigger always requests the opposite of its current
open(also when an ask holds it open), so the guard never drops a real toggle.Tests
collapsible.test.tsx+4 (8 in total):onOpenChangestays open, and its callback isn't called, when a match opens a nested one;onOpenChangeisn't called when a match asks an already open Collapsible to open;aria-controlswhile closed and names the content once open.The first and third failed on
8b2328ce3before the fix. Mutation proof, each applied alone:event.target !== nodechecknext === openguardsetOpen)aria-controlsThe open-outer test passes with either guard alone, since each one stops the stray toggle; the two single-guard tests pin each fix separately.
Screenshots
Before is
8b2328ce3(the reviewed head) and After is51e66b09c. The fixes change behaviour only, and every state is identical: amber boxes mark the reviewed disclosure triggers, and there are no red boxes. The 20 states are the same as above (Memory closed, open and focused; tool calls closed, open and focused; desktop and 390px; light and dark).pixel-report.txthas the counts: 17 states have 0 changed pixels, and 3 dark-theme tool-call states differ by 6 or 13 px, the noise floor recorded on the original captures. The nested case can't be shown in the app, because nothing nests hidden-until-found content today. The unit tests above cover it, and the existing find-in-page e2e (memory-consolidation.spec.ts,tool-call-list.spec.ts) still passes.Memory, values open (identical; amber marks the reviewed trigger)
Memory, values open: desktop dark and 390px, light and dark
memory-open-desktop-dark:
memory-open-mobile-light:
memory-open-mobile-dark:
Memory, values closed (identical; amber marks the reviewed trigger)
Memory, values closed: desktop dark and 390px, light and dark
memory-closed-desktop-dark:
memory-closed-mobile-light:
memory-closed-mobile-dark:
Memory, keyboard focus on Show current values (identical; amber marks the reviewed trigger)
Memory, keyboard focus on Show current values: desktop dark
memory-focus-desktop-dark:
Transcript, tool-call group closed (identical; amber marks the reviewed trigger)
Transcript, tool-call group closed: desktop dark and 390px, light and dark
tools-closed-desktop-dark:
tools-closed-mobile-light:
tools-closed-mobile-dark:
Transcript, tool-call group open (identical; amber marks the reviewed trigger)
Transcript, tool-call group open: desktop dark and 390px, light and dark
tools-open-desktop-dark:
tools-open-mobile-light:
tools-open-mobile-dark:
Transcript, keyboard focus on the Activity toggle (identical; amber marks the reviewed trigger)
Transcript, keyboard focus on the Activity toggle: desktop dark
tools-focus-desktop-dark:
Gates
On
51e66b09c:task studio:check: passed. Web 1628 tests in 190 files, server 252 tests in 27 files.task studio:browser: passed. 150 passed, 38 skipped.🤖 Generated with Claude Code