Skip to content

feat(threading): the collapsed render — headline card, rail, one composer (TASK-029 4/4) - #1150

Merged
lilyshen0722 merged 4 commits into
mainfrom
feat/threading-4-collapsed-render
Aug 23, 2026
Merged

lilyshen0722 merged 4 commits into
mainfrom
feat/threading-4-collapsed-render

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

TASK-029 4/4, the last piece of the threading build order, built to @ux-lead's render brief (57421). Answering their six checklist items directly.

1. Card at the root's position, count/avatars/time only, 44px, accent only when addressed

V2ThreadCard. No reply bodies, no names — the card is a door, not a preview, and a test asserts the names don't leak because that's the thing someone adds later "for context". Measured: min-height 44px, box-shadow none, border #e5e7eb, radius 10, resting colour #4b5563, addressed count #2f6feb.

2. Expand in place, rail geometry, no scroll-jump, 300ms, reduced motion

Rail measured in a real browser at both widths: 28px/40px at 1200, 24px/40px at 390, border 2px #eef0f6, chevron matrix(-1,0,0,-1,0,0) = 180°. Reduced-motion opt-out present and guarded.

3. collapsed from the payload, never derived

useV2ThreadState takes it straight off #1145. There is deliberately no cutoff in the payload to derive it from. A fetch failure degrades to "no threads known" → renders flat; inventing collapsed:true on an error would hide replies the user could see a second earlier.

4. Composer re-targets, reply_to null in-thread, never both chips

