Fixed an issue where cited webpages could not be opened during online searches. - #16840
Conversation
📝 WalkthroughWalkthroughChangesDocument URL preview
Estimated code review effort: 2 (Simple) | ~10 minutes 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
web/src/components/next-message-item/reference-document-list.tsx (1)
24-32: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winRemove commented-out code.
Per coding guidelines, commented-out code should be removed. The
NewDocumentLinkJSX block at lines 24-32 is dead code.♻️ Proposed cleanup
<FileIcon id={item.doc_id} name={item.doc_name}></FileIcon> - {/* <NewDocumentLink - documentId={item.doc_id} - documentName={item.doc_name} - prefix="document" - link={item.url} - className="text-text-sub-title-invert" - > - {middleEllipsis(item.doc_name)} - </NewDocumentLink> */} <div className="text-text-sub-title-invert">As per coding guidelines: "Remove dead tests, commented-out code, stale documentation, and 'move later' notes."
🤖 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-document-list.tsx` around lines 24 - 32, Remove the commented-out NewDocumentLink JSX block from the reference document list, leaving the surrounding component structure unchanged.Source: Coding guidelines
🤖 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/pages/next-search/document-preview-modal/index.tsx`:
- Around line 38-39: Remove the commented-out useRef and useState declarations
near the document preview modal implementation, leaving the surrounding active
code unchanged.
- Around line 15-22: Replace the chunk type’s broad [key: string]: any index
signature with a dedicated PreviewChunk interface containing the currently
supported fields, and add document_url explicitly with its appropriate type.
Update the document-preview modal to use PreviewChunk so accesses such as
document_url remain type-safe without accepting arbitrary properties.
- Around line 42-43: Update the isWebPage calculation in the document preview
URL selection to detect web pages from the chunk’s explicit web-page
discriminator, such as doc_type, or directly from document_url presence, rather
than requiring fileType to be empty. Preserve getDocumentUrl() for non-web
documents and use document_url for web pages regardless of dots in their titles.
---
Outside diff comments:
In `@web/src/components/next-message-item/reference-document-list.tsx`:
- Around line 24-32: Remove the commented-out NewDocumentLink JSX block from the
reference document list, leaving the surrounding component structure unchanged.
🪄 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: 81bd8d29-0313-465f-b611-c91491ba4d99
📒 Files selected for processing (3)
web/src/components/next-message-item/reference-document-list.tsxweb/src/interfaces/database/dataset.tsweb/src/pages/next-search/document-preview-modal/index.tsx
| chunk: { | ||
| docnm_kwd?: string; | ||
| document_name?: string; | ||
| positions?: number[][]; | ||
| content_with_weight?: string; | ||
| content?: string | null; | ||
| [key: string]: any; | ||
| }; |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add document_url explicitly and avoid [key: string]: any index signature.
The catch-all [key: string]: any weakens type safety — any property access compiles without error, masking bugs. Since document_url is accessed at lines 42-43, it should be explicitly declared. Consider defining a dedicated PreviewChunk interface instead of relying on an index signature.
♻️ Proposed type improvement
chunk: {
docnm_kwd?: string;
document_name?: string;
+ document_url?: string;
positions?: number[][];
content_with_weight?: string;
content?: string | null;
- [key: string]: any;
};As per coding guidelines: "Reduce public surface area when a helper can be made private or internal." The index signature expands the accepted type surface unnecessarily.
📝 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.
| chunk: { | |
| docnm_kwd?: string; | |
| document_name?: string; | |
| positions?: number[][]; | |
| content_with_weight?: string; | |
| content?: string | null; | |
| [key: string]: any; | |
| }; | |
| chunk: { | |
| docnm_kwd?: string; | |
| document_name?: string; | |
| document_url?: string; | |
| positions?: number[][]; | |
| content_with_weight?: string; | |
| content?: string | null; | |
| }; |
🤖 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/pages/next-search/document-preview-modal/index.tsx` around lines 15 -
22, Replace the chunk type’s broad [key: string]: any index signature with a
dedicated PreviewChunk interface containing the currently supported fields, and
add document_url explicitly with its appropriate type. Update the
document-preview modal to use PreviewChunk so accesses such as document_url
remain type-safe without accepting arbitrary properties.
Source: Coding guidelines
| // const ref = useRef<(highlight: IHighlight) => void>(() => {}); | ||
| // const [loaded, setLoaded] = useState(false); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Remove commented-out code.
Per coding guidelines, commented-out code should be removed. These useRef and useState lines are dead code.
♻️ Proposed cleanup
- // const ref = useRef<(highlight: IHighlight) => void>(() => {});
- // const [loaded, setLoaded] = useState(false);
const documentName = chunk.docnm_kwd || chunk.document_name;As per coding guidelines: "Remove dead tests, commented-out code, stale documentation, and 'move later' notes."
📝 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.
| // const ref = useRef<(highlight: IHighlight) => void>(() => {}); | |
| // const [loaded, setLoaded] = useState(false); | |
| const documentName = chunk.docnm_kwd || chunk.document_name; |
🤖 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/pages/next-search/document-preview-modal/index.tsx` around lines 38 -
39, Remove the commented-out useRef and useState declarations near the document
preview modal implementation, leaving the surrounding active code unchanged.
Source: Coding guidelines
| const isWebPage = !fileType && !!chunk.document_url; | ||
| const url = isWebPage ? (chunk.document_url as string) : getDocumentUrl(); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
isWebPage heuristic fails for web page titles containing dots.
getFileExtensionRegex extracts text after the last dot, so a web page title like "Welcome to Example.com" yields fileType = "com", making isWebPage false. This prevents the external link from rendering and falls back to getDocumentUrl(), which won't work for web pages — the exact bug this PR aims to fix.
Consider a more robust check, such as explicitly marking web pages via a doc_type field or checking document_url presence directly rather than inferring from filename extensions.
🐛 Proposed fix: prefer explicit web-page detection
- const fileType = documentName ? getFileExtensionRegex(documentName) : '';
- const isWebPage = !fileType && !!chunk.document_url;
- const url = isWebPage ? (chunk.document_url as string) : getDocumentUrl();
+ const fileType = documentName ? getFileExtensionRegex(documentName) : '';
+ const isWebPage = !!chunk.document_url && !fileType;
+ const url = isWebPage ? (chunk.document_url as string) : getDocumentUrl();Alternatively, if a doc_type or similar discriminator is available on the chunk, use that instead of the extension heuristic:
- const isWebPage = !fileType && !!chunk.document_url;
+ const isWebPage = chunk.doc_type_kwd === 'webpage' || (!fileType && !!chunk.document_url);🤖 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/pages/next-search/document-preview-modal/index.tsx` around lines 42 -
43, Update the isWebPage calculation in the document preview URL selection to
detect web pages from the chunk’s explicit web-page discriminator, such as
doc_type, or directly from document_url presence, rather than requiring fileType
to be empty. Preserve getDocumentUrl() for non-web documents and use
document_url for web pages regardless of dots in their titles.
Summary
Fixed an issue where cited webpages could not be opened during online searches.