Skip to content

fix: preserve rapid extended options saves - #754

Merged
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
Pranjal1423:fix/extended-options-rapid-save-race-552
Sep 4, 2026
Merged

fix: preserve rapid extended options saves#754
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
Pranjal1423:fix/extended-options-rapid-save-race-552

Conversation

@Pranjal1423

@Pranjal1423 Pranjal1423 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Closes #552

This PR resolves the issue where making quick successive changes in Extended Options could send a stale payload to WordPress, causing previous in-flight changes to be silently overwritten and lost after reload.

Changes:

  • apps/os-settings/parts/features.ts: Added optimistic in-memory updates via Object.assign( ctx.data.extendedOptions, options ) inside saveExtended. This ensures any subsequent rapid click reads the newest user selections rather than waiting for the previous server response. Also added an inFlightExtendedSaves counter so the ui.extendedSaving ("Saving…") indicator accurately tracks overlapping background requests without flickering or premature reset.
  • tests/vitest/extended-options-save.test.ts: Added automated test coverage for rapid successive toggles while a save is in flight to verify that all changes are preserved and dispatches carry the newest combined values.

Testing:

  1. Open OpenStation Preferences → Features as an administrator.
  2. Scroll to the Extended options section.
  3. Turn Enable drag-and-drop in the Media Library OFF, and immediately turn Enable games ON before the first save finishes (or toggle the same option twice quickly).
  4. Verify that the "Saving…" indicator stays active until all saves settle.
  5. Reload OpenStation and verify that both choices are preserved as left (Media Library stays OFF, Games stays ON).

Or

Run command: npx vitest run tests/vitest/extended-options-save.test.ts

Before Fix (Test Fails — Bug Present)

$ npx vitest run tests/vitest/extended-options-save.test.ts

 RUN  v4.1.5 /Users/pranjalwadhwani/Desktop/desktop-mode

 ❯ tests/vitest/extended-options-save.test.ts (6 tests | 1 failed) 206ms
     ✓ a toggle dispatches the full option set 21ms
     ✓ a second toggle carries the newest values 9ms
     × rapid toggles while a save is in flight carry the newest values and do not drop prior toggles 163ms
     ✓ a successful save announces the saved set 5ms
     ✓ a failed save says so inline and announces nothing 4ms
     ✓ the section is never painted for a non-admin 3ms

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  tests/vitest/extended-options-save.test.ts > Extended Options — saving > rapid toggles while a save is in flight carry the newest values and do not drop prior toggles
AssertionError: expected { media_library_enhanced: true, …(2) } to deeply equal { media_library_enhanced: false, …(2) }

- Expected
+ Received

  {
    "agents": false,
    "games": true,
-   "media_library_enhanced": false,
+   "media_library_enhanced": true,
  }

 ❯ tests/vitest/extended-options-save.test.ts:109:28

 Test Files  1 failed (1)
      Tests  1 failed | 5 passed (6)
   Start at  22:21:22
   Duration  892ms (transform 270ms, setup 292ms, import 35ms, tests 206ms, environment 290ms)

After Fix (All Tests Pass — Bug Fixed)

$ npx vitest run tests/vitest/extended-options-save.test.ts

 RUN  v4.1.5 /Users/pranjalwadhwani/Desktop/desktop-mode

 ✓ tests/vitest/extended-options-save.test.ts (6 tests) 205ms

 Test Files  1 passed (1)
      Tests  6 passed (6)
   Start at  23:58:27
   Duration  1.01s (transform 292ms, setup 318ms, import 40ms, tests 205ms, environment 361ms)
Open WordPress Playground Preview

@AllTerrainDeveloper AllTerrainDeveloper left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great! Thank you!

@Pranjal1423 would you like to create a guest-post in our blog as the top contributor? :)

You can write about yourself, who are you, why you like OpenStation, why you contribute, the tools you use, etc.

@Pranjal1423

Copy link
Copy Markdown
Contributor Author

Thank you! 😄 I’d love to!

Great! Thank you!

@Pranjal1423 would you like to create a guest-post in our blog as the top contributor? :)

You can write about yourself, who are you, why you like OpenStation, why you contribute, the tools you use, etc.

@AllTerrainDeveloper

Copy link
Copy Markdown
Collaborator

Thank you! 😄 I’d love to!

Great! Thank you!
@Pranjal1423 would you like to create a guest-post in our blog as the top contributor? :)
You can write about yourself, who are you, why you like OpenStation, why you contribute, the tools you use, etc.

I've sent you the invitation ;) Feel free to start the blog post when you wish! =)

@AllTerrainDeveloper
AllTerrainDeveloper merged commit 9bac917 into WordPress:trunk Sep 4, 2026
5 checks passed
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.

A quick second change in Extended Options saves the wrong value

2 participants