Skip to content

Fix: Prevent duplicate percentage values when switching between mobile and desktop in Tech Report#1140

Merged
tunetheweb merged 4 commits intomainfrom
copilot/fix-percentage-replacement-issue
Oct 15, 2025
Merged

Fix: Prevent duplicate percentage values when switching between mobile and desktop in Tech Report#1140
tunetheweb merged 4 commits intomainfrom
copilot/fix-percentage-replacement-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 15, 2025

Problem

When switching between mobile and desktop client views on the Tech Report page, percentage change indicators were being appended instead of replaced. This caused multiple percentage values to accumulate and display together, as shown in the issue screenshots.

For example, switching from mobile to desktop would result in displays like:

  • ▼ -2.67% ▲ 5.26% ▼ -2.67% ▲ 5.26% ▼ -2.67% (instead of just the desktop values)

Root Cause

In the updateAppSummary() method in src/js/techreport/timeseries.js, when the client breakdown was changed, new monthchange span elements were being appended to breakdown cards without first removing the existing ones:

// Old code - just appends without cleanup
card.appendChild(monthChange);

This is different from the updateClientSummary() method, which clears the entire container (container.innerHTML = '') before rebuilding, preventing this issue.

Solution

Added cleanup logic to remove any existing .monthchange element before appending the new one:

/* Remove existing monthchange element if present */
const existingChange = card.querySelector('.monthchange');
if(existingChange) {
  existingChange.remove();
}

const monthChange = document.createElement('span');
monthChange.textContent = latestMoMStr;
monthChange.className = `monthchange ${styling?.color} ${styling?.direction}`;
card.appendChild(monthChange);

This ensures that only one percentage change indicator is displayed at a time, regardless of how many times the user switches between mobile and desktop views.

Testing

  • ✅ Build passes successfully with webpack
  • ✅ Minimal change - only 4 lines added to cleanup existing elements
  • ✅ No impact on other functionality

Fixes the issue where percentage values were appended instead of replaced when changing client breakdown state.

Original prompt

This section details on the original issue you should resolve

<issue_title>Tech Report: Bug - percentage is appended instead of replaced, when changing state between mobile and desktop</issue_title>
<issue_description>go here

change mobile to desktop

you get the change in percentage appended, instead of replacing the previous one..

Image

Image</issue_description>

<agent_instructions>the issue is about 'client-breakdown' switch not cleaning up properly the values in 'data-summary -> breakdown-item - breakdown-value' component related to a chart</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #1139


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…updateAppSummary

Co-authored-by: max-ostapenko <1611259+max-ostapenko@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix percentage appending issue when changing states Fix: Prevent duplicate percentage values when switching between mobile and desktop in Tech Report Oct 15, 2025
Copilot AI requested a review from max-ostapenko October 15, 2025 18:57
Comment thread src/js/techreport/timeseries.js Outdated
@tunetheweb tunetheweb marked this pull request as ready for review October 15, 2025 19:34
@tunetheweb tunetheweb merged commit d0f7539 into main Oct 15, 2025
11 checks passed
@tunetheweb tunetheweb deleted the copilot/fix-percentage-replacement-issue branch October 15, 2025 19:34
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.

Tech Report: Bug - percentage is appended instead of replaced, when changing state between mobile and desktop

3 participants