Skip to content

Save Theme Button After Change Won't Work - #282

Open
harshvardhan60792 wants to merge 1 commit into
MultiboxLabs:mainfrom
harshvardhan60792:fix/281-save-theme-button-after-change-won-t-wor
Open

Save Theme Button After Change Won't Work#282
harshvardhan60792 wants to merge 1 commit into
MultiboxLabs:mainfrom
harshvardhan60792:fix/281-save-theme-button-after-change-won-t-wor

Conversation

@harshvardhan60792

@harshvardhan60792 harshvardhan60792 commented Aug 9, 2026

Copy link
Copy Markdown

Fixes #281

Save button got stuck as a static 'Saved' confirmation because the auto-close timeout checked a stale closure of saveSuccess (always false, so it never fired) and no code cleared saveSuccess on subsequent edits; fixed by tracking success in a ref for the timeout and resetting saveSuccess whenever the user edits the space again.

Testing: Repo has no test suite (confirmed no test files/dirs); verified by tracing the exact stale-closure bug against the reported repro steps and confirming the edited file still parses/formats cleanly via npx prettier --check (no syntax errors) -- did not run bun install/full typecheck as it was not needed to validate this narrow logic fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved editing and saving behavior in the space editor.
    • Editing any field, including the name, now correctly resets the save-success state.
    • Prevented previous success notifications from closing the editor after new changes are made.

Save button got stuck as a static 'Saved' confirmation because the auto-close timeout checked a stale closure of saveSuccess (always false, so it never fired) and no code cleared saveSuccess on subsequent edits; fixed by tracking success in a ref for the timeout and resetting saveSuccess whenever the user edits the space again.
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

SpaceEditor now tracks the latest save-success state with a ref. Field and name edits reset the ref and UI state. The auto-close timeout reads the current ref value, so later edits can be saved again.

Changes

Space editor save-state flow

Layer / File(s) Summary
Track and reset save-success state
src/renderer/src/components/settings/sections/spaces/space-editor.tsx
The editor resets save-success state when fields or the name change. The auto-close timeout checks the current ref value instead of a stale closure value.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: iamevanyt

Poem

A bunny taps Save once more,
Fresh edits hop across the floor.
The success flag clears from sight,
The timer checks the state just right.
“Save again!” the rabbit cheers.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the save button issue addressed by the pull request.
Linked Issues check ✅ Passed The changes reset the saved state and support subsequent theme saves as required by issue #281.
Out of Scope Changes check ✅ Passed The changes are limited to resetting save state and preventing stale timeout behavior in the space editor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown

Greptile Summary

The PR resets saved-state feedback when theme or name values change and replaces the stale timeout closure with a ref. The shared ref leaves overlapping save timeouts unable to distinguish which save they belong to.

  • Adds ref-backed tracking for the latest save-success state.
  • Re-enables saving after subsequent edits.
  • Auto-closes after a successful save unless the ref has been reset.

Confidence Score: 4/5

The overlapping-save timeout race should be fixed before merging because an older timeout can close the editor during a newer save confirmation.

The new mutable ref fixes the stale closure for a single save but conflates multiple save generations, allowing an earlier uncancelled timeout to observe a later success and close prematurely.

Files Needing Attention: src/renderer/src/components/settings/sections/spaces/space-editor.tsx

Important Files Changed

Filename Overview
src/renderer/src/components/settings/sections/spaces/space-editor.tsx The edit reset covers all current mutation paths, but sharing one success ref across uncancelled timeout generations permits an older save timeout to close the editor after a newer save.

Reviews (1): Last reviewed commit: "Save Theme Button After Change Won't Wor..." | Re-trigger Greptile

Comment on lines +73 to 75
if (saveSuccessRef.current) {
onClose();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Shared ref conflates save generations

When the user saves, edits, and successfully saves again within 1.5 seconds, the first uncancelled timeout reads the shared saveSuccessRef value written by the second save and closes the editor less than 1.5 seconds after the latest save.

@coderabbitai coderabbitai Bot left a comment

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.

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 `@src/renderer/src/components/settings/sections/spaces/space-editor.tsx`:
- Around line 68-73: Update handleSave and both edit handlers to use an
edit-generation counter: capture the current generation when handleSave starts,
increment it whenever Lines 35 or 109 process an edit, and only set
saveSuccessRef/current success state or invoke onClose from the save completion
timeout when the captured generation still matches. Ensure each timeout is tied
to its originating save so an older request cannot overwrite newer edits or
close the editor prematurely.
🪄 Autofix

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: ASSERTIVE

Plan: Pro Plus

Run ID: 9d1fa668-6abf-43f3-82fa-5143c5c87e35

📥 Commits

Reviewing files that changed from the base of the PR and between 55b0bb6 and 89dd641.

📒 Files selected for processing (1)
  • src/renderer/src/components/settings/sections/spaces/space-editor.tsx

Comment on lines +68 to +73
saveSuccessRef.current = true;
setSaveSuccess(true);

// Auto-close after short delay
// Auto-close after short delay, unless the user started editing again in the meantime
setTimeout(() => {
if (saveSuccess) {
if (saveSuccessRef.current) {

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not let an older save overwrite a newer edit.

If the user edits the space while flow.spaces.updateSpace(...) is pending, Lines 35 or 109 set saveSuccessRef.current to false. When the request resolves, Line 68 unconditionally sets it back to true, and Lines 72-73 can call onClose() while editedSpace contains unsaved changes.

The shared boolean also does not identify which save owns the timeout. A timeout from an earlier save can observe true from a later save and close the editor too early.

Capture an edit generation when handleSave starts. Increment it in both edit handlers. Apply the success state and close only when the captured generation still matches.

Proposed fix
 const saveSuccessRef = useRef(false);
+const editGenerationRef = useRef(0);

 const updateEditedSpace = (updates: Partial<Space>) => {
+  editGenerationRef.current += 1;
   setEditedSpace((prev) => ({ ...prev, ...updates }));

 const handleSave = async () => {
+  const saveGeneration = editGenerationRef.current;
   setIsSaving(true);
   setSaveSuccess(false);
   try {
     ...
     await flow.spaces.updateSpace(space.profileId, space.id, updatedFields);
     onSpacesUpdate();
+    if (saveGeneration !== editGenerationRef.current) {
+      return;
+    }
     saveSuccessRef.current = true;
     setSaveSuccess(true);

     setTimeout(() => {
-      if (saveSuccessRef.current) {
+      if (saveGeneration === editGenerationRef.current && saveSuccessRef.current) {
         onClose();
       }
     }, 1500);
   }

 const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+  editGenerationRef.current += 1;
   setEditedSpace({
🤖 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 `@src/renderer/src/components/settings/sections/spaces/space-editor.tsx` around
lines 68 - 73, Update handleSave and both edit handlers to use an
edit-generation counter: capture the current generation when handleSave starts,
increment it whenever Lines 35 or 109 process an edit, and only set
saveSuccessRef/current success state or invoke onClose from the save completion
timeout when the captured generation still matches. Ensure each timeout is tied
to its originating save so an older request cannot overwrite newer edits or
close the editor prematurely.

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.

Save Theme Button After Change Won't Work

1 participant