Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/src/components/chat/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const MainContent = () => {
React.useEffect(() => {
if (
// on first response from AI
pathname === '/chat/new' &&
pathname === `/${aiState.group}/chat/new` &&
aiState.id !== '' // id is set only once the chat has been saved to the db
) {
// reloads the sidebar, which repulls from the db now that the chat has been saved
router.replace(`/${aiState.group}/chat/${aiState.id}`);
router.refresh();
window.history.pushState({}, '', `/chat/${aiState.id}`);
}
}, [aiState.messages, router, aiState.id, pathname]);
Comment on lines +28 to 35
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 | 🔴 Critical

Hardcoded group value and missing dependency will break navigation for non-ucdavis groups.

Two issues in this effect:

  1. Inconsistent group handling: Line 28 dynamically checks aiState.group, but line 33 hardcodes /ucdavis/ instead of using ${aiState.group}. This breaks navigation for any group other than "ucdavis".

  2. Missing dependency: aiState.group is used in the condition but not included in the dependency array, violating React's exhaustive-deps rule and potentially causing stale closure bugs.

🐛 Proposed fix
     if (
       // on first response from AI
       pathname === `/${aiState.group}/chat/new` &&
       aiState.id !== '' // id is set only once the chat has been saved to the db
     ) {
       // reloads the sidebar, which repulls from the db now that the chat has been saved
       router.refresh();
-      window.history.pushState({}, '', `/ucdavis/chat/${aiState.id}`); // change to group
+      window.history.pushState({}, '', `/${aiState.group}/chat/${aiState.id}`);
     }
-  }, [aiState.messages, router, aiState.id, pathname]);
+  }, [aiState.messages, router, aiState.id, aiState.group, pathname]);
📝 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
pathname === `/${aiState.group}/chat/new` &&
aiState.id !== '' // id is set only once the chat has been saved to the db
) {
// reloads the sidebar, which repulls from the db now that the chat has been saved
router.refresh();
window.history.pushState({}, '', `/chat/${aiState.id}`);
window.history.pushState({}, '', `/ucdavis/chat/${aiState.id}`); // change to group
}
}, [aiState.messages, router, aiState.id, pathname]);
pathname === `/${aiState.group}/chat/new` &&
aiState.id !== '' // id is set only once the chat has been saved to the db
) {
// reloads the sidebar, which repulls from the db now that the chat has been saved
router.refresh();
window.history.pushState({}, '', `/${aiState.group}/chat/${aiState.id}`);
}
}, [aiState.messages, router, aiState.id, aiState.group, pathname]);
🤖 Prompt for AI Agents
In `@web/src/components/chat/main.tsx` around lines 28 - 35, The effect uses
aiState.group in its condition but hardcodes "/ucdavis" in
window.history.pushState and omits aiState.group from the dependency array;
update the pushState target to use the dynamic group (use `${aiState.group}`)
and add aiState.group to the effect dependencies so the effect reacts to group
changes; keep the existing router.refresh() and aiState.id checks in the effect
(refer to aiState.group, aiState.id, aiState.messages, router.refresh, and
window.history.pushState).


Expand Down