Skip to content

ROX-31423: Standardize boolean toggle state updater pattern#18411

Merged
sachaudh merged 1 commit intomasterfrom
ROX-31423
Jan 12, 2026
Merged

ROX-31423: Standardize boolean toggle state updater pattern#18411
sachaudh merged 1 commit intomasterfrom
ROX-31423

Conversation

@sachaudh
Copy link
Contributor

@sachaudh sachaudh commented Jan 8, 2026

Description

Standardized the boolean toggle state updater pattern across the UI codebase to use the functional updater form setState((prev) => !prev) instead of the direct value form setState(!value).

This follows React's recommended pattern when new state depends on previous state, preventing stale closure bugs and correctly handling rapid state changes (e.g., multiple rapid clicks).

Key Changes:

  • Updated 37 files (39 occurrences) to use (prev) => !prev pattern
  • Includes hooks, components, and containers across the codebase

TypeScript Constraint Exceptions:
Two files retained the direct value pattern due to TypeScript prop constraints:

  • FlowBulkDropdown.tsx - setOpen prop typed as (o: boolean) => void
  • CreateViewBasedReportModal.tsx - setIsOpen prop typed as (value: boolean) => void

These props accept only boolean values, not functional updaters. Changing them would require updating parent component type contracts.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • modified existing tests

How I validated my change

  • Verified TypeScript compilation passes with no errors
  • Verified ESLint passes with no errors
  • No behavioral changes - purely syntactic refactoring for consistency and safety

@openshift-ci
Copy link

openshift-ci bot commented Jan 8, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Jan 8, 2026

Images are ready for the commit at 0334f54.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.10.x-748-g0334f54a98.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.94%. Comparing base (0041570) to head (0334f54).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18411   +/-   ##
=======================================
  Coverage   48.93%   48.94%           
=======================================
  Files        2631     2631           
  Lines      197964   197964           
=======================================
+ Hits        96872    96886   +14     
+ Misses      93703    93695    -8     
+ Partials     7389     7383    -6     
Flag Coverage Δ
go-unit-tests 48.94% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sachaudh sachaudh marked this pull request as ready for review January 9, 2026 16:03
@sachaudh sachaudh requested a review from a team as a code owner January 9, 2026 16:03
@sachaudh sachaudh force-pushed the ROX-31423 branch 2 times, most recently from af9c748 to edf68e6 Compare January 9, 2026 17:17
@sachaudh
Copy link
Contributor Author

sachaudh commented Jan 9, 2026

Tests should be resolved once #18422 goes in. The reason is explained in this comment: #18422 (comment)

Use functional updater (prev) => !prev for all boolean toggles to
prevent stale closure bugs and handle rapid state changes correctly.
Updated 37 files across hooks, components, and containers.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Saif Chaudhry <schaudhr@redhat.com>
Copy link
Contributor

@dvail dvail left a comment

Choose a reason for hiding this comment

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

🎉

These props accept only boolean values, not functional updaters. Changing them would require updating parent component type contracts.

Certainly not something that we should do in this PR, but I don't think updating the type contracts should be a blocker to change the other instances of this. (Other than the blocker of it being more cleanup work.)

@sachaudh sachaudh merged commit 1f88869 into master Jan 12, 2026
90 checks passed
@sachaudh sachaudh deleted the ROX-31423 branch January 12, 2026 20:40
ksurabhi91 pushed a commit that referenced this pull request Jan 13, 2026
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Saif Chaudhry <schaudhr@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants