Skip to content

Dataroom document name revert#2105

Open
mfts wants to merge 1 commit intomainfrom
cursor/dataroom-document-name-revert-42e2
Open

Dataroom document name revert#2105
mfts wants to merge 1 commit intomainfrom
cursor/dataroom-document-name-revert-42e2

Conversation

@mfts
Copy link
Owner

@mfts mfts commented Mar 7, 2026

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 populateCache to optimistically update the document name across all relevant SWR caches: root documents, current folder documents, sidebar folder tree, and folder tree with documents.


Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes
    • Fixed document name updates to consistently reflect changes across all dataroom views, folders, and nested structures
    • Added error notifications to inform users when document renaming fails
    • Improved dialog behavior to properly close after submission and maintain accurate loading states during the update process

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
Copy link

cursor bot commented Mar 7, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@vercel
Copy link

vercel bot commented Mar 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
papermark Ready Ready Preview, Comment Mar 7, 2026 2:01am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

Walkthrough

Modified 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

Cohort / File(s) Summary
Document Name Update Modal
components/datarooms/edit-dataroom-document-modal.tsx
Added helper functions updateDocNameInDocuments and updateDocNameInFolderTree to update document names in flat lists and hierarchical folder structures. Introduced local state derived values (trimmedName, teamId, baseKey). Replaced direct API calls with parameterized POST endpoint /api/teams/{teamId}/documents/{documentId}/update-name. Enhanced SWR cache invalidation with targeted mutate calls across documents, folder documents, and folder endpoints using populateCache. Added error handling for non-OK responses and finally block for cleanup.

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Dataroom document name revert' is vague and misleading—it suggests reverting a feature rather than fixing a revert bug. The actual change is about preventing visual reversion when renaming documents using optimistic SWR cache updates. Revise the title to accurately reflect the fix, such as 'Fix document name revert flicker with optimistic SWR cache updates' or 'Prevent document name revert on rename with populateCache'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Validate 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 | 🟠 Major

Only close the modal on success.

finally still runs after the early returns 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3cf4458 and 6d18b9e.

📒 Files selected for processing (1)
  • components/datarooms/edit-dataroom-document-modal.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants