Skip to content

fix(chat): reset the pinned card height when the prompt changes - #16372

Merged
buluoray merged 2 commits into
mainfrom
fix/pinned-card-height-reset
Oct 3, 2026
Merged

buluoray merged 2 commits into
mainfrom
fix/pinned-card-height-reset

Conversation

@buluoray

@buluoray buluoray commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A text prompt that follows an image-only prompt pins once, at the right moment, instead of the pinned card flashing on and off.

usePinnedPrompt leaves a tall prompt unpinned while more of its bubble is left than the resting card height (#16321). That height is the last one a card reported, so it belongs to the previous prompt. An image-only card rests two lines tall; when the next candidate is a text prompt, the gate admits it too early, the card mounts, reports one line, the gate fails on the next frame and the card unmounts with no scroll in between.

Why it matters

Anyone who scrolls a chat with an image-only prompt followed by a longer text prompt sees the pinned card flicker at the hand-off. It looks broken and draws the eye to the wrong place.

Not a goal

What changed (motivation → approach → change)

  • Symptom: the pinned card mounts and unmounts on consecutive frames after an image-only prompt.
  • Root cause: the gate reads pinCollapsedHRef, which still holds the previous card's measured height.
  • Change: the hook remembers which prompt is the pin candidate and resets pinCollapsedHRef to DEFAULT_PINNED_CARD_H when it changes, until the new card reports. The candidate is keyed on its index and ts together, so transcripts whose messages carry no timestamp (ts is '') still reset. Both hosts pass the same identity (pinCandidateKey) to PinnedPrompt as promptKey, and its collapsed-height measure re-runs on it, so a card that stays mounted with unchanged text (older history prepended, one image-only prompt handing off to another) reports its height for the new prompt. website/docs/page-layout.md records that the resting height is per prompt.

Backwards compatibility

Compatible: only the height the gate reads for a newly pinned prompt changes; the API of usePinnedPrompt is unchanged.

Removes nothing: no field, key, prop or behavior is removed.

Tests

  • usePinnedPrompt.test.tsx › "gates a new prompt on the seed height, not the previous card's measured height": a card reports 90px, then a text prompt with 70px of bubble left must stay unpinned, and pins at the default height once one line is left. It fails with the reset disabled.
  • Same test, "…across a hand-off between prompts that carry no ts": runs the scenario with ts: '' on every message. It fails with a key on ts alone.
  • PinnedPrompt.promptKey.test.tsx: the card reports again when promptKey changes and the text does not, including a timestamp-less image-only hand-off, and does not report for a re-render with the same key. Two of its three tests fail with promptKey removed from the measure effect's deps.
  • The pinned-prompt and ChatPane suites (53 files, 562 tests), tsc and eslint pass.

Manual verification

N/A — unit coverage sufficient: the defect is a frame-level gate decision, and the test drives that exact frame sequence through the hook.

Screenshots / video

Why no screenshot: the fix removes a one-frame mount/unmount at a single hand-off; every settled frame renders exactly as on main, so a still image would look identical before and after.

Related Issues

Split out of #15984, which is closed in favor of #16321; this was its remaining live fix (raised in review there).

Pattern harvest

Rule candidate: review-prompt
Pattern: a cached measurement keyed to one entity (a card, a row) reused after the entity it describes has changed.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

The gate that leaves a tall prompt unpinned compares what is left of
the bubble against the last measured card height, which belongs to the
previous prompt. An image-only card is two lines tall, so a text
prompt after it could pin, re-measure at one line, fail the gate and
unpin with no scroll in between. The height now falls back to the
default whenever the pin candidate changes.
@buluoray
buluoray requested a review from a team October 3, 2026 03:37
@buluoray
buluoray requested a review from a team as a code owner October 3, 2026 03:37
@buluoray
buluoray requested a review from cruisercohen October 3, 2026 03:37
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a01a641594fda01fd22b60dc9cca91376901d825 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check that an expanded or peeking card across a promptKey change still reports its height. If it doesn't, the gate keeps using the default height under a taller card.

What this change ships

Inventory (5 items) — 5 justified

Intent: when a text prompt follows an image-only prompt, the pinned card should pin once instead of flickering. This is a FIX.

  1. A newly pinned prompt is gated on the default height, not on the height the previous card measured — justified
  2. A card that stays mounted re-measures when the pinned prompt's identity changes but its text doesn't (promptKey prop) — justified
  3. One shared pinCandidateKey(idx, ts) identity, used by the hook, ChatPage and ChatPane — justified
  4. Transcripts without timestamps still reset, because the index is part of the key — justified
  5. page-layout.md says the resting height belongs to each prompt — justified

[FIRST-PRINCIPLES-REVIEWED] a01a641

Description read

[DESCRIPTION-READ] cf02487890633f993d4179288eee45c1dce3872c4e8d10edad0c1fc41859b38b

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of a01a641594fda01fd22b60dc9cca91376901d825 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Check by hand that the pinned card no longer flickers when scrolling from an image-only prompt to a longer text prompt. No recording was supplied.

[UX-REVIEWED] a01a641

Description read

[DESCRIPTION-READ] ef2fc8e265b4f4e5e3744b4e849937185405257e51ae6c12da8100618ab88b1b

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of a01a641594fda01fd22b60dc9cca91376901d825 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check by hand that a text prompt followed by an image-only one doesn't jump for one frame when its card reports 90px over the reset seed height.

[DESIGN-REVIEWED] a01a641

Description read

[DESCRIPTION-READ] 8ddf096cb4e2bc0e24714da58be368ed762e44382d8dd6dd46571d8a6530fec4

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of a01a641594fda01fd22b60dc9cca91376901d825 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a01a641

False positive or not applicable? A repository writer can comment:
/ai-review override gpt a01a641594fda01fd22b60dc9cca91376901d825: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed a01a641594fda01fd22b60dc9cca91376901d825 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] a01a641

