Skip to content

fix/rendering issues for text based files on chat preview and toggle for .md files#373

Merged
CraftOS-dev merged 1 commit into
V1.4.1from
fix/chat-preview-text-based-files
Jul 10, 2026
Merged

fix/rendering issues for text based files on chat preview and toggle for .md files#373
CraftOS-dev merged 1 commit into
V1.4.1from
fix/chat-preview-text-based-files

Conversation

@AlanAAG

@AlanAAG AlanAAG commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Clicking a generated .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.
  • Adds a Preview/Source toggle for markdown attachments so users can view rendered markdown or raw text.

Root cause

AttachmentPreviewModal's kind = classify(attachment) returned a new object on every render instead of being memoized. The text-loading useEffect depended on kind, so its own setTextLoading/setTextContent calls triggered a re-render, which produced a new kind reference, which re-fired the effect — aborting and re-issuing the same fetch in an infinite loop. This wasn't

Summary

  • Clicking a generated .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.
  • Adds a Preview/Source toggle for markdown attachments so users can view rendered markdown or raw text.

Root cause

AttachmentPreviewModal's kind = classify(attachment) returned a new object on every render instead of being memoized. The text-loading useEffect depended on kind, so its own setTextLoading/setTextContent calls triggered a re-render, which produced a new kind reference, which re-fired the effect — aborting and re-issuing the same fetch in an infinite loop. This wasn't .md-specific; it affected any URL-backed text-classified attachment (agent-generated attachments never carry inline base64 content).

Fix: memoize kind with useMemo(() => ..., [attachment]), matching the pattern already used for imageSrc/pdfBlobUrl in the same file.

Feature

  • classify() now also flags isMarkdown (.md files only).
  • Markdown attachments default to a rendered Preview (reusing the existing MarkdownContent/react-markdown pipeline used in chat bubbles), with a Source tab to see raw text.
  • Toggle only appears for .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)
  • Manually verify in the app: generate a .md file 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

@AlanAAG AlanAAG requested review from Copilot and zfoong and removed request for Copilot July 7, 2026 19:33
@CraftOS-dev CraftOS-dev merged commit b51698f into V1.4.1 Jul 10, 2026
1 check passed
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.

2 participants