Repository navigation
feat(artifacts): type-first selection composer, retire CommentPopover - #12998
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify on touch: markdown/text artifact bodies lose their visible Copy control, and the composer's focus collapses the selection the OS copy callout needs. [DESIGN-REVIEWED] 9fb8479 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS No RFC covers replacing the pill→popover flow; the "No RFC" rationale rests on #9823's investigation — a maintainer should confirm that issue settles this shape. The core deletion is sound on the lane's own terms: base carried two spellings of "comment on a selection" ( What this change shipsInventory (10 items) — 10 justifiedIntent: selecting text on any artifact surface opens the comment box immediately and a typed comment is never lost — a FIX (extra-click flow and silent draft loss), executed by consolidating onto the existing composer.
[FIRST-PRINCIPLES-REVIEWED] 9fb8479 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
UX Review (Fable 5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS Failure banner never says the typed text is kept — the blind reader couldn't tell "pick it up" from having to retype. Watch
[UX-REVIEWED] 9fb8479 |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
c11e865 to
465bd4d
Compare
465bd4d to
5aa2194
Compare
5aa2194 to
c754e2f
Compare
c754e2f to
175e280
Compare
|
span=e8bc62bbfe9d
|
|
span=25ddbd9785f7
|
|
span=856a5cdfb1ee
|
|
span=6ea12d23d5ac
|
|
span=5533a6f699ce
|
|
span=da468325cce0
|
|
span=23dbf0c7f905 Disposition: fixed (next head)
|
|
span=6504b7c8bc2e Disposition: fixed (next head)
|
|
span=82eb7d6ad555 Disposition: fixed (next head)
|
|
span=6f14dd78a6e0 Disposition: out of scope (pre-existing)
|
|
span=97663f1f6241 Disposition: fixed (next head)
|
|
span=12d43a663671 Disposition: fixed (next head)
|
|
span=f1b27074cbbb Disposition: fixed (next head)
|
|
span=f591af13b310 Disposition: rebutted
|
|
span=23dbf0c7f905 Disposition: fixed (next head)
|
|
span=6504b7c8bc2e Disposition: fixed (next head)
|
|
span=5240292db20e Disposition: rebutted (pre-existing pairing, out of scope)
|
|
span=d8bebcb8af6e Disposition: rebutted
|
|
span=db475ac19fc7 Disposition: rebutted
|
|
span=3989cb6a88ed Disposition: rebutted (same premise as the Item 3 finding)
|
|
span=8d9b0c379089 Disposition: acknowledged (lane marks it justified; no action)
|
|
span=5a080fd9536f Disposition: acknowledged (lane marks it justified; no action)
|
|
span=e105b157b92d Disposition: acknowledged (lane marks it justified; no action)
|
|
span=8d93d8b49013 Disposition: acknowledged (lane marks it justified; no action)
|
|
span=dd06202547a0 Disposition: acknowledged (lane marks it justified; no action)
|
|
span=25d4c5918480 Disposition: acknowledged (lane marks it justified; no action)
|
|
span=810442e40285 Disposition: acknowledged (lane marks it justified; no action)
|
|
span=6a48d23ad593 Disposition: acknowledged (lane marks it justified; no action)
|
…ire CommentPopover Selecting text on an artifact — the full artifact page, the remote artifact page and the chat side panel — now opens the same type-first comment box the file viewer got in #9812 (`SelectionToolbar`'s `composer`), instead of a selection pill with a Comment button that opened a titled popover. - `useFileArtifactComments` exposes `selectionComposer` (+ `iframeSelection`) in place of `requestAnchoredComment`: the anchor is resolved from the live range in `onOpen`, the anchored post fires from `onSubmit`. - `ArtifactDetailPage` / `RemoteArtifactDetailPage` follow the same shape; the bare mouseup probes on the prose wrappers go away. - Iframe (widget/html) bodies keep working: the bridge's selection reaches the toolbar as `externalSelection`, which now opens the composer too (SelectionToolbar). - `CommentPopover` is deleted from `CommentOverlay.tsx` with its capture entry, tests and the orphaned `components.commentOverlay.add_a_comment` key (13 catalogs). Closes #9823
Problem / Motivation
Goal: Selecting text on any artifact surface opens the comment box straight away, and a typed comment is never lost.
Selecting text on an artifact page, the remote artifact page or the chat side panel's artifact view produced a selection pill whose Comment button opened a second, titled card (
CommentPopover) to type into — an extra click and a pointer round-trip per annotation — while the file viewer (since #9812) opens a type-first comment box straight from the selection. Two comment inputs for one feature, already drifting: the IME guard, the keyboard contract, the selection restore and the draft handling existed only in the composer, and a typed comment on an artifact host could be dropped silently by anything that unmounted the card.Why it matters
Both the Design and UX lanes on #9812 flagged the divergence: the same feature in two dresses, with the two comment inputs already drifting apart (IME guard, keyboard contract, selection restore, draft handling exist only in the composer). The original harm from #9760 — an extra click and a pointer round-trip per annotation — applied equally to the artifact pages. The issue's investigation comment settles the shape:
SelectionComposer.onOpen(text)fires before focus moves into the input, which is the host's one chance to resolve the anchor from the live range, andonSubmit(comment, text)carries the typed comment. No product decision remains.Not a goal
SelectionToolbarand store (declared riders): the raw-copy contract, the column clamp, the empty-box re-target draft restore, the tombstoned / text-held draft store, and the "Saving…" in-flight label — plus the sharedanchorFromRangeandannotationHighlightextractions (unchanged behaviour).What changed (motivation → approach → change)
Goal → approach. Selecting text on an artifact now opens the type-first comment box straight away — the same
SelectionToolbarcomposer the file viewer got in #9812 — on all four artifact hosts: the full artifact page (ArtifactDetailPage, markdown/text body and widget/html iframe body), the remote artifact page (RemoteArtifactDetailPage, markdown body and html iframe body), and the chat side panel (ArtifactPanel, both the docked and the full-screen mount). The two-stage flow — a selection pill with a Comment button that opened the titledCommentPopovercard — is gone, andCommentPopoveris deleted fromCommentOverlay.tsxtogether with its capture entry, its unit/integration tests and the one i18n key only it used (components.commentOverlay.add_a_comment, removed from all 12 catalogs + en-XA).Change, by piece:
useFileArtifactComments(website/src/components/FileArtifactComments.tsx):requestAnchoredComment()is split. The Range→{quote, prefix, suffix, startOffset, endOffset}derivation becomesresolveSelectionAnchor(), called from the composer'sonOpenand stored in a ref (never rendered);onSubmitfeedspostMutfrom that ref. The hook returnsselectionComposerandiframeSelectionin place ofrequestAnchoredComment.onIframeSelectstores the bridge's anchor and hands the toolbar aniframeSelection;onOpenkeeps that anchor when there is no live DOM range for the same text (so the frame's prefix/suffix are not replaced by the bare quote). Offsets from the frame are dropped as before — they are in the iframe body's text space, not the parent highlighter's.ArtifactPanel: bothSelectionToolbarmounts passcomposer={layer.selectionComposer}andexternalSelection={layer.iframeSelection}; theid: 'comment'andid: 'copy'actions are gone — the composer row is Add comment + Close (themax-two-buttons-per-rowrule caps the row at two controls), and copying the selection is the composer's Cmd/Ctrl+C while its input is empty. The native mounts listen on the preview ref itself (not the scroll box) so the box opens only over text the anchor resolver can map; for an iframe body the toolbar isexternalOnlyand opens from the bridge'siframeSelectionalone. It issuspendedwith the tab so a hidden panel's open box does not stay on screen (same contract asMarkdownPanel).The annotated passage stays visible (from review): focusing the composer collapses the real selection, so on open every native host paints the passage through the CSS Custom Highlight API (
::highlight(mc-annotate), the same paint the file viewer uses) and clears it on close/submit. That painter is extracted fromMarkdownPanelintowebsite/src/utils/annotationHighlight.ts(per-owner aggregation, unchanged behaviour) so all four hosts share it. Iframe bodies keep their own in-frame selection visible instead.One composer wiring for every artifact host (from review): the pending/staged anchor promotion, the
externalSelectionstate, the highlight token, the draft mirror and the draft guard live once, inwebsite/src/hooks/useSelectionComposerAnchor.ts, parameterized by what actually differs per host — how the live DOM selection becomes an anchor (resolveDomAnchor, which also paints the highlight), how the anchor is read back (quoteOf/quoteOnly), what a submit posts, and the draft-store key.useFileArtifactComments,ArtifactDetailPageandRemoteArtifactDetailPageeach call it; the three page-local copies of that block are gone, so a guard one host gets, every host gets.A refused post never costs the comment (from review): the artifact hosts'
onSubmitnow returns a promise (postMut.mutateAsync(...)resolved to true/false), andSelectionToolbarwaits on it — the box stays open with its text and its persisted draft while the post is in flight (submit held, a second Enter does not double-post), closes and clears the slot only on success, and on a rejected POST (offline, gateway restart, 5xx) keeps both, shows "Couldn’t save your comment. Your text is still here — try again." inside the box (the string makes no claim about closing: Close asks "Discard your unsaved comment?" and a confirmed discard clears the slot), and lets the retry post against the same anchor. While the post is in flight nothing waits on the network and nothing discards: Escape and ✕ close the box but ask nothing and clear nothing, and the host's own draft guard (Edit, version switch, full screen, close, Back, Fork) proceeds without asking — the text is already in the durable slot, and the flight's own settle decides it (a success clears the slot even after the box is gone; a refusal leaves it for the next open over the same passage). A confirmed discard mid-flight would have cleared the slot under a post that may still be refused, and waiting for the answer would have left the box stuck on a hung POST. A late success clears only the anchor that post was made against (a generation counter on the shared hook), so a slow post on one passage or one artifact cannot null the anchor of the box open on the next. The Add comment control shows a spinner and reads "Saving…" (new keycomponents.selectionToolbar.saving, from UX review: a bare spinner read as "could be loading" and invited a re-select instead of a wait) and the input is read-only (a keystroke landing before the answer would be blanked by the success path), and on success the persisted slot is cleared even if the box was torn down mid-post (a slot that survived would come back as a draft of a comment already stored). A voidonSubmit(the file viewer's local add) still closes at once. A composer post that fails is reported once, inside the box: the local hosts route it through a banner-free mutation (postAnchoredMut), so the page's "Comment action failed — " banner stays down for it (the sidebar's document-level add, replies, resolves and deletes keep their banner). New i18n keycomponents.selectionToolbar.comment_post_failedinen.manual.json+ 11 catalogs + en-XA.The composer stays inside its document column (from review): the toolbar's clamp now also bounds the box's right edge by its container's, so a selection near the column's edge on the artifact page no longer opens the box over the comments sidebar's cards; a container narrower than the box (the docked side panel) keeps the viewport clamp alone.
The discard prompt is reachable from full screen (from review):
Modalgainslayer: 'top'(z-[10000]/[10001]) anduseConfirmforwards it; all four hosts' "Discard your unsaved comment?" use it: the artifact panel and file viewer raise it from inside an opaque full-screen shell at z-[9999] (which otherwise painted over the prompt and left Exit full screen looking dead), and the two artifact pages raise it while the composer — itself a z-[9999] body portal — is still mounted and would swallow clicks on the prompt's buttons.One Range→anchor derivation (from review): the quote / prefix / suffix / offset arithmetic every host ran on the live selection is now
anchorFromRange(root, range)inwebsite/src/utils/selectionAnchor.ts, called by the three artifact resolvers and byMarkdownPanel's selection-coords path; the per-host resolvers keep only what differs (containment predicate, source-coordinate lookup, the highlight paint).Toolbars keyed per artifact (from review): both artifact pages key their
SelectionToolbarmounts by the artifact (slug,provider/externalId), so a param-only navigation between cached artifacts (the route element is reused) remounts the box instead of carrying the previous artifact's draft and anchor into the next one's callbacks.One draft guard, owned by the layer (from review):
useFileArtifactCommentsreturnsguardCommentDraft(the shared hook's) andArtifactPaneluses the active layer's guard directly for full screen enter/exit and close; the panel's own copy of that logic and the two pass-through members it needed (hasComposerDraft,clearComposerDraftSlot) are gone.Draft store: memory is authoritative (from review):
composerDraftStoreForreads the tab's in-memory snapshot (deletions included) whenever one exists and consultssessionStorageonly to seed a fresh tab, so a slot deletion whose storage write was refused cannot be resurrected from the stale record as a draft of an already-posted comment. The remote page's composer post also goes through its ownpostAnchoredMut, so its refusal raises the in-box notice alone.Draft safety on the artifact hosts (from review): the composer reports its draft state, and every action that unmounts the toolbar asks "Discard your unsaved comment?" first — Edit and the version picker on the page, full screen enter/exit, close and Escape on the side panel, and Escape / Close / Back / Fork on the remote page (the file viewer's prompt wording). A typed draft is also persisted per artifact + passage through the shared
draftStore, so a chat-slot switch (which replaces the whole side panel), a page navigation or a reload brings it back on the next open over the same passage (the remote page keys its store per provider + external id); a confirmed discard clears that passage's slot. External (iframe) selections restore too:externalSelectionnow carries the frame'sstartoffset as the passage key, and the toolbar reads the store on that path like it does on the DOM path. File-viewer rider (from review, sharedSelectionToolbar): an EMPTY open box re-targeted onto another passage now restores THAT passage's saved draft instead of leaving an empty box over its slot — previously the restore was skipped whenever the box was already visible, so the first keystroke overwrote the saved text.ArtifactDetailPage/RemoteArtifactDetailPage: same pattern.handleMouseUp/handleMdMouseUpbecome anchor-only resolvers called fromonOpen; the passiveonMouseDown/onMouseUpprobes on the prose wrappers (and their a11y eslint waivers) go away, since the toolbar owns the gesture. The DOM toolbar is mounted only while an anchored comment can be made (commentableon the local page;isMarkdownon the remote page); the iframe branches mount one withexternalSelectionwired to the bridge. A plain-source remote body gets no toolbar, as before.SelectionToolbar: theexternalSelectionpath now opens the composer like a DOM selection does —onOpenfires before focus, submit is live, a typed draft is not re-anchored by a new external selection, and setting it back tonullcloses an external-sourced box (the host revoked the selection). It saves no container offsets (there is no DOM range), so Escape closes without restoring the selection and the box does not follow a scroll; it is placed below the handed-over point, never over the line. NewexternalOnlyprop: onlyexternalSelectionopens the toolbar (the iframe wrapper's own render-failure text is not annotatable). The composer's Cmd/Ctrl+C now copies the selection EXACTLY as made (boundary whitespace kept, viarawSelectedTextRef) — this reaches the file viewer'sMarkdownPanelcomposer too; anchors stay trimmed. No production mount passedexternalSelectionbefore this PR (tests only), so the plain-row behaviour is unchanged.Enumeration of every
CommentPopovermount /requestAnchoredCommentconsumer, with verdicts:FileArtifactComments.tsx:282→ composer (this PR);ArtifactPanel.tsx:192consumer → composer prop (this PR);ArtifactDetailPage.tsx×2 (iframe + native) → composer (this PR);RemoteArtifactDetailPage.tsx→ composer (this PR);capture/comment-popover-copy.{html,tsx}+scripts/capture-comment-popover-copy.mjs→ deleted (subject gone);integration/CommentOverlay.integration.test.tsxCommentPopover block → deleted (CommentList / formatCommentsMessage blocks kept);src/test/CommentPopover.copy.test.tsx,CommentPopover.copyRaw.test.tsx→ deleted (the composer's copy contract is pinned inSelectionToolbar.composer.test.tsx; the anchor-trim contract inArtifactDetailPage.anchoredComments.test.tsx). Every otherSelectionToolbarmount (MarkdownPanel×2 composer, chat's plain rows) keeps its props; the one behaviour they inherit is the raw-text Cmd/Ctrl+C copy above.MarkdownPanel's per-file comment-draft store is extracted verbatim intowebsite/src/utils/composerDraftStore.ts(composerDraftStoreFor(key), sessionStorage + in-memory twin) so the artifact hosts can use the same one — its behaviour is unchanged.A post refused after its box was closed is still reported (from review): when ✕ / Escape closed the box mid-flight and the store then refuses the post, the toolbar has nothing left to render, so the shared hook reports the refusal once (
onRefusedAfterClose, only when the box that posted is gone) and each host shows "Your comment wasn’t saved. Select the same text again to pick it up and try again." on the failure surface it already has (the page banner on both artifact pages, the sidebar's failure line in the side panel); on every host the notice is retired the moment a later composer post succeeds, so it cannot keep inviting a retry that already landed. The slot keeps the text, so that instruction holds: the same selection restores it. One new key,components.selectionToolbar.comment_post_failed_closed, in all 12 catalogs + en-XA.One flight per draft, newer text always kept (from review):
ComposerDraftStoregainshold/release, keyed by the passage AND the pending text. While a post is in flight, a read that would return exactly that pending text returns null on every store instance over the same key — so a second composer instance over the same passage (the side panel's full-screen layer, opened mid-post; or the same passage re-selected after Escape mid-flight) cannot restore the pending text and post it a second time — but the slot stays writable: what that second box types is the user's newer draft and is written. The flight's settle then clears the slot only if it still holds the text that was posted (clear(anchor, start, onlyIf)); a newer draft survives the old post's success and its refusal alike, and the next open over the passage restores it. (Round 26 held the whole slot and refused writes, which dropped that newer draft — reversed here.) The snapshot also carries tombstones: a slot this tab cleared stays cleared even when the storage write recording the deletion was refused, while storage still seeds a slot this tab never touched (a draft from an earlier page lifetime). The pending-post key isJSON.stringify([key, start, anchor, text])— the anchor is the selected passage itself and may hold newlines, so a delimiter-joined key would have let a saved draft overAand an in-flight post overA\nBat the same offset mask each other (from review, round 28).One count of outstanding posts, not one flag (from review): the shared hook counts posts in flight and the draft store counts holds per pending text, so when box A is closed mid-flight and box B posts over the same text, A settling first leaves the host "in flight" and the passage held until B settles — a guarded transition in that window still proceeds without discarding B's draft, and B's refusal still finds its text. The store's
isHeld(no consumer) is removed.The panel mounts a composer only where a selection can anchor (from review):
ArtifactPanelmounts itsSelectionToolbarfor iframe bodies and for markdown / text — the two native kinds whose renderer attaches the preview ref, the same two the artifact page allows. Over json / svg / image (rich viewers, no ref) a composer could never open, so none is mounted — but the Copy row the panel shipped before this PR stays (from review): a single Copy control, no composer, over the scroll box, so a selection in a json / svg artifact keeps a reachable copy on touch, where there is no Cmd/Ctrl+C. The retired pill's dead Comment button is the only thing gone from those bodies. On the iframe branch both panel toolbars (docked and full screen) take the scroll box ascontainerRef(the preview ref is never attached there;externalOnlykeeps the toolbar's own selection check off it), so the box's placement clamp has a right edge to honour and a right-half bridge selection cannot open the box over the comments sidebar.The "not saved" banner never masks a later write, and is never masked by an earlier one (from review): on the remote page the orphaned-post notice is cleared by the user's next write attempt of any kind (the composer's included) — so it can never hide that attempt's own refusal — and it sits FIRST in the banner's fallback chain: a react-query error clears only on its own mutation's next mutate/reset, so a sidebar add refused earlier would otherwise sit in front of a fresher "not saved" notice for good (the composer posts through its own mutation and never resets
postMut).A box closed mid-flight abandons its flight (from review): the toolbar tracks the current flight (
flightRef); Escape / ✕ mid-flight reset the submitting state so the next box over any passage opens editable, and the abandoned flight's settle only releases / clears the slot — it never touches the UI of a box it no longer owns.The page anchor carries its neighbours (from review):
ArtifactDetailPage's native resolver now forwards theprefix/suffixthatanchorFromRangealready computed (the oldhandleMouseUpnever did), so a page comment on the second of two identical passages re-anchors to the second —rangeForAnchorscores a repeated quote by its context. The iframe path already carried them.The "not saved" banner names the passage (from review):
onRefusedAfterClosereceives the annotated quote (folded to one line, clipped at 48 characters) and the notice reads "Your comment on “…” wasn’t saved. Select that text again to pick it up and try again." — the reader who dismisses it keeps a pointer to the text to select. Thecomment_post_failed_closedstring is re-translated with the{{quote}}placeholder in all 13 catalogs.Stale comments retired (from review): the two notes that described
onMutErrrendering a composer refusal are replaced by the actual contract — the composer's mutation deliberately skips the page / sidebar banner so a refusal is reported once, in the box.The draft slot is keyed on the word, not the drag (from review): the toolbar's slot offset now skips whatever leading whitespace the selection started on (
start = pre.length + (raw.length − raw.trimStart().length),length = raw.trim().length), so it agrees with the trimmed passage the host is told about and with the hosts' ownanchorFromRangeoffset — a draft typed after selecting " beta" is filed underbeta's offset and re-selectingbetarestores it, where before it was orphaned under a key no later selection could read. The same trimmed offsets feed Escape's selection restore and the scroll re-anchor.The artifact page suspends its composer under a full-width panel (from review): on a narrow viewport an open comments / chat panel hides the document body; both
ArtifactDetailPagetoolbars now takesuspended={narrowPanelOpen}(the body wrapper's ownhiddencondition) so the box, portalled to<body>, stops floating over the panel and returns with its draft when the panel closes — the same shapeArtifactPanelalready passes.A refusal never leaves the flight as the text's only copy (from review): with a post in flight and its box closed, a second box over the same passage may type a newer draft (kept — later words win) and then DISCARD it, emptying the slot; if the old post is then refused, the toolbar's settle writes the pending text back into the empty slot, so the "select that text again to pick it up" notice holds. A newer draft still in the slot is left alone; a success still clears. No new store layer — the flight already holds the text.
✕ says that closing does not stop a post (from review): while a post is in flight the composer's close button is labelled "Close — saving continues" (
components.selectionToolbar.close_saving_continues, 13 catalogs), so the cue sits at the point of action instead of the comment appearing later unannounced.A refused post asks the store whether the slot is truly empty (from review): the write-back above must not overwrite a NEWER draft whose own post is still in flight — the store's
readmasks such a draft as null, exactly so a third box cannot re-post it. The store gainsisEmpty(anchor, start), the unmasked check, and the settle restores the pending text only when it is true; a newer held draft survives the older refusal and is what the newer refusal finds in its box and in the slot.The "not saved" notice is per artifact (from review): both artifact pages are one route element reused across artifacts; the notice names a passage of the artifact it was typed on and its draft waits under that artifact's key, so
ArtifactDetailPagenow clears it on[slug]andRemoteArtifactDetailPageon[provider, externalId]— it is never shown over the next artifact.Copy. The composer's Cmd/Ctrl+C copies the raw, untrimmed selection — the contract the retired popover's Copy button had (
CommentPopover.copyRaw.test.tsx, now pinned inSelectionToolbar.composer.test.tsx). Anchors are trimmed as before, so the stored data is unchanged. The visible Copy button is gone from the artifact hosts (two-per-row cap); the file viewer's composer keeps its own Copy action.Backwards compatibility
Compatible: nothing a user can do today stops working — the same selection still leads to the same anchored comment in the same store, one step shorter. Internally this REMOVES
CommentPopover(CommentOverlay.tsx) anduseFileArtifactComments().requestAnchoredComment, and every consumer of both is enumerated with a verdict in the mount list above (all insidewebsite/; none outside the diff).ComposerDraftStoregainshold/releaseand an optional thirdclearargument (additive). On the chat side panel json / svg bodies keep their Copy row (one control; only the pill's dead Comment button is gone — see the mount bullet). i18n:components.commentOverlay.add_a_commentis deleted (only the retired popover used it) andcomponents.selectionToolbar.comment_post_failed_closedandcomponents.selectionToolbar.savingare added, all across the 12 catalogs + en-XA. No production caller passedexternalSelectionbefore this PR; the behaviour change on that path is exercised only by the new artifact-host mounts.Tests
website/src/test/FileArtifactComments.test.tsx(+5):onOpenresolves the live selection into an anchor pinned to THIS occurrence of a repeated quote (anindexOfanchor would land on the first — mutation-killed);onOpenwith no live range anchors on the quote alone with no offsets; an in-iframe selection setsiframeSelectionand keeps the bridge's prefix/suffix throughonOpen(mutation-killed: dropping the keep-branch fails it);onClosediscards both;onSubmitbefore anyonOpenis a no-op.website/src/test/SelectionToolbar.composer.test.tsx(+5, new describe): external selection opens the composer withonOpenbefore focus and submits the external text; Escape closes with oneonClose; a new external selection over a typed draft does not re-anchor it (mutation-killed: removing the guard fails it); over an EMPTY box it re-opens; without a composer the plain row still shows.website/src/test/ArtifactDetailPage.anchoredComments.test.tsx: rewritten against the composer input label, negative cases now wait past the toolbar's debounce, +1 scene for a selection made inside a widget iframe (bridge → composer → anchor is quote + context only).website/src/test/RemoteArtifactDetailPageCoverage.test.tsx(+4),website/src/test/ArtifactPanelCoverage.test.tsx: adapted (the panel stub now asserts the active layer's composer is wired and the widget mount receives the bridge selection, and that no Comment action remains); on the remote page Escape, Back and Fork over a typed draft each ask first (Cancel keeps the draft and stays put; Discard proceeds), and a typed draft comes back when the same passage is selected after the page was unmounted (mutation-killed: droppingconfirmDiscard+ a stable draft key fails all four).SelectionToolbar.composer.test.tsx(+3: a refused submit keeps text/draft/anchor, shows the notice, blocks a double-post while pending, and the retry goes through; a rejecting promise reads as a refusal; a void submit still closes at once),useSelectionComposerAnchor.test.tsx(+1: a refused submit keeps the pending anchor),FileArtifactComments.test.tsx(+2: refused post resolves false and the retry posts the same anchor; sidebar thread activation on native and iframe bodies),ArtifactDetailPage.anchoredComments.test.tsx(+1) andRemoteArtifactDetailPageCoverage.test.tsx(+1): the page keeps the typed comment and does not reveal the panel until the retry lands. Mutation checks: forcing the toolbar to close on a false outcome fails 2 tests; forcing the hook to clear on a false outcome fails 1.website/src/hooks/useSelectionComposerAnchor.test.tsx(+5): the shared wiring —onOpensubmits the DOM-resolved anchor once and clears; a staged bridge anchor is promoted only when the toolbar opens for that same text (a different text falls back to the quote alone);onClose/clearSelectionStatedrop pending + external selection;guardCommentDraftasks only while a draft is open and clears that passage's slot on a confirmed discard; the toolbar receives the host-keyed store and the sameconfirmDiscard.mainfail 20 tests (composer absent / labels / stub shape); green here. Run by path only.FileArtifactComments.tsxgraduated past the 80% per-file floor with the new tests, so its row is removed from.github/coverage-baselines/frontend.txt(the gate's own rule: a file that meets the floor leaves the baseline; adding a row is the forbidden direction).SelectionToolbar.composer.test.tsx(+2: a selection dragged from the space before a word writes and restores its draft under the word's own offset — mutation check: the untrimmed offset fails it; the ✕ label reads "Close — saving continues" only while a post is in flight — mutation check: a fixed label fails it),ArtifactDetailPage.anchoredComments.test.tsx(+1: on a narrow viewport opening the comments panel hides the composer and closing it brings the typed draft back — mutation check: droppingsuspendedfails it).ArtifactDetailPage.anchoredComments.test.tsx(the posted-anchor test now pinsprefixending inalphaandsuffixopening withgamma— mutation check: dropping the pass-through fails it; the refused-after-close scene pins the quoted notice),useSelectionComposerAnchor.test.tsx(+1: the host receives the passage, folded and clipped to 48 characters with an ellipsis — mutation check: passing the raw quote fails it; the refusal test pins the argument),FileArtifactComments.test.tsx/RemoteArtifactDetailPageCoverage.test.tsx(notice pins updated to the quoted string). Capture driver: +2 assertions measuring the composer's right edge against the comments sidebar's left edge in the draft scene (871 ≤ 916 on both themes).composerDraftStore.test.ts(+1: a hold over the multi-line passageA\nBnever masks the sibling passageA's draft that spells the same bytes — mutation check: the delimiter-joined key fails it),FileArtifactComments.test.tsx(+1: the refused-after-close notice is gone once the retry it asks for lands — mutation check:onSuccess: invalidatealone fails it),SelectionToolbar.composer.test.tsx(+2: a re-target over an emptied box, DOM path and external path, opens without the previous passage's post-failed notice — mutation checks: dropping eithersetSubmitFailed(false)fails its test).composerDraftStore.test.ts(the hold test now pins masking by text; +1: a newer draft written over a held passage is kept, the settling post clears only the text it posted, a matching conditional clear tombstones),SelectionToolbar.composer.test.tsx(+2: a newer draft typed over the passage after a mid-flight Escape survives the old post's success and its refusal, and comes back on the next open; the placement re-runs when the post-failed notice appears so an above-selection box does not grow over the passage — the refusal lands with no key event to re-run it; the in-flight tests pin the "Saving…" label). Mutation checks: an unconditional clear on success, a read that masks the whole held slot, and droppingsubmitFailedfrom the placement deps each fail their test. Capture driver: the in-flight scene asserts the Saving… label and no Add comment button (122 assertions).SelectionToolbar.composer.test.tsx(+1: a refusal puts the pending text back when the newer draft typed over it was discarded, both outcomes — mutation check: dropping the write-back fails it),ArtifactPanelCoverage.test.tsx(json body gets a Copy-only toolbar and no composer; the widget body's toolbar container is the attached scroll box — mutation checks: dropping either fails them),RemoteArtifactDetailPageCoverage.test.tsx(+1: an earlier refused sidebar write does not hide a later "not saved" notice — mutation check: the old chain order fails it),artifactPanelsNarrow.test.ts(main's source pin follows the namednarrowPanelOpencondition). Capture driver: +1 scene (kind=json, 4 assertions), 132/132.composerDraftStore.test.ts(+1:isEmptysees through a hold — a slot holding a newer in-flight draft is not empty; a discarded draft is, and a stale storage record does not un-empty it — mutation check: a maskedisEmptyfails it),SelectionToolbar.composer.test.tsx(+1: a refused older post never overwrites a newer draft whose own post is still in flight — mutation check: the oldread === nullcheck fails it),ArtifactDetailPage.anchoredComments.test.tsxandRemoteArtifactDetailPageCoverage.test.tsx(+1 each: the "not saved" notice does not follow a param-only navigation to another artifact — mutation checks: dropping either page's reset fails its test).useSelectionComposerAnchor.test.tsx(+1: the first of two outstanding posts settling does not make the second's draft discardable — mutation check: a flag instead of a count fails it),composerDraftStore.test.ts(holds count; releasing one of two keeps the passage held — mutation check: a set instead of a count fails it),ArtifactPanelCoverage.test.tsx(+1: json body toolbar — superseded in round 33 by the Copy-only row),RemoteArtifactDetailPageCoverage.test.tsx(+1: the "not saved" banner yields to the next write's own refusal — mutation check: the old chain order + no clear fails it). Capture driver: +1 scene (post=slowfail, 14 assertions).composerDraftStore.test.ts(+2: a held slot reads as empty and refuses writes on every instance over the key until released; a slot seeded in storage by an earlier page lifetime is still read while a sibling this tab cleared stays cleared),SelectionToolbar.composer.test.tsx(+1: a flight abandoned by Escape neither freezes the next box nor closes it when it settles),useSelectionComposerAnchor.test.tsx(+1: a refusal is reported to the host only when the box that posted is gone),FileArtifactComments.test.tsx(+1: the sidebar's failure line carries the refused-after-close notice),ArtifactDetailPage.anchoredComments.test.tsxandRemoteArtifactDetailPageCoverage.test.tsx(+1 each: the page banner carries it, the same selection brings the text back and the retry posts it). Mutation checks: dropping the hold, dropping the abandon, dropping the orphan report, dropping the tombstones and lettingreadignore a hold each fail their test. The capture driver gains 4 assertions on the refused-post scene (exactly one failure notice; no page banner with the store's raw reason).useSelectionComposerAnchor.test.tsx(+1 generation guard — a late success on A leaves B's anchor; the in-flight guard test now pins proceed-without-asking and slot untouched),SelectionToolbar.composer.test.tsx(Escape mid-flight closes, keeps the slot, no prompt; a late success after ✕ clears the slot),composerDraftStore.test.ts(+1: a clear whose storage write is refused still wins),RemoteArtifactDetailPageCoverage.test.tsx(no page banner on a refused composer post). Mutation checks: dropping the generation compare, dropping the in-flight proceed, restoring the storage merge, dropping the mid-flight branch, and routing the remote post back throughpostMuteach fail their test.SelectionToolbar.composer.test.tsx(+1: Escape/✕ refused while a submit is in flight, then honoured after the refusal — mutation check: dropping the in-flight check fails it),useSelectionComposerAnchor.test.tsx(+1: the guard waits for the in-flight post — mutation check: dropping the wait fails it),ArtifactDetailPage.anchoredComments.test.tsxandFileArtifactComments.test.tsx(a refused composer post raises no page/sidebar banner — mutation check: routing back through the banner mutation fails it).selectionAnchor.test.tsbuilds its fixtures withcreateElement/textContent(Automated Rule Check: noinnerHTML).selectionAnchor.test.ts(+5: this-occurrence offset, leading-whitespace skip, Range.toString space across blocks, 32-char context caps and edge clamp, whitespace-only → null),RemoteArtifactDetailPageCoverage.test.tsx(+2: a draft does not follow a cached A→B navigation — mutation check: dropping the key fails it; Back's prompt on z-[10001]),ArtifactDetailPage.anchoredComments.test.tsx(Edit's prompt on z-[10001]),SelectionToolbar.composer.test.tsx(spinner while submitting).SelectionToolbar.composer.test.tsx(+2: input read-only + slot cleared on a success after unmount; box clamped into the container column),ConfirmDialog.test.tsx(+1:layer: 'top'paints on z-[10001]),ArtifactPanelCoverage.test.tsx(+1: Exit full screen over a draft raises the prompt above the shell). Mutants killed: no slot clear before the mounted gate, read-only dropped, viewport-only clamp, layer dropped.tsc -b,eslint --max-warnings 0on changed files,i18n:check,check-i18n-keys,lint:i18n,deadKeys/catalogParity/keyReference, theme-colors / phantom-classes / restyle-ratchet,jscpd(0 clones).website/scripts/capture-artifact-selection-composer.mjsdrives the isolated entrywebsite/capture/artifact-selection-composer.{html,tsx}— the REALArtifactDetailPage/RemoteArtifactDetailPage/ArtifactPanelover a fetch stub at the API boundary, including the real sandboxed iframe and real in-iframe bridge (the driver selects text INSIDE the frame). 132/132 assertions pass per run (composer opens on selection, no Comment button, the annotated passage is highlighted under the box, the box holds exactly Add comment + Close, the posted anchor carries quote + offsets on the DOM path and quote + context only from the frame, the posted comment appears; Edit over a typed draft raises "Discard your unsaved comment?" with Discard comment + Cancel and Cancel keeps the text and stays out of edit mode; after a full reload a fresh document shows no box, re-selecting the same passage brings the typed draft back, and Escape over it asks first; with the fixture'spost=failthe refused post keeps the text, re-enables the input and Add comment, stores nothing; withpost=slowthe in-flight box shows the spinner, holds Add comment, keeps the input read-only with its text, and the post lands when the store answers; the remote page opens the composer on its markdown body and from a selection inside its HTML iframe, Back over a typed draft asks first and Cancel keeps both, the posted anchor carries offsets +version_number; in the side panel's full screen a selection opens the composer, and Exit full screen over the draft raises the prompt on the z-[10001] layer where it is the topmost hit target at its Cancel button).Manual verification
website/scripts/capture-artifact-selection-composer.mjsagainst the isolated entry (see Screenshots): 124/124 assertions on this head, scenes per theme: artifact page markdown body (open + post), widget body (in-iframe selection), page draft (Edit prompt; full reload then re-select restores), page in-flight (post=slow), page refused (post=fail), page closed-then-refused (post=slowfail: Escape mid-flight, then the 503 — the page banner, then re-selecting restores the text), side panel docked and full screen (prompt above the shell), remote page markdown and HTML bodies (Back prompt). The cached A→B navigation is covered by unit tests only.Denied ID …@pierre/diffs…?worker&urlfrom Vite's fs.allow on the editor tests ofArtifactDetailPage.test.tsx— identical onmainin the same environment, not reachable in CI (realnode_modules).Screenshots / video
After typing and pressing Enter, the anchored comment lands in the durable store and shows in the sidebar (dark / light):
A typed comment is never dropped silently. Any action that unmounts the box (Edit, a version switch, full screen, close, Escape, Back / Fork on the remote page) asks first, and a draft survives a teardown no guard can catch — leaving the page, a chat-slot switch — coming back when the same passage is selected again:
The remote artifact page gets the same composer on both of its bodies, and its Back / Fork ask before leaving a typed draft behind:
The chat side panel over a json artifact (dark / light): no anchor resolver maps its selections, so no composer — the single-control Copy row the panel shipped before stays, and on touch is the only reachable copy:
The chat side panel's full-screen mount: the composer over a selection in the full-screen body, and Exit full screen over that draft raising the prompt ABOVE the full-screen shell (dark / light):
While the store is answering (dark / light): the submit control reads "Saving…" with a spinner, the input is read-only, a second Enter cannot post twice; ✕ and Escape still close the box but keep the draft in its slot for the flight to decide:
A post the store refuses never costs the comment (dark / light): the typed text stays in the box, read-only only while the post is in flight, with "Couldn’t save your comment. Your text is still here — try again." and Add comment offered again; nothing was stored, so the comments panel did not reveal:
The box closed mid-flight (Escape / ✕), then the store refused the post (dark / light): the box is gone, so the page banner says so — "Your comment on “Draft the rollout checklist” wasn’t saved. Select that text again to pick it up and try again." — one notice, naming the passage, no raw store reason; re-selecting the passage brings the text back:
Related Issues
Closes #9823
Context: #9812 (the file viewer's type-first composer and the Design / UX approval of its shape), #9760 (the original extra-click harm).
Pattern harvest
Rule candidate: when a host lets a
SelectionToolbarcomposer open from anexternalSelection, resolve the anchor in the host'sonSelect/bridge handler FIRST and letonOpenkeep it when there is no live DOM range for the same text —onOpencannot re-derive it, and overwriting it with the bare quote silently loses prefix/suffix.Rule candidate: a
useEffectthat opens a composer at mount must be declared after the visibility effect that firesonCloseon!visible, or the mount-time run of the latter closes the box the former just opened.Rule candidate: when the same
SelectionToolbarcomposer is mounted by several hosts, the anchor promotion + draft guard belong in one shared hook parameterized by the host's resolver and submit — a guard added to one inline copy is a guard the other copies silently lack (the remote page shipped three rounds without the discard prompt its siblings had).Rule candidate: a store accessor that MASKS state for one caller (a held draft reads as null so a second box cannot re-post it) must not be the accessor another caller uses to test emptiness — give emptiness its own unmasked accessor, or the masking caller's safety becomes the other caller's data loss.
Not generalizable: the sidebar footer's "+ Add comment" sharing a verb with the composer's submit predates this PR (the retired popover used the same label); a distinct verb there is a
CommentsSidebarfollow-up across every host of that sidebar, not a selection-composer change.Not generalizable: the artifact pages drop the iframe's start/end offsets on purpose (the parent highlighter's text space differs); the remote page keeps them because the provider's anchor schema requires them — a per-store contract, not a rule.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)