Verdict parsed from the review's SHA-scoped output markers for commit a01a641594fda01fd22b60dc9cca91376901d825.

False positive or not applicable? A repository writer can comment:
/ai-review override fable a01a641594fda01fd22b60dc9cca91376901d825: <one-sentence reason>

@buluoray

buluoray commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Design Review (CONCERNS on 5ee8801), empty ts candidate key: fixed in c9ae40a. Confirmed in source: ChatMessage.ts is a non-optional string, so the ?? idx fallback never fired and timestamp-less transcripts kept one key across every hand-off. The candidate is now keyed on index and ts together, the same identity the ResizeObserver effect uses. Added a timestamp-less variant of the seed-height test; it fails with the ts-only key.

The resting-height reset keys on a pin candidate's identity, its index
and ts together: a timestamp-less transcript (an import, a legacy log)
reads ts as '' for every prompt, so ts alone never changes across a
hand-off. The host also passes that identity to PinnedPrompt as
promptKey, and the card's collapsed-height measure re-runs on it, so a
card that stays mounted with the same text (older history prepended,
one image-only prompt handing off to another) reports its height for
the new identity instead of leaving the one-line seed under a taller
card.
@buluoray
buluoray force-pushed the fix/pinned-card-height-reset branch from c9ae40a to a01a641 Compare October 3, 2026 04:13
@buluoray

buluoray commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Design Review (CONCERNS on c9ae40a), reset without a new measurement: fixed in a01a641 (folded into the second commit to stay within two). Confirmed in source: <PinnedPrompt> has no React key in either host and its collapsed-height measure only re-ran on text/expanded/peek/folding, so a still-mounted card with unchanged text never re-reported after the reset. Both hosts now pass the candidate identity (pinCandidateKey, index + ts) as promptKey, and the measure effect re-runs on it. The card is not remounted, which keeps its glide and morph intact. New PinnedPrompt.promptKey.test.tsx covers the same-text hand-off and the timestamp-less image-only one; two of its three tests fail with promptKey removed from the effect's deps.

@buluoray
buluoray enabled auto-merge (squash) October 3, 2026 04:50
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 3, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Read-only review: the fix is sound on its own (keys on index + ts and the card re-reports via promptKey), but it repairs the #16321 gate that open revert #16342 removes, and the two collide in usePinnedPrompt.ts, PinnedPrompt.tsx, both hosts and page-layout.md. Please settle #16342 first: if the revert lands, close this; if the revert is dropped, this can merge as is.

@buluoray
buluoray merged commit fb00b98 into main Oct 3, 2026
99 of 105 checks passed
@buluoray
buluoray deleted the fix/pinned-card-height-reset branch October 3, 2026 17:02
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 3, 2026
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.

3 participants