Skip to content

Fix Chat/Search/Agent bot show image - #16152

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/fix-chat-search-agent-bot-show-image
Jun 18, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/fix-chat-search-agent-bot-show-image

Conversation

@wangq8

@wangq8 wangq8 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Fix Chat/Search/Agent bot show image

@wangq8
wangq8 marked this pull request as ready for review June 17, 2026 10:04
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 17, 2026
@wangq8
wangq8 requested review from cike8899 and dcc123456 June 17, 2026 10:04
@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds buildDocumentImageUrl and useDocumentImageUrl to the image component. The hook fetches images as blobs with an auth header in shared contexts and manages object URL lifecycle via reference counting and delayed cleanup. ReferenceImageList is refactored to consume this hook via a new ImagePhotoView component, removing the direct restAPIv1 URL construction.

Changes

Authenticated Share-Aware Document Image URL

Layer / File(s) Summary
buildDocumentImageUrl and useDocumentImageUrl hook implementation
web/src/components/image/index.tsx
Removes the restAPIv1 import and adds auth/shared helpers and React hooks. Defines buildDocumentImageUrl (constructs the URL with optional _t). Implements internal fetchDocumentImage cache that deduplicates concurrent fetches, converts blobs to object URLs, and performs reference-counted delayed revocation. Implements useDocumentImageUrl (chooses between direct URL or authenticated blob fetching based on sharing token presence, manages lifecycle). Updates Image component to derive src from the hook result.
ImagePhotoView component and carousel wiring
web/src/components/next-message-item/reference-image-list.tsx
Imports useDocumentImageUrl alongside Image, removes the restAPIv1 import. Introduces the internal ImagePhotoView component that calls useDocumentImageUrl(id) to supply the PhotoView src, and replaces the inline carousel block with ImagePhotoView.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop hop, the image hath a token now,
No plaintext URL upon the bough!
A blob is fetched, an object URL born,
Then revoked at cleanup like dew by morn.
The carousel shines with ImagePhotoView,
Sharing secrets safe — hooray, it's true! 🖼️

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is essentially identical to the title and provides no substantive detail about the problem, solution, or type of change as required by the template. Complete the description template by explaining the specific image display issue, selecting the appropriate change type (Bug Fix), and detailing how the centralized image URL construction and auth-aware blob loading fix the problem.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: fixing image display in Chat/Search/Agent bot features, which aligns with the core modifications to image URL handling.
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.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 70f319c and a96e815.

📒 Files selected for processing (2)
  • web/src/components/image/index.tsx
  • web/src/components/next-message-item/reference-image-list.tsx

Comment thread web/src/components/image/index.tsx Resolved
{...props}
src={`${restAPIv1}/documents/images/${id}${t ? `?_t=${t}` : ''}`}
src={src || undefined}
className={classNames('max-w-[45vw] max-h-[40wh] block', className)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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.

Comment on lines +37 to +49
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>
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a96e815 and bd3c0e8.

📒 Files selected for processing (1)
  • web/src/components/image/index.tsx

Comment on lines +57 to +59
.then((blob) => {
item.objectUrl = URL.createObjectURL(blob);
return item.objectUrl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Comment thread web/src/components/image/index.tsx Outdated
let objectUrl = '';
let ignore = false;
setImageUrl('');
fetch(directUrl, { headers: { [Authorization]: authorization } })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to use async/await to reduce the amount of code.

@wangq8
wangq8 merged commit 99a25dc into infiniflow:main Jun 18, 2026
2 checks passed
@asiroliu

asiroliu commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator
image

@asiroliu

asiroliu commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator
image

@asiroliu

asiroliu commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants