Skip to content

fix(listview): stop card clicks creating a duplicate history entry - #43310

Open
aminghadersohi wants to merge 3 commits into
apache:masterfrom
aminghadersohi:aminghadersohi/listview-card-duplicate-history-entry
Open

fix(listview): stop card clicks creating a duplicate history entry#43310
aminghadersohi wants to merge 3 commits into
apache:masterfrom
aminghadersohi:aminghadersohi/listview-card-duplicate-history-entry

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

Why

Clicking a chart or dashboard card and then pressing the browser Back button does not return you to the page you came from — you stay on the chart, and only a second Back press gets you out.

The cause is a double navigation. ListViewCard renders its cover (the thumbnail) as a react-router <Link to={url}>, while ChartCard and DashboardCard additionally wrap the whole card in a clickable element that calls history.push(url). Neither stops propagation, so a single click on the cover is handled twice and pushes two identical history entries. Back pops the duplicate, which resolves to the same Explore/Dashboard URL, so the navigation looks broken.

This only shows up where cards are rendered with thumbnails — the homepage chart/dashboard sections. The Chart and Dashboard list pages default to table view (card view is behind LISTVIEWS_DEFAULT_CARD_VIEW), which uses a plain link and pushes once, which is why those entry points behave correctly.

I kept the whole card clickable rather than removing the wrapper handler, since clicking the title or body — which are not inside the link — must still navigate.

What

Added a small isNavigationHandledByLink helper in src/views/CRUD/utils.tsx that reports whether a click originated inside an anchor. ChartCard and DashboardCard skip their own history.push in that case and let the link navigate, so one click produces exactly one history entry.

How to test

Regression tests added for both cards asserting that a click on the cover produces exactly one PUSH, plus a test that clicking outside the cover still navigates. Both new cover tests fail on master (the recorded navigations are ['PUSH …', 'PUSH …']) and pass with the fix.

npx jest src/features/charts src/features/dashboards src/features/home/ChartTable.test.tsx \
  src/features/home/DashboardTable.test.tsx src/pages/ChartList src/pages/DashboardList src/views/CRUD
# Test Suites: 15 passed, 15 total
# Tests:       201 passed, 201 total

Manually: enable THUMBNAILS, go to the homepage, click a chart card thumbnail, then press Back — you land back on the homepage instead of staying on the chart.

Risk & rollback

Low and contained to the two card components. The only behavior change is that a click on the cover no longer double-navigates; clicks on the title, description, and card background are unchanged, and bulkSelectEnabled still short-circuits navigation as before. Straight revert if needed.

Review guidance

Start with src/views/CRUD/utils.tsx for the helper and its rationale, then the two one-line call sites. The riskiest assumption is the closest('a[href]') check — it deliberately matches any anchor ancestor, so if a card ever gains a non-navigating anchor, that click would stop navigating the card.

ListViewCard renders its cover as a router Link while ChartCard and
DashboardCard also make the whole card clickable. A click on the cover was
handled by both, pushing two identical history entries for one click, so the
browser Back button popped the duplicate and left the user on the page they
were trying to leave.

Skip the card-level navigation when the click originated inside a link.
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.67%. Comparing base (097c99b) to head (8f042cc).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #43310   +/-   ##
=======================================
  Coverage   66.67%   66.67%           
=======================================
  Files        2876     2876           
  Lines      164007   164012    +5     
  Branches    37834    37837    +3     
=======================================
+ Hits       109347   109353    +6     
+ Misses      52514    52512    -2     
- Partials     2146     2147    +1     
Flag Coverage Δ
javascript 73.91% <100.00%> (+<0.01%) ⬆️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aminghadersohi
aminghadersohi marked this pull request as ready for review August 19, 2026 03:39
@dosubot dosubot Bot added change:frontend Requires changing the frontend listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. labels Aug 19, 2026
@aminghadersohi
aminghadersohi requested review from msyavuz and rusackas and removed request for msyavuz August 19, 2026 03:40

@bito-code-review bito-code-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #f222ec

Actionable Suggestions - 1
  • superset-frontend/src/features/dashboards/DashboardCard.test.tsx - 1
Additional Suggestions - 2
  • superset-frontend/src/features/charts/ChartCard.test.tsx - 1
    • Brittle CSS class selector in test · Line 93-93
      Using a CSS class name `.gradient-container` for test queries is fragile — class names are implementation details that can change without notice, causing tests to break. This class is not defined within this file or ChartCard.tsx (verified by grep search), making the selector opaque. Use a `data-test` attribute or semantic query instead.
  • superset-frontend/src/views/CRUD/utils.tsx - 1
    • Missing unit tests for utility · Line 493-496
      The new `isNavigationHandledByLink` utility has no unit tests, unlike the nearby `isNeedsPassword` function which is tested in `utils.test.tsx`. Per project testing standards, new utilities require coverage for success paths, error scenarios, and edge cases before merging.
Review Details
  • Files reviewed - 5 · Commit Range: 2cb4f09..6ac343a
    • superset-frontend/src/features/charts/ChartCard.test.tsx
    • superset-frontend/src/features/charts/ChartCard.tsx
    • superset-frontend/src/features/dashboards/DashboardCard.test.tsx
    • superset-frontend/src/features/dashboards/DashboardCard.tsx
    • superset-frontend/src/views/CRUD/utils.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

// the cover used to be handled twice and pushed two identical entries, which
// left the Back button popping the duplicate rather than returning the user
// to the page they came from.
jest.spyOn(global, 'fetch').mockResolvedValue({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unrestored spy in test leaks across tests

The jest.spyOn(global, 'fetch') at line 110 is never restored. Tests that run after this one will still have the mocked fetch, causing cross-test pollution.

Code Review Run #f222ec


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

- restore the fetch spy so it does not leak into later tests
- query the cover link by role instead of an internal CSS class
- cover isNavigationHandledByLink directly in views/CRUD/utils.test.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:frontend Requires changing the frontend listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant