fix/rendering issues for text based files on chat preview and toggle for .md files#373
Merged
Merged
Conversation
…ggle for .md files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.md(or any URL-backed text) attachment in chat entered a perpetual loading state, with the Network tab showing an endless cascade of aborted/retried requests.Root cause
AttachmentPreviewModal'skind = classify(attachment)returned a new object on every render instead of being memoized. The text-loadinguseEffectdepended onkind, so its ownsetTextLoading/setTextContentcalls triggered a re-render, which produced a newkindreference, which re-fired the effect — aborting and re-issuing the samefetchin an infinite loop. This wasn'tSummary
.md(or any URL-backed text) attachment in chat entered a perpetual loading state, with the Network tab showing an endless cascade of aborted/retried requests.Root cause
AttachmentPreviewModal'skind = classify(attachment)returned a new object on every render instead of being memoized. The text-loadinguseEffectdepended onkind, so its ownsetTextLoading/setTextContentcalls triggered a re-render, which produced a newkindreference, which re-fired the effect — aborting and re-issuing the samefetchin an infinite loop. This wasn't.md-specific; it affected any URL-backed text-classified attachment (agent-generated attachments never carry inline base64content).Fix: memoize
kindwithuseMemo(() => ..., [attachment]), matching the pattern already used forimageSrc/pdfBlobUrlin the same file.Feature
classify()now also flagsisMarkdown(.mdfiles only).MarkdownContent/react-markdownpipeline used in chat bubbles), with a Source tab to see raw text..md; other text types (.json,.csv, etc.) are unchanged.Test plan
npx tsc --noEmit— no new errors introduced (pre-existing CSS-module resolution gap in this project is unrelated, confirmed present before this change too).mdfile via chat, click to open — preview loads once (no repeated network requests), toggle to Source and back works, non-.md text attachments still preview as raw text.Closes #369