Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: adds safety guard to ag grid (#1946)

Mike Fortman0569c4c0bc3d
diff --git a/frontend/app/chat/page.tsx b/frontend/app/chat/page.tsx
index 3a0e43d62..dc89373cf 100644
--- a/frontend/app/chat/page.tsx
+++ b/frontend/app/chat/page.tsx
@@ -164,10 +164,11 @@ function ChatPage() {
});
// Show warning if waiting too long (20 seconds)
+ const hasStreamingMessage = !!streamingMessage;
useEffect(() => {
let timeoutId: NodeJS.Timeout | null = null;
- if (isChatStreaming && !streamingMessage) {
+ if (isChatStreaming && !hasStreamingMessage) {
timeoutId = setTimeout(() => {
setWaitingTooLong(true);
}, 20000); // 20 seconds
@@ -178,7 +179,7 @@ function ChatPage() {
return () => {
if (timeoutId) clearTimeout(timeoutId);
};
- }, [isChatStreaming, streamingMessage]);
+ }, [isChatStreaming, hasStreamingMessage]);
const handleEndpointChange = (newEndpoint: EndpointType) => {
setEndpoint(newEndpoint);
diff --git a/frontend/app/knowledge/page.tsx b/frontend/app/knowledge/page.tsx
index f70811f1d..e7c281e13 100644
--- a/frontend/app/knowledge/page.tsx
+++ b/frontend/app/knowledge/page.tsx
@@ -453,6 +453,20 @@ function SearchPage() {
const gridRows = fileResults;
const gridRef = useRef<AgGridReact>(null);
+ const gridReadyRef = useRef(false);
+
+ const handleGridReady = useCallback(() => {
+ gridReadyRef.current = true;
+ }, []);
+
+ const handleGridPreDestroyed = useCallback(() => {
+ gridReadyRef.current = false;
+ }, []);
+
+ const getGridApi = useCallback(() => {
+ if (!gridReadyRef.current) return null;
+ return gridRef.current?.api ?? null;
+ }, []);
// Re-run only when row identity/status changes, not on every list poll reference.
const gridRowsSelectionKey = useMemo(
@@ -466,7 +480,7 @@ function SearchPage() {
);
useEffect(() => {
- const api = gridRef.current?.api;
+ const api = getGridApi();
if (!api) {
return;
}
@@ -475,7 +489,7 @@ function SearchPage() {
setSelectedRows((current) =>
sameFileSelection(current, nextSelected) ? current : nextSelected,
);
- }, [gridRowsSelectionKey, isDeletableKnowledgeRow]);
+ }, [gridRowsSelectionKey, isDeletableKnowledgeRow, getGridApi]);
const columnDefs: ColDef<File>[] = [
{
@@ -745,17 +759,18 @@ function SearchPage() {
};
const onSelectionChanged = useCallback(() => {
- if (!gridRef.current) {
+ const api = getGridApi();
+ if (!api) {
return;
}
const nextSelected = syncGridSelectionToDeletableRows(
- gridRef.current.api,
+ api,
isDeletableKnowledgeRow,
);
setSelectedRows((current) =>
sameFileSelection(current, nextSelected) ? current : nextSelected,
);
- }, [isDeletableKnowledgeRow]);
+ }, [isDeletableKnowledgeRow, getGridApi]);
const handleBulkDelete = async () => {
const rowsToDelete = selectedRows.filter(isDeletableKnowledgeRow);
@@ -826,9 +841,7 @@ function SearchPage() {
setShowBulkDeleteDialog(false);
// Clear selection in the grid
- if (gridRef.current) {
- gridRef.current.api.deselectAll();
- }
+ getGridApi()?.deselectAll();
} catch (error) {
toast.error(
error instanceof Error
@@ -886,7 +899,7 @@ function SearchPage() {
onDelete={() => setShowBulkDeleteDialog(true)}
onCancel={() => {
setSelectedRows([]);
- gridRef.current?.api.deselectAll();
+ getGridApi()?.deselectAll();
}}
/>
</div>
@@ -1011,6 +1024,8 @@ function SearchPage() {
}
isRowSelectable={(params) => isDeletableKnowledgeRow(params.data)}
domLayout="normal"
+ onGridReady={handleGridReady}
+ onGridPreDestroyed={handleGridPreDestroyed}
onSelectionChanged={onSelectionChanged}
pagination={pagination}
paginationPageSize={paginationPageSize}
@@ -1045,6 +1060,8 @@ function SearchPage() {
}
isRowSelectable={(params) => isDeletableKnowledgeRow(params.data)}
domLayout="normal"
+ onGridReady={handleGridReady}
+ onGridPreDestroyed={handleGridPreDestroyed}
onSelectionChanged={onSelectionChanged}
pagination={pagination}
paginationPageSize={paginationPageSize}
diff --git a/frontend/components/AgGrid/registerAgGridModules.ts b/frontend/components/AgGrid/registerAgGridModules.ts
index 486a76ba7..00b6b1362 100644
--- a/frontend/components/AgGrid/registerAgGridModules.ts
+++ b/frontend/components/AgGrid/registerAgGridModules.ts
@@ -9,6 +9,7 @@ import {
ModuleRegistry,
PaginationModule,
QuickFilterModule,
+ RowApiModule,
RowSelectionModule,
TextFilterModule,
ValidationModule,
@@ -28,6 +29,7 @@ ModuleRegistry.registerModules([
DateFilterModule,
EventApiModule,
GridStateModule,
+ RowApiModule,
RowSelectionModule,
// The ValidationModule adds helpful console warnings/errors that can help identify bad configuration during development.
...(process.env.NODE_ENV !== "production" ? [ValidationModule] : []),