Repository navigation
fix(chat): keep a reopened Markdown image at its final height - #2739
Conversation
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
|
Warning Review limit reachedYou'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. View limit details
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. |
… 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.
|
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 ( 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. |
|
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:
CodeRabbit: not waited on. Checks run: |
|
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). |
Fixes #2548
Change
Parts 1 and 2 of #2548 (the
/compactand/clearchips) 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 optionalsizeandrememberhooks on the resolver.src/components/Markdown.tsx: a standaloneMarkdownImagepasses that size toReservedImage, whose loading slot then takes the image's own box instead of 16:9;ReservedImagereports 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-sizedlays the slot out as.markdown-imagelays the decoded image out:min(100%, authored or natural width, height bound x ratio), the image's ratio, the same--chat-image-max-hbound.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 (whichlib/imageBox.tsalready 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.tshas 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:266.47 x5, then 127.09(16:9 slot, then the real height): fails.127.09in every frame: passes. Also checked by hand inside.chat-transcriptwith 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.bun run check full(the browser QA above is part of CI's browser job).