fix: prevent setState on unmounted component in HIPAADashboard#13479
Conversation
HIPAADashboard fires four parallel API calls on mount — safeguards, PHI namespaces, data flows, and summary. The useEffect had no cleanup, so navigating away mid-flight left setState calls firing on an unmounted component. Separated .json() parsing from state updates so the cancelledRef check runs after all async work completes, with guards in catch and finally. Same pattern applied across the compliance dashboard suite — this was the fourth one. Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @AdeshDeshmukh — thanks for opening this PR!
This is an automated message. |
There was a problem hiding this comment.
Pull request overview
Prevents React warnings/errors caused by calling setState after HIPAADashboardContent unmounts by adding a cancellation ref guard around async fetch completion.
Changes:
- Added a
cancelledRef(useRef) that is reset on mount and flipped in theuseEffectcleanup. - Moved
.json()parsing into local variables and addedcancelledRefguards beforesetStatecalls in success,catch, andfinally.
There was a problem hiding this comment.
✅ Security review: PASS
- Standard React unmount guard pattern (
useRef+ cleanup function) - No new API calls, no input handling changes
- All state updates correctly gated by
cancelledRef.currentcheck - JSON parsing completes before the guard check (correct — avoids dangling promises)
Clean fix.
|
@kubestellar-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@kubestellar-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
✅ Security & quality review: PASS
cancelledRefpattern correctly prevents setState-after-unmount race condition.json()parsing moved before the guard — prevents dangling promise resolution from triggering state updates- Guard in
catchandfinallyblocks covers all async paths - Ref reset on mount + flip in cleanup is idiomatic React
- No new attack surface, no sensitive data exposure
- Matches the established pattern used in the other 3 compliance dashboards
LGTM — safe to merge.
|
@kubestellar-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
8b99012
into
kubestellar:main
✅ Post-Merge Verification: passedCommit: |
Fourth dashboard in the compliance suite with the same pattern —
four API calls fire on mount, resolve asynchronously, and dump into
setState with no one checking if the component is still around.
Same cancelledRef fix — .json() parsing pulled ahead of the guard,
checks in catch and finally, ref reset on mount and flipped in
cleanup. Nothing fancy, just the same treatment the other three
already got.