Repository navigation
feat(frontend): add AuthenticatedImg component for authorized image requests - #16525
Conversation
…equests - Add AuthenticatedImg component in image/index.tsx to handle images requiring Authorization headers - Update file-icon component to use AuthenticatedImg for document thumbnails - Update markdown-content components to use AuthenticatedImg for file thumbnails - Improve error handling in document-preview hooks (try-catch for network errors, proper binary/JSON response detection) - Simplify PDF previewer rendering conditions
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds authenticated blob-URL loading for image thumbnails, applies it to file icon and markdown/reference previews, and updates document preview error handling plus PDF preview rendering. ChangesAuthenticated Image Rendering
Document Preview Fixes
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/components/file-icon/index.tsx`:
- Around line 5-7: The file icon component is reimplementing authenticated image
URL handling and dropping the cleanup from the effect, so object URLs are never
revoked. Update the component to use the shared useAuthenticatedImageUrl hook
instead of inline auth/file-fetch logic in FileIcon, or extract that hook into
src/hooks/ if it is not already shared. Keep FileIcon lean and ensure URL
creation/revocation is handled by the hook.
In `@web/src/components/image/index.tsx`:
- Around line 171-179: AuthenticatedImg currently returns null when
useAuthenticatedImageUrl(src) yields no usable URL, which leaves protected
thumbnails blank because callers treat fileThumbnail as truthy and skip their
SvgIcon fallback. Update AuthenticatedImg (and the thumbnail branch that
consumes it) to expose a fallback path for failed/empty authenticated image
loading, so a broken blob URL can still render the existing icon/placeholder
instead of rendering nothing.
- Around line 86-88: The auth check in isAuthRequiredUrl is too broad because it
marks any URL containing /documents/images/ as authenticated, even cross-origin
URLs. Update the logic in isAuthRequiredUrl to require same-origin before
returning true for image/document URLs, so getAuthorization() is only used for
requests to the app’s own API or same-origin image endpoints. Keep the /api/v1/
handling, but gate the /documents/images/ case behind an origin check using the
URL parsing logic already available in this component.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c055f04a-b92f-4f30-9352-561298aa4974
📒 Files selected for processing (8)
web/src/components/document-preview/hooks.tsweb/src/components/document-preview/index.tsxweb/src/components/file-icon/index.tsxweb/src/components/floating-chat-widget-markdown.tsxweb/src/components/image/index.tsxweb/src/components/markdown-content/index.tsxweb/src/components/next-markdown-content/index.tsxweb/src/pages/next-search/markdown-content/index.tsx
- Security: Add same-origin check in isAuthRequiredUrl to prevent token leakage - Fix memory leak: Refactor file-icon to use shared useAuthenticatedImageUrl hook instead of reimplementing auth fetch logic without proper cleanup - UX: Add fallback prop to AuthenticatedImg for degraded UI on load failure
- Remove unused 'getSearchValue' import from image/index.tsx - Suppress no-console warning in document-preview hooks.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16525 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
This PR enhances the frontend image and document preview components with authenticated image request support.
Background: File thumbnails and certain image resources require Authorization headers to be fetched from protected API endpoints. Previously, these resources would fail to load due to missing authentication.
Changes
Add
AuthenticatedImgcomponent (web/src/components/image/index.tsx)Authorizationheader when fetching imagesUpdate file-icon component (
web/src/components/file-icon/index.tsx)<img>with<AuthenticatedImg>for document thumbnailsUpdate markdown-content components (3 files)
<AuthenticatedImg>for file thumbnails in:web/src/components/markdown-content/index.tsxweb/src/components/next-markdown-content/index.tsxweb/src/pages/next-search/markdown-content/index.tsxImprove error handling (
web/src/components/document-preview/hooks.ts)Simplify PDF previewer (
web/src/components/document-preview/index.tsx)Test plan