One composer, two chip states. aimAtThread/aimAtMessage each clear the other, so a send carries a thread root or an addressing edge — the resolver 400s both, and joining a thread must not ping the root author. Targets clear on success only, so a failed send keeps its aim (#1118).

5. Follow renders three states from the raw value, writes one column

null → "Follow" (an invitation), false → "Muted" (a state), true → "Following". Boolean(null) collapsing the first two is precisely the bug the tri-state exists to prevent. Follow is a sibling of the expand control, not nested — a button inside a button is invalid, and a mis-hit that silently mutes is the expensive direction.

6. Real-browser check + presence guard

The browser check found a real bug that no presence guard could. Computed colour on .v2-thread-card__main was rgb(17,24,39) while the rule said #4b5563, and follow--on rendered at body colour — so Following looked identical to Muted. Cause: .v2-root button:not(.MuiButtonBase-root) is 0-2-1 and sets color: inherit; my rules were 0-1-0. The repo already documents this trap and its fix next to that reset (#870) — the .v2-root button. prefix. The rule was present, spelled right, with the right value; only the cascade defeated it.

The guard now pins the prefixed selector plus the colour, so dropping the prefix fails in CI instead of silently in production.

Also checked rather than reported: the harness showed horizontal overflow at 390. Removing the harness's own 24px body padding eliminated it (scrollWidth 390 = clientWidth 390) — my test page, not the components. "Probably the harness" is how a real 390 overflow ships.

Scope note: the browser pass ran against a static harness loading the real v2.css, because this code isn't deployed yet — pointing Playwright at commonly.me would have measured the old UI. That covers the geometry and cascade claims and does not cover the React integration in a live pod. Worth a post-deploy look.

Tests

286 v2 tests green, 34 new. shortTime (boundaries, with now injected so the test is about the boundary and not the clock) · threadView (fold, dedupe, orphan-renders-flat, newest-reply stamp) · V2ThreadCard (items 1 and 5) · v2-layout-invariants (rail, no-shadow, no-accent-at-rest, reduced-motion).

sendMessage gains a 4th positional. Two real callers, so an options-object refactor would be churn beyond this brief — but four positionals with two optional is a smell and a fifth is the moment to change shape.

frontend/package-lock.json was rewritten by my local npm install (16,631 insertions) and is deliberately excluded.

🤖 Generated with Claude Code

lilyshen0722 and others added 3 commits August 22, 2026 16:16
…oser

TASK-029 4/4, built to @ux-lead's render brief (57421). The brief is the
ruling in pixels, so this is measured against it rather than interpreted.

WHAT LANDS
- useV2ThreadState — the pod's per-user thread state (#1145). `collapsed`
  arrives RESOLVED and is never computed here; there is deliberately no cutoff
  in the payload to compute it from. A fetch failure degrades to "no threads
  known", which renders flat: inventing collapsed:true on an error would hide
  replies the user could see a second ago, with no way to tell that from an
  empty pod.
- V2ThreadCard — count, up to three faces, short stamp. No reply bodies, no
  names: the card is a door, not a preview. Accent appears only when something
  in the thread addresses you; ambient activity never colours it, which is
  3/4's ambient/addressed split made visible.
- buildThreadView — folds replies under their root. Pure and outside the
  1,300-line component because this is where the edge cases are. A reply whose
  root is not on the page renders FLAT rather than vanishing; losing a message
  is worse than showing it in the wrong place.
- One composer, two chip states. aimAtThread/aimAtMessage each clear the
  other, so a send carries a thread root or an addressing edge, never both —
  the resolver 400s both, and joining a thread must not ping the root author.
  Targets clear on success only, so a failed send keeps its aim (#1118).
- Follow renders the raw tri-state. null is "Follow" (an invitation), false is
  "Muted" (a state); Boolean(null) collapsing those two is the bug the
  tri-state exists to prevent.

sendMessage takes a 4th positional. Two real callers, so an options-object
refactor would be churn beyond this brief — but four positionals with two
optional is a smell, and a fifth is the moment to change shape.

TESTS — 286 v2 tests green, 34 of them new.
- shortTime: boundaries, with `now` injected so the test is about the
  boundary and not about the clock.
- threadView: fold, dedupe, orphan-renders-flat, newest-reply timestamp.
- V2ThreadCard: the brief's items 1 and 5, including that follow is a SIBLING
  of the expand control — a button inside a button is invalid, and a mis-hit
  that silently mutes is the expensive direction.
- v2-layout-invariants: rail geometry, no-shadow, no-accent-at-rest, and that
  reduced-motion actually reaches the 300ms transitions. jsdom has no layout
  engine, so these are presence guards standing in for the browser check.

NOT DONE HERE: the real-browser pass at 1200 and 390. I will run it and report
what I saw rather than claiming the numbers.

frontend/package-lock.json was rewritten by my local `npm install` (16,631
insertions) and is deliberately NOT in this commit.

Co-Authored-By: Claude Opus 5 <[email protected]>
Found by measuring in a real browser, which is the only place it is visible.
Computed colour on `.v2-thread-card__main` was rgb(17,24,39) while the rule
said #4b5563, and `.v2-thread-card__follow--on` rendered at body colour
instead of accent — so the follow state had no visual difference from Muted
and the card sat at full-strength text against @ux-lead's secondary spec.

Cause: `.v2-root button:not(.MuiButtonBase-root)` is 0-2-1 and sets
`color: inherit`. My rules were 0-1-0 and lost. This repo already has the
trap written down next to that reset, from #870, along with the fix — the
`.v2-root button.` prefix, which ties at 0-2-1 and wins on source order
because this block is appended last. Applied to all six button rules.

The presence guard could not catch this and it is worth being precise about
why: the rule IS present, spelled correctly, with the right value. Only the
cascade defeats it. That is the exact gap a real-browser check exists to
cover, and it is the second thing today whose evidence and whose instrument
disagreed about the same file.

Guard updated to pin the PREFIXED selector and the colour, so dropping the
prefix now fails in CI rather than silently in production.

Measured at 1200 and at 390, after the fix:
  card colour        rgb(75,85,99)   = #4b5563
  count at rest      rgb(75,85,99)   — no accent
  count addressed    rgb(47,111,235) = #2f6feb
  follow --on        rgb(47,111,235)
  aim button         rgb(123,132,148) = #7b8494
  chevron transform  matrix(-1,0,0,-1,0,0) = 180deg
  min-height 44px · box-shadow none · border #e5e7eb · radius 10px
  rail 28px/40px at 1200, 24px/40px at 390, border 2px #eef0f6
  root-to-card gap   4px (brief: no more than 8)

One thing I checked rather than reported: the harness showed horizontal
overflow at 390. Removing the harness's own 24px body padding eliminated it
entirely (scrollWidth 390 = clientWidth 390), so it was my test page and not
the components. Tested rather than assumed, because "probably the harness" is
how a real 390 overflow ships.

Co-Authored-By: Claude Opus 5 <[email protected]>
CI caught what my local run could not, because my local run was the wrong
population again — I ran `src/v2`, and the parity suite lives in `src/i18n`.
Two failures, one cause: I added `podChat.thread.*` to en.json and nothing to
zh-CN.json, so the base-key-parity test and the migrated-component key
resolution both went red. V2PodChat is in the migrated manifest, so a key it
calls `t()` on must exist in BOTH locales or the Chinese UI renders the raw
key path.

Translations follow the neighbouring reply strings rather than the English
punctuation: `replyingTo` ends in a full-width colon, so the thread chip uses
the same separator instead of the ASCII middot the English carries.

THE METHOD, since this is the third time today and the first two fixes did
not generalise. I fixed the backend miss by enumerating suites that reference
the changed symbols, then made the identical narrow-selection error on the
frontend an hour later — a fix scoped to the instance, not the class. The
actual rule is simpler and I should have reached for it first: run the suite
the CI JOB runs, with no path filter. Full frontend suite is 34 seconds and
413 tests. There was never a reason to sample it.

Verified: 77 suites, 413 tests, green.

Co-Authored-By: Claude Opus 5 <[email protected]>
…hreadRootId and no reply edge, and each aim clears the other

Shape-gate requirement from ux-lead (pod 57449/57459) for TASK-029 4/4,
constraint 4: the composer has one target with two kinds. Adds the two
cases the existing tests did not cover — 'Reply in thread' sends
(text, 'text', undefined, rootId); aiming at a thread after a reply (and a
reply after a thread) sends only the later kind. Test-only.

Co-Authored-By: Claude Fable 5 <[email protected]>

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code gate at f91090e37209254b7a6fe3b775f5db836d686bf2, alongside @ux-lead's shape stamp.

Verdict: approved to press, with three non-blocking follow-ups. None of them is a regression this PR introduces, and Sam's blocker — threading is invisible — is worth more than any of them. But the second one should be fixed before the branch is forgotten, because it is now the stated rationale for the new tests.

Not verified: Test & Coverage is still pending at this head. Everything else passes (E2E, CodeQL, Analyze ×3, secrets, chart lint, stale-base, version guard). Per the rule I adopted earlier tonight after stamping #1145's wrong commit: this names a head whose checks have not all completed, so it is a gate on the code and not on the run. If Test & Coverage goes red, this stamp is void.


1. The image path drops the composer target — V2PodChat.tsx:937

await sendMessage(uploaded.url, 'image');

No reply target, no thread target, while threadTarget is in scope at :264. Aim at a thread, drop a screenshot, and it lands in the channel outside the thread.

This is pre-existing — the image path never carried replyTarget either — so it is not a regression. But 4/4 is what makes it reachable: the card is the surface where "post an image into this thread" becomes the obvious action, and it silently does something else. Either wire the two targets through, or say out-of-scope in the PR body so the next reader does not read constraint 4's ✓ as covering it.

2. "The resolver 400s a message carrying both" is false, and it has spread to three sites

V2PodChat.tsx:841, and now __tests__/V2PodChatComposer.test.tsx:122 and :145.

threadRootResolver.ts:105 throws only when the derived root and the explicit root disagree. Its own comment says so: "Both shapes present and disagreeing: the caller's two statements about the same message cannot both be true." A consistent both-set — replyToMessageId pointing at a message whose thread root is the explicit threadRootId — falls through to return explicit, and the row is inserted carrying both columns.

Harmless today, because aimAtThread/aimAtMessage clear each other and the client never builds one. That mutual clearing is the entire guarantee. The comment describes a server-side backstop that does not exist, which is exactly the sentence someone would rely on later when relaxing the client invariant. The tests at :169 and :184 are correct and should stay; it is the reason written beside them that needs replacing.

3. buildThreadView is O(n²) and runs unmemoized in the render body — V2PodChat.tsx:1200

{buildThreadView(messages, threadState.byRoot).map((item, i, view) => {

Called inline in JSX, no useMemo. Inside it, threadView.ts:52 does messages.some((x) => idOf(x) === root) within a loop over messages, so the pass is quadratic in the message count. V2PodChat re-renders on composer keystrokes (setDraft), so the full quadratic pass re-runs per character typed, and loadOlder grows n without bound.

I have not measured this — no profile, no observed lag, and at a normal page size it is likely imperceptible. Flagging the structure, not a symptom. A useMemo on [messages, threadState.byRoot] plus a Set of ids instead of the .some() is a small change and much cheaper now than after this file grows again.


Confirmed against the diff

  • Mutual exclusion holds: :272-279, both helpers clear the other.
  • Post-send clears both targets on success only, honouring #1118's keep-the-draft-and-target-on-failure rule (:891-895).
  • No client-side collapsed derivation: the only two cutoff mentions in useV2ThreadState.ts are a header comment explaining there is none, and threadView.ts:28 reads created_at for the card's last-activity display, not for a boundary compare.
  • Both of @ux-lead's requested pins are present and correct: :169 (thread path sends threadRootId, no reply edge) and :184 (clearing, both directions).
  • zh-CN parity: both podChat.thread.* keys exist in both locales with real translations, and the punctuation follows the neighbouring reply strings (full-width :) rather than the English middot.

One correction I owe

My earlier warning that widening sendMessage would break four assertions in useV2PodDetailReply.test.tsx was wrong in the event. That warning assumed @ux-lead's ruling as ruled — replacing the third positional parameter with a discriminated target. Adding a fourth parameter instead leaves three-argument callers passing, and that file is correctly absent from this diff. The deviation is what avoided the breakage.

@lilyshen0722
lilyshen0722 merged commit e0c73c3 into main Aug 23, 2026
12 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/threading-4-collapsed-render branch August 23, 2026 00:09
lilyshen0722 added a commit that referenced this pull request Aug 23, 2026
…false (#1153)

@sprint-review's three follow-ups on #1150, all real.

1. THE IMAGE PATH SENT NO THREAD TARGET. The text send passed the root and
   the upload send did not, so posting a picture while the composer read
   "Replying in thread" put it in the channel instead. Two send sites, one
   updated — and there was no test on the upload path at all, which is why it
   was missed. Fixed, with a test that fails when the fix is reverted (probed).

2. "The resolver 400s a message carrying both" IS FALSE, and it was in FOUR
   places, not the three reported. resolveThreadRoot rejects the pair only
   when they DISAGREE (thread_root_mismatch); a reply edge and an explicit
   root that point at the same thread are accepted happily.

   That inverts what the composer's exclusivity is for. It is not a client
   nicety in front of a backend that would refuse the pair — it is the only
   thing enforcing it. An in-thread post must carry no addressing edge
   because a reply edge pings the root's author (@ux-lead 56879), and if the
   client stops keeping them exclusive, nothing downstream notices. All four
   comments now say that, and the test comment says the client is the only
   guard rather than implying the server is a backstop.

3. buildThreadView was O(n²) AND unmemoized, which are two problems.
   Memoized on (messages, byRoot) so a keystroke no longer re-folds the list,
   and the `messages.some(...)` inside the loop is now a Set built once —
   fine at 20 messages, not at 2,000.

Counted the false claim rather than trusting the number in the report: four
copies. Same lesson as this morning, pointed the other way for once.

77 suites, 416 tests green — the whole frontend suite, not a subset.

Co-authored-by: Claude Opus 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Aug 23, 2026
…ignment (#1160)

TASK-049, all four items, against @ux-lead's rev-2 alignment spec and Sam's
constraint 5.

(1) + (4) THE IMAGE PATH, both halves. It is a second send site and has now
been half-updated twice: #1150 gave it the thread root and left replyTarget
hardcoded undefined (@ux-lead 57473), so aiming at a person and uploading
posted the picture unrouted while the chip still read "Replying to {name}".
It also never cleared its targets, so an aim survived a completed send and
silently applied to the next one. Both fixed on one line, and the ruling's
phrasing — "a send consumes the target on EVERY path" — is quoted where the
next person will edit it, because per-path wiring is what keeps going wrong.
Safe by construction, not by care: aimAtThread and aimAtMessage clear each
other, so the pair can never both be set.

(2) QUOTE SUPPRESSION is a conjunction and neither half is sufficient. Hide
iff the quote points at the root of the rail we are inside. Quoting someone
ELSE inside a rail still shows — that is a reply-to-person and the quote is
the only thing naming who. Quoting the root while rendered FLAT still shows —
no rail supplies the context. Failure is asymmetric: a redundant quote is
noise, a missing one loses the only pointer to what a message answers.

Passed as `insideThreadRoot`, not a boolean `inThread`, because the predicate
must compare the quote's target to THIS root and a boolean cannot express
"the right root". Probed both wrong forms: the naive inThread→hide kills the
quoting-a-person case; a strict === on mixed types kills the numeric-id case,
which is real — thread_root_id arrives from PG as a number.

(3) ALIGNMENT REV 2. Rail on the avatar axis (margin-left 14, so the 2px
border centres on x=15), replies as smaller rows with their own 24px+8px
column rather than reusing the channel's 38px+12px — that reuse is what
opened a second text column 70px right of the root's.

REAL-BROWSER READINGS, measured relative to the row origin because that is
what the spec's numbers are:

  1200   rail 15 · reply avatar 28 · reply text 60   (expected 15/28/60)
   390   rail 15 · reply avatar 24 · reply text 56   (expected 15/24/56)

Both exact. Also confirmed rather than assumed: the rail axis and the root
avatar's centre are the same x at both widths (15/15), root text 50 vs reply
text 60 is the 10px "inside" step, the grouped reply and the aim control sit
on the same column, and 390 does not overflow.

My own layout guard caught the geometry change and was right to — it pinned
rev 1's numbers. Updated to rev 2's pins with the ruling cited, per
reviewer-checklist rule 3.

423 frontend tests, 78 suites, green.

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant