Fix #7677: 3.20 Sometimes Global Score doesn't auto-update across tabs
Description
Fixes #7677 Uses local storage to spread the data to others tabs.
Type of change
- [x] Enhancement (non-breaking change which improves an existing functionality).
Detailed scenario
What was tested
Manual test like the video
How to test
Follow the video in the issue.
Technical description
Documentation
This pull request enhances the way global score updates are handled across browser tabs by introducing a mechanism to broadcast and synchronize score changes using localStorage events. This ensures that when the global score is updated in one tab, the change is immediately reflected in all other open tabs, improving consistency and user experience.
Global score synchronization improvements:
- Added the
broadcastGlobalScoreUpdatefunction to send global score updates to other tabs vialocalStorage, including a timestamp to ensure reliable event firing. - Implemented a listener for the
storageevent that receives global score updates from other tabs and callsupdateGlobalScoreUIto refresh the score display. - Modified AJAX success handlers to broadcast global score updates after updating local state, ensuring all tabs remain in sync when scores change from dashboard or Rocket Insights actions. [1] [2] [3]
UI update enhancements:
- Added the
updateGlobalScoreUIfunction to centralize UI updates for the global score widget and Rocket Insights table row, simplifying score refresh logic.
Mandatory Checklist
Code validation
- [x] I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
- [x] I triggered all changed lines of code at least once without new errors/warnings/notices.
- [ ] I implemented built-in tests to cover the new/changed code.
Code style
- [x] I wrote a self-explanatory code about what it does.
- [x] I protected entry points against unexpected inputs.
- [x] I did not introduce unnecessary complexity.
- [x] Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.
Unticked items justification
No tests for this.
Coverage summary from Codacy
See diff coverage on Codacy
| Coverage variation | Diff coverage |
|---|---|
| Report missing for ebe9a5283d6c2d7602612d29b9cfff8aaa9710fa[^1] | :white_check_mark: ∅ (target: 50.00%) |
Coverage variation details
| Coverable lines | Covered lines | Coverage | |
|---|---|---|---|
| Common ancestor commit (ebe9a5283d6c2d7602612d29b9cfff8aaa9710fa) | Report Missing | Report Missing | Report Missing |
| Head commit (728801be22559179c9a4c82dd9a66bf3ae0108a8) | 41437 | 18493 | 44.63% |
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
| Coverable lines | Covered lines | Diff coverage | |
|---|---|---|---|
| Pull request (#7786) | 0 | 0 | ∅ (not applicable) |
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%
See your quality gate settings Change summary preferences
[^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
@wordpressfan Do we still continue with this PR as we established that it was edgy.
No, let's block it exactly as @Miraeld , and if needed we can validate later and go ahead with the PR