Skip to content

Dataroom document name revert#2105

Merged
mfts merged 3 commits intomainfrom
cursor/dataroom-document-name-revert-42e2
Mar 11, 2026
Merged

Dataroom document name revert#2105
mfts merged 3 commits 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
    • Trimmed document names before validation/submission to prevent accidental whitespace errors
  • Performance

    • Faster UI updates by applying targeted in-memory cache updates instead of full revalidation

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 11, 2026 1:59am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 486a294b-03e5-4508-8e1f-d0f6b020daa2

📥 Commits

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

📒 Files selected for processing (1)
  • components/datarooms/edit-dataroom-document-modal.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/datarooms/edit-dataroom-document-modal.tsx

Walkthrough

Modified the edit-dataroom-document-modal to add typed utilities for updating document names in-memory, trim and validate names, call a parameterized POST API to update names, and replace full SWR revalidations with targeted mutate calls that populate caches and handle errors/loading state.

Changes

Cohort / File(s) Summary
Document Name Update Modal
components/datarooms/edit-dataroom-document-modal.tsx
Added types and utilities (DataroomIncludeDocumentsItem, updateDocNameInDocuments, updateDocNameInFolderTree, updateDocNameInIncludeDocumentsTree) to update names in flat and tree structures. Trim input before validation, call POST /api/teams/{teamId}/documents/{documentId}/update-name using computed baseKey, and perform targeted SWR mutate updates (documents, folder documents, folders, folders?include_documents=true) without revalidation. Improved error handling for non-OK responses and ensured loading/dialog cleanup on completion.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Dataroom document name revert' accurately describes the main change: fixing a bug where document name changes visually reverted by implementing optimistic SWR cache updates.

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

@mfts mfts merged commit 2a4e5b6 into main Mar 11, 2026
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants