aminghadersohi opened a new pull request, #43310:
URL: https://github.com/apache/superset/pull/43310
## 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]