Repository navigation
fix: refresh memory sidebar avatar immediately after update - #17401
Conversation
The memory detail sidebar reads its data via the fetchMemoryDetail query key (GET /memories/:id/config), but useUpdateMemory only invalidated the unrelated memoryDetail key on success, so the new avatar was not shown until a full page refresh. Invalidate the fetchMemoryDetail query as well and drop a stale comment.
📝 WalkthroughWalkthroughThe memory update hook now invalidates detail queries through ChangesMemory cache invalidation
Sidebar cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes 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: 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/pages/memories/hooks.ts`:
- Around line 221-223: Define a same-file MemoryKeys query-key factory with as
const return values, following the existing query and invalidation key patterns,
then update the invalidateQueries call to use the factory instead of the inline
[MemoryApiAction.FetchMemoryDetail] key.
🪄 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 Plus
Run ID: 7e93976d-2cf7-4b1f-bb8c-b6e1cb0a8053
📒 Files selected for processing (2)
web/src/pages/memories/hooks.tsweb/src/pages/memory/sidebar/index.tsx
💤 Files with no reviewable changes (1)
- web/src/pages/memory/sidebar/index.tsx
| queryClient.invalidateQueries({ | ||
| queryKey: [MemoryApiAction.FetchMemoryDetail], | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use the required query-key factory.
This invalidation is functionally correct, but it introduces another inline React Query key. Define a same-file MemoryKeys factory with as const return values and use it here, alongside the file’s other query and invalidation calls.
As per coding guidelines, React Query keys in web/src/**/*.{ts,tsx} must use a same-file {Domain}Keys factory with as const.
Suggested change
+const MemoryKeys = {
+ fetchMemoryDetail: () => [MemoryApiAction.FetchMemoryDetail] as const,
+};
+
queryClient.invalidateQueries({
- queryKey: [MemoryApiAction.FetchMemoryDetail],
+ queryKey: MemoryKeys.fetchMemoryDetail(),
});📝 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.
| queryClient.invalidateQueries({ | |
| queryKey: [MemoryApiAction.FetchMemoryDetail], | |
| }); | |
| const MemoryKeys = { | |
| fetchMemoryDetail: () => [MemoryApiAction.FetchMemoryDetail] as const, | |
| }; | |
| queryClient.invalidateQueries({ | |
| queryKey: MemoryKeys.fetchMemoryDetail(), | |
| }); |
🤖 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/memories/hooks.ts` around lines 221 - 223, Define a same-file
MemoryKeys query-key factory with as const return values, following the existing
query and invalidation key patterns, then update the invalidateQueries call to
use the factory instead of the inline [MemoryApiAction.FetchMemoryDetail] key.
Source: Coding guidelines
wangq8
left a comment
There was a problem hiding this comment.
Simple, correct fix. The react-query key mismatch (memoryDetail vs fetchMemoryDetail) is a textbook stale-cache bug — invalidating the correct key resolves it cleanly.
Also good housekeeping: removing the stale refreshCount comment in the sidebar component.
Approved.
Summary
After uploading a new avatar on the memory configuration page and saving, the avatar shown in the memory detail sidebar was not updated until a full page refresh.
Root cause: a react-query key mismatch. The sidebar and the configuration page read data via
useFetchMemoryBaseConfiguration, whose query key is['fetchMemoryDetail', ...](GET /api/v1/memories/:id/config), butuseUpdateMemoryonly invalidated the unrelated['memoryDetail', id]key on success. As a result, the sidebar's cached query was never refetched after an update.This PR additionally invalidates the
fetchMemoryDetailquery key inuseUpdateMemory'sonSuccess, so the sidebar refetches and shows the new avatar immediately. It also removes a stale comment in the sidebar referring to an unimplementedrefreshCountmechanism.