Conversation
The document rename modal was using plain mutate() calls which only
trigger revalidation (refetch), causing the old name to briefly
reappear. Additionally, the sidebar tree cache key was wrong
('?tree=true' instead of no param / '?include_documents=true'),
so the sidebar never refreshed after a rename.
Changes:
- Replace revalidation-only mutate() calls with populateCache to
optimistically update cached document names in-place
- Fix sidebar tree SWR key mismatch (was '?tree=true', now correctly
targets both '...folders' and '...folders?include_documents=true')
- Update all four relevant SWR caches: root documents, folder
documents, sidebar tree (no params), sidebar tree (include_documents)
- Add recursive updateDocNameInFolderTree helper to handle nested
folder structures in the sidebar tree cache
Co-authored-by: Marc Seitz <mfts@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughModified the edit-dataroom-document-modal component to add helper functions for updating document names across in-memory data structures, introduced local state-derived values, parameterized API endpoints with computed identifiers, and enhanced SWR cache invalidation using targeted mutate calls with populateCache strategy. Changes
Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
components/datarooms/edit-dataroom-document-modal.tsx (2)
97-105:⚠️ Potential issue | 🟡 MinorValidate the trimmed name before submitting.
A whitespace-only value passes
safeParse({ name })and then becomes""at Line 104, so the client skips local validation and only fails after the network round-trip.Suggested fix
- const validation = editDocumentNameSchema.safeParse({ name }); + const trimmedName = name.trim(); + const validation = editDocumentNameSchema.safeParse({ + name: trimmedName, + }); if (!validation.success) { return toast.error(validation.error.errors[0].message); } setLoading(true); - const trimmedName = name.trim(); const teamId = teamInfo?.currentTeam?.id;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/datarooms/edit-dataroom-document-modal.tsx` around lines 97 - 105, The current validation uses editDocumentNameSchema.safeParse({ name }) but then trims the value into trimmedName, allowing whitespace-only names to pass; re-run validation against the trimmedName (e.g., safeParse({ name: trimmedName })) before calling setLoading and proceeding, and if validation fails return toast.error(validation.error.errors[0].message); ensure this check occurs immediately after computing trimmedName so the submission never proceeds with an empty/whitespace-only name.
163-166:⚠️ Potential issue | 🟠 MajorOnly close the modal on success.
finallystill runs after the earlyreturns in the error paths, so Line 165 dismisses the dialog even when the rename fails. That forces the user to reopen it and re-enter the name instead of retrying in place.Suggested fix
- } finally { - setLoading(false); - setOpen(false); - } + setOpen(false); + } finally { + setLoading(false); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/datarooms/edit-dataroom-document-modal.tsx` around lines 163 - 166, The modal is being closed inside the finally block (setOpen(false)) which runs even on error; move only setLoading(false) into the finally and call setOpen(false) only after the successful rename/update path so the dialog remains open on errors. Locate the block using setLoading and setOpen in the EditDataroomDocumentModal component (edit-dataroom-document-modal.tsx) and remove setOpen(false) from the finally, then invoke setOpen(false) immediately after the code path that confirms success (the success branch that currently returns or proceeds after the rename/update promise resolves).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@components/datarooms/edit-dataroom-document-modal.tsx`:
- Around line 97-105: The current validation uses
editDocumentNameSchema.safeParse({ name }) but then trims the value into
trimmedName, allowing whitespace-only names to pass; re-run validation against
the trimmedName (e.g., safeParse({ name: trimmedName })) before calling
setLoading and proceeding, and if validation fails return
toast.error(validation.error.errors[0].message); ensure this check occurs
immediately after computing trimmedName so the submission never proceeds with an
empty/whitespace-only name.
- Around line 163-166: The modal is being closed inside the finally block
(setOpen(false)) which runs even on error; move only setLoading(false) into the
finally and call setOpen(false) only after the successful rename/update path so
the dialog remains open on errors. Locate the block using setLoading and setOpen
in the EditDataroomDocumentModal component (edit-dataroom-document-modal.tsx)
and remove setOpen(false) from the finally, then invoke setOpen(false)
immediately after the code path that confirms success (the success branch that
currently returns or proceeds after the rename/update promise resolves).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f9bb24fb-2daf-441a-a4cd-6798d119417a
📒 Files selected for processing (1)
components/datarooms/edit-dataroom-document-modal.tsx
Implement optimistic SWR cache updates for document renames to fix a bug where name changes visually reverted.
The previous implementation failed to invalidate the sidebar tree cache due to an incorrect SWR key and only triggered background revalidation for other caches, causing a visible "revert" flicker. This PR introduces
populateCacheto optimistically update the document name across all relevant SWR caches: root documents, current folder documents, sidebar folder tree, and folder tree with documents.Summary by CodeRabbit