Update the insights lightbulb badge live on dismiss and refresh
Merged
GA
2mo ago+99+99+01234567890123456789-8-8-0123456789
Problem
The unread count on the nav lightbulb only changed after a navigation. Dismissing an insight on the dashboard left the old number in place. The acknowledge/unacknowledge turbo-stream responses and GenerateInsightsJob's broadcast never touched the badge, and neither layout copy (desktop header, mobile top nav) had a target a stream could hit.
Change
- The count chip moves into
layouts/shared/_insights_badge.html.erb. It's wrapped in adata-insights-badgespan withdisplay: contents, which stays in the page even at 0 so later streams always have a target. The chip still positions against the lightbulb link, so the look is unchanged. - The
acknowledge/unacknowledgestreamsreplace_all "[data-insights-badge]", which updates both layout copies. GenerateInsightsJob#broadcast_feedbroadcasts the same replace on the plain family stream, which every layout subscribes to via_htmldoc. New unread insights bump the count on whatever page is open, not only on /insights.
Behaviour notes
The badge still counts unread insights. That was a deliberate choice over switching it to "not dismissed". So:
- /insights still marks everything read on a real visit, and the badge reads 0 there.
- Undo restores an insight as
read, so undoing a dashboard dismissal leaves the count where the dismissal put it. - "9+" still caps the number, and the chip disappears at 0.
Screenshots
Dismissing an insight on the dashboard, before (left) and after (right). The feed already lists one insight, but before this change the lightbulb badge still reads 2.

Validation
- New controller tests:
- both layout copies render a badge target
acknowledgestreams the decremented count- the last unread insight yields an empty badge
- the "9+" cap
unacknowledgestreams the unchanged count
- New job test for the family-stream badge broadcast.
bin/rails test: 10335 runs, 0 failures, 0 errors.- rubocop, erb_lint, Biome and Brakeman are clean.
- No system tests cover insights, so none were applicable.
Summary by CodeRabbit
- Bug Fixes
- Insight badges now update across both lightbulb icons when insights are acknowledged or unacknowledged, and when new insights are generated.
- Badges show the unread count, display “9+” for counts above nine, and remain empty when no unread insights are available.