Skip to content

fix(chat): keep a reopened Markdown image at its final height - #2739

Merged
devswha merged 2 commits into
mainfrom
fix/chat-reopened-image-height
Nov 4, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/chat-reopened-image-height

Conversation

@devswha

@devswha devswha commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2548

Change

Parts 1 and 2 of #2548 (the /compact and /clear chips) were fixed by #2549. This PR fixes part 3: a reopened chat redrew each standalone Markdown image from the lane-wide 16:9 loading slot, then the stat and the new download moved everything below it to the image's real height.

  • src/components/ChatMarkdownImages.tsx: the chat's image resolver remembers the natural size each image decoded at, per PC, pane and source (bounded, 500), through optional size and remember hooks on the resolver.
  • src/components/Markdown.tsx: a standalone MarkdownImage passes that size to ReservedImage, whose loading slot then takes the image's own box instead of 16:9; ReservedImage reports the natural size once decoded (onDecoded). Nothing else is reused: no bytes load and the viewer cannot open until the new stat answers and passes the same size and type checks as before.
  • src/components/ChatView.css: .image-slot.is-loading.is-sized lays the slot out as .markdown-image lays the decoded image out: min(100%, authored or natural width, height bound x ratio), the image's ratio, the same --chat-image-max-h bound.

Chat thumbnails, tool images and file previews (no size) are unchanged. The settled look is unchanged; only the loading box of an image seen before differs. Design: as in t3code's ChatMarkdown (which lib/imageBox.ts already follows), the box is reserved before the bytes arrive; this reserves the known size instead of a generic ratio.

Reproduction (origin/main 9390fa1)

scripts/chat-markdown-images-browser-qa.ts has a new case: a standalone image decodes, the answer is mounted again (as a reopen or a row scrolling back in), and the stat and bytes answer only after five frames of the new mount. The top of the paragraph below the image, by frame:

  • main: 266.47 x5, then 127.09 (16:9 slot, then the real height): fails.
  • this branch: 127.09 in every frame: passes. Also checked by hand inside .chat-transcript with a 240x3000 image at 1280x800 (height bound hit): slot and decoded image are both 45x560 CSS px (0.05 px sub-pixel difference in the text below).

Validation

  • bun run check fast: green (typecheck, build, unit 11046 pass / 0 fail).
  • bun scripts/chat-markdown-images-browser-qa.ts: 5/5 PASS; the new case fails on main.
  • bun test src/components/ChatMarkdownImages.test.ts: 17 pass; the new test (a remount holds the remembered box, loads no bytes before the new stat, stats once; another pane does not share it) fails on main.
  • Skipped: bun run check full (the browser QA above is part of CI's browser job).

A reopened chat drew each standalone Markdown image from the 16:9 loading slot until a new stat and download came back. Remember resolved previews per PC, pane and source, and decoded sizes per address, so the image holds its final box from the first frame while the stat checks it again.

Fixes #2548
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4331eb8 and 95a53a7.

Files selected for processing: 7
  • changelog.d/chat-reopened-image-height.md
  • scripts/chat-markdown-images-browser-qa.ts
  • scripts/chat-markdown-images-fixture.tsx
  • src/components/ChatMarkdownImages.test.ts
  • src/components/ChatMarkdownImages.tsx
  • src/components/ChatView.css
  • src/components/Markdown.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

… the stat

Review round 1: reusing the cached preview URL loaded bytes before the new stat (stale foreground cwd, inline size limit skipped, a byte failure lost to reconnect). Remember only the decoded size per PC, pane and source; the slot also narrows where the height bound stops the image.
@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Review round 1 (omo + Codex Terra on 1fe621c): no HIGH. Both found the same three reproduced MEDIUMs, all caused by reusing the cached preview URL before the new stat: (1) a relative image could show the previous foreground directory's file, (2) bytes could load before the 20 MiB / type check, (3) a byte failure during the re-stat was lost, so reconnect would not retry it.

Fixed in this push by caching only the decoded size (per PC, pane and source). The reopened slot takes that box, but nothing loads and the viewer cannot open until the new stat passes, as on main. Codex's LOW about the slot width under the height bound is also fixed (height bound x ratio in the width), and the browser QA frame loop now stops after 600 frames. The QA also no longer reopens before load fires (complete is set one task earlier).

Not fixed (LOW): a file rewritten at the same path with new dimensions gets the old box, then moves once, which is no worse than main. The bounded size cache is not cleared when a PC is removed.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Review round 2 at 95a53a7: omo CLEAR (no HIGH or MEDIUM). Codex Terra: no HIGH. Its items are left as follow-up notes, since none is a regression from main:

  • A relative image whose pane changed foreground directory between reopens briefly gets the old file's box, then moves once (main always moves). The cwd prop is not a reliable key (the server prefers the foreground cwd, and the prop can arrive after the first frame), so a key change could bring the 16:9 jump back.
  • An image with an authored <img width> that hits the chat's height bound: the loading box is narrower than the decoded image's box. The heights match, so nothing below moves; only the width changes on decode.
  • The new browser QA frame loop returns after 600 frames without failing explicitly when the reopened image never settles. Codex rated it MEDIUM as a test-strength issue and omo rated it LOW. Today a never-settling regression would still fail through the stats or position assertions in most cases.

CodeRabbit: not waited on. Checks run: bun run check fast green at 95a53a7 (unit 11046 pass, 0 fail); bun scripts/chat-markdown-images-browser-qa.ts 5/5, with the new case failing against main's src.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Merge note: merged on the omo review (CLEAR at this head), Codex Terra (no HIGH; reproduced findings fixed, the rest listed in the PR comments) and green checks. CodeRabbit did not review this head (rate-limited or skipped).

@devswha
devswha merged commit 4fd51f8 into main Nov 4, 2026
16 checks passed
@devswha
devswha deleted the fix/chat-reopened-image-height branch November 4, 2026 14:29
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.

fix(chat): /compact reads "Done" while it runs, shows again after /clear, and reopened images jump

1 participant