Skip to content

Conversation

@Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Oct 7, 2025

Description

Fixes #7677
Uses local storage to spread the data to others tabs.

Type of change

  • 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 broadcastGlobalScoreUpdate function to send global score updates to other tabs via localStorage, including a timestamp to ensure reliable event firing.
  • Implemented a listener for the storage event that receives global score updates from other tabs and calls updateGlobalScoreUI to 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 updateGlobalScoreUI function to centralize UI updates for the global score widget and Rocket Insights table row, simplifying score refresh logic.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • 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

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

No tests for this.

@Miraeld Miraeld requested a review from a team October 7, 2025 13:20
@Miraeld Miraeld self-assigned this Oct 7, 2025
Copilot AI review requested due to automatic review settings October 7, 2025 13:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issue #7677 where global scores don't automatically update across browser tabs. The implementation adds a localStorage-based mechanism to broadcast global score updates between tabs, ensuring score consistency across the entire browser session.

Key changes:

  • Added localStorage event broadcasting for global score updates
  • Implemented cross-tab synchronization using storage events
  • Centralized UI update logic for global score display

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 434 to 450
function updateGlobalScoreUI(newScoreData) {
// Update local state
globalScoreData = newScoreData;

// Update dashboard widget if visible
if (isOnDashboard()) {
const $widget = $('#wpr_global_score_widget');
if ($widget.length && newScoreData.html) {
$widget.html(newScoreData.html);
}
}

// Update Rocket Insights table row if visible
if (isOnRocketInsights() && newScoreData.row_html) {
updateGlobalScoreRow(newScoreData);
}
}
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

The function duplicates existing UI update logic found elsewhere in the codebase. The dashboard widget update on lines 441-443 is identical to line 528, and the Rocket Insights update on lines 447-448 is identical to line 591. This creates maintainability issues if the update logic needs to change.

Copilot uses AI. Check for mistakes.
@codacy-production
Copy link

codacy-production bot commented Oct 7, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for ebe9a521 (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (ebe9a52) Report Missing Report Missing Report Missing
Head commit (728801b) 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

Footnotes

  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.

@Mai-Saad Mai-Saad requested a review from Copilot October 9, 2025 05:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 4 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jeawhanlee
Copy link
Contributor

@wordpressfan Do we still continue with this PR as we established that it was edgy.

@wordpressfan
Copy link
Contributor

No, let's block it exactly as @Miraeld , and if needed we can validate later and go ahead with the PR

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.

3.20: Sometimes Global Score doesn't auto-update across tabs

4 participants