Skip to content

fix: improve file preview fallback handling#472

Merged
wonderwhy-er merged 1 commit into
mainfrom
fix/ui-ux-improvements
May 14, 2026
Merged

fix: improve file preview fallback handling#472
wonderwhy-er merged 1 commit into
mainfrom
fix/ui-ux-improvements

Conversation

@edgarsskore
Copy link
Copy Markdown
Collaborator

@edgarsskore edgarsskore commented May 13, 2026

Summary

  • Keep file preview loading after refresh instead of falling back to an unavailable message.
  • Include returned file content in read_file structuredContent for preview consumers.
  • Render unsupported file payloads as escaped raw content when structured content is available.

Tests

  • npm run build
  • node test/test-markdown-preview.js
  • node test/test-file-handlers.js

Summary by CodeRabbit

Release Notes

  • New Features

    • File previews now display raw content for unsupported file types when available, instead of showing an unavailability message.
  • Bug Fixes

    • Improved preview reliability by removing artificial timeouts that previously marked previews as unavailable.
    • Enhanced text extraction from structured file previews across all file formats.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f3297522-914b-4191-ba2a-ca8e4cb0e018

📥 Commits

Reviewing files that changed from the base of the PR and between 5c30886 and ddbe8fc.

📒 Files selected for processing (7)
  • src/handlers/filesystem-handlers.ts
  • src/types.ts
  • src/ui/file-preview/src/app.ts
  • src/ui/file-preview/src/file-type-handlers.ts
  • src/ui/file-preview/src/payload-utils.ts
  • test/test-file-handlers.js
  • test/test-markdown-preview.js
💤 Files with no reviewable changes (1)
  • src/ui/file-preview/src/app.ts

📝 Walkthrough

Walkthrough

The PR integrates structured content field population across file handlers and UI layers. A new optional content: string field is added to the FilePreviewStructuredContent interface, populated differently for PDFs (newline-joined text), images (image data), and other files (text content). UI extraction and rendering logic now prefer this structured field over legacy extraction methods. Unsupported file handling becomes content-aware, enabling previews when raw content is available. App initialization is simplified by removing a timeout-based fallback.

Changes

File preview structured content integration

Layer / File(s) Summary
Data contract and handler implementations
src/types.ts, src/handlers/filesystem-handlers.ts, test/test-file-handlers.js
Added optional content?: string field to FilePreviewStructuredContent. Handlers populate it with PDF text (text entries joined by newlines), image data, or plain text. Tests validate the contract is fulfilled for all file types.
UI payload extraction and structured-content-first fallback
src/ui/file-preview/src/payload-utils.ts
New extractStructuredContentText helper extracts the content field from structured payloads. extractRenderPayload now prefers structured content over tool-extracted text in its fallback chain.
Unsupported file content-aware behavior and preview test
src/ui/file-preview/src/file-type-handlers.ts, test/test-markdown-preview.js
Unsupported handler determines preview and copy capabilities based on whether stripped content is non-empty; renders empty placeholder or escaped-content display. New test covers payload extraction, capability detection, and rendered output validation.
App initialization and host context setup
src/ui/file-preview/src/app.ts
Removed 8-second timeout fallback from host-connection handling. Directly initializes currentHostContext and seeds persisted payload state without intermediate unavailability markers.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size:L

Suggested reviewers

  • wonderwhy-er
  • scutuatua-crypto

Poem

🐰 A content field takes its place,
through handlers, PDFs, images with grace.
UI layers extract with care,
unsupported files now shine fair.
State flows pure, no timeout despair! 📄✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'fix: improve file preview fallback handling' directly summarizes the main objective: improving how file preview handles fallback scenarios (preventing unavailable messages on refresh and rendering unsupported content).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ui-ux-improvements

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@wonderwhy-er wonderwhy-er merged commit cf277c7 into main May 14, 2026
2 checks 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