Repository navigation
Fix Chat/Search/Agent bot show image - #16152
Conversation
📝 WalkthroughWalkthroughAdds ChangesAuthenticated Share-Aware Document Image URL
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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/image/index.tsx`:
- Line 77: In the className string within the classNames function call, fix the
invalid CSS unit from `40wh` to `40vh` in the max-h-[40wh] class. The unit `wh`
is not valid CSS; it should be `vh` to properly represent viewport height units.
- Around line 26-69: The useDocumentImageUrl hook has two issues to fix. First,
remove the line that sets imageUrl to an empty string before the fetch starts
(the setImageUrl('') call that happens before the fetch) to prevent the image
from briefly disappearing during loading. Second, in the catch block of the
fetch error handler, instead of setting imageUrl to an empty string when the
authenticated fetch fails, set it to directUrl as a fallback so users can still
see the unauthenticated version of the image rather than a broken image
placeholder.
In `@web/src/components/next-message-item/reference-image-list.tsx`:
- Around line 37-49: The ImagePhotoView component is calling useDocumentImageUrl
to get the src, but then passes the id to the Image component which calls the
same hook again internally, resulting in duplicate fetches. Modify the Image
component to accept an optional src prop parameter that takes precedence over
the internal hook call in image/index.tsx, then update ImagePhotoView to pass
the resolved src value from useDocumentImageUrl directly to the Image component
along with the id, so the hook is only called once and the Image component uses
the provided src when available.
🪄 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: 2d05d471-6f14-422c-a4e1-1d7f043cbbf0
📒 Files selected for processing (2)
web/src/components/image/index.tsxweb/src/components/next-message-item/reference-image-list.tsx
| {...props} | ||
| src={`${restAPIv1}/documents/images/${id}${t ? `?_t=${t}` : ''}`} | ||
| src={src || undefined} | ||
| className={classNames('max-w-[45vw] max-h-[40wh] block', className)} |
There was a problem hiding this comment.
Typo in CSS unit: 40wh should be 40vh.
The class max-h-[40wh] uses an invalid CSS unit. It should be max-h-[40vh] for viewport height.
Proposed fix
- className={classNames('max-w-[45vw] max-h-[40wh] block', className)}
+ className={classNames('max-w-[45vw] max-h-[40vh] block', className)}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| className={classNames('max-w-[45vw] max-h-[40wh] block', className)} | |
| className={classNames('max-w-[45vw] max-h-[40vh] block', className)} |
🤖 Prompt for 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.
In `@web/src/components/image/index.tsx` at line 77, In the className string
within the classNames function call, fix the invalid CSS unit from `40wh` to
`40vh` in the max-h-[40wh] class. The unit `wh` is not valid CSS; it should be
`vh` to properly represent viewport height units.
| function ImagePhotoView({ id, index }: ImageItem) { | ||
| const src = useDocumentImageUrl(id); | ||
|
|
||
| return ( | ||
| <PhotoView src={src}> | ||
| <Image | ||
| id={id} | ||
| className="h-40 w-full" | ||
| label={`Fig. ${(index + 1).toString()}`} | ||
| /> | ||
| </PhotoView> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Double fetch: hook is called twice for each image.
ImagePhotoView calls useDocumentImageUrl(id) on line 38, then passes id to Image which internally calls the same hook again (line 72 of image/index.tsx). This results in:
- Two network requests per image in shared contexts
- Two separate object URLs created and managed
- Doubled memory usage for blob storage
Consider refactoring Image to accept an optional src prop that bypasses the internal hook, or lift the hook call to ImagePhotoView and pass the resolved URL to both consumers.
Proposed approach
Option 1 - Modify Image to accept optional src override:
// In image/index.tsx
const Image = ({ id, t, label, className, src: srcProp, ...props }: IImage) => {
const hookSrc = useDocumentImageUrl(id, t);
const src = srcProp ?? hookSrc;
// ...rest of component
};Then in ImagePhotoView:
function ImagePhotoView({ id, index }: ImageItem) {
const src = useDocumentImageUrl(id);
return (
<PhotoView src={src}>
<Image
id={id}
+ src={src}
className="h-40 w-full"
label={`Fig. ${(index + 1).toString()}`}
/>
</PhotoView>
);
}🤖 Prompt for 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.
In `@web/src/components/next-message-item/reference-image-list.tsx` around lines
37 - 49, The ImagePhotoView component is calling useDocumentImageUrl to get the
src, but then passes the id to the Image component which calls the same hook
again internally, resulting in duplicate fetches. Modify the Image component to
accept an optional src prop parameter that takes precedence over the internal
hook call in image/index.tsx, then update ImagePhotoView to pass the resolved
src value from useDocumentImageUrl directly to the Image component along with
the id, so the hook is only called once and the Image component uses the
provided src when available.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/image/index.tsx`:
- Around line 57-59: The fetch promise can resolve after the cache entry has
been cleaned up by the 30-second timer, causing a blob URL to be created and
assigned to item.objectUrl but never revoked. Before creating and assigning the
blob URL in the .then block that receives the blob parameter, verify that the
item still exists in the cache. Only proceed with URL.createObjectURL(blob) and
assigning to item.objectUrl if the cache entry is still valid, otherwise skip
the assignment to prevent orphaned blob URLs. Apply this fix to both locations
where blob URLs are created from fetch responses.
🪄 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: c6f1a552-adc5-445d-89f9-e81ff96f9c37
📒 Files selected for processing (1)
web/src/components/image/index.tsx
| .then((blob) => { | ||
| item.objectUrl = URL.createObjectURL(blob); | ||
| return item.objectUrl; |
There was a problem hiding this comment.
Handle in-flight fetch cleanup before the blob URL exists.
If all consumers release before a slow fetch resolves, the 30s timer can delete the cache while objectUrl is still unset. When the promise later resolves, Line 58 creates a blob URL that is never revoked.
Proposed fix
item.timer = setTimeout(() => {
if (item.count <= 0) {
if (item.objectUrl) {
URL.revokeObjectURL(item.objectUrl);
+ } else {
+ item.promise
+ ?.then((objectUrl) => {
+ URL.revokeObjectURL(objectUrl);
+ })
+ .catch(() => undefined);
}
imageCache.delete(cacheKey);
}
}, 30000);Also applies to: 72-77
🤖 Prompt for 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.
In `@web/src/components/image/index.tsx` around lines 57 - 59, The fetch promise
can resolve after the cache entry has been cleaned up by the 30-second timer,
causing a blob URL to be created and assigned to item.objectUrl but never
revoked. Before creating and assigning the blob URL in the .then block that
receives the blob parameter, verify that the item still exists in the cache.
Only proceed with URL.createObjectURL(blob) and assigning to item.objectUrl if
the cache entry is still valid, otherwise skip the assignment to prevent
orphaned blob URLs. Apply this fix to both locations where blob URLs are created
from fetch responses.
| let objectUrl = ''; | ||
| let ignore = false; | ||
| setImageUrl(''); | ||
| fetch(directUrl, { headers: { [Authorization]: authorization } }) |
There was a problem hiding this comment.
It is recommended to use async/await to reduce the amount of code.



Fix Chat/Search/Agent bot show image