Fix back navigation from activity page to cards (#2727)

Three changes needed to support navigating back from a card to the
activity page:

- Add root_path to the prefer_referrer allowlist on the card show page
- Switch event links from HTML target="_top" to data-turbo-frame="_top"
  so Turbo handles the navigation and turbo:before-visit fires to save
  the referrer
- Normalize trailing slashes in the referrer path comparison so
  /account_id and /account_id/ both match

ref: https://app.fizzy.do/5986089/cards/2390
This commit is contained in:
Mike Dalessio
2026-03-18 22:03:36 -04:00
committed by GitHub
parent 248fc5d3e7
commit 11df9c3589
4 changed files with 29 additions and 4 deletions
@@ -24,8 +24,9 @@ export default class extends Controller {
referrerBackLinkTargetConnected(link) {
if (!this.#referrerUrl || !this.#referrerLabel) { return }
const allowedPaths = (link.dataset.turboNavigationAllowedReferrerPaths || "").split(",")
const referrerPath = new URL(this.#referrerUrl).pathname
const stripTrailingSlash = path => path.replace(/\/$/, "")
const allowedPaths = (link.dataset.turboNavigationAllowedReferrerPaths || "").split(",").map(stripTrailingSlash)
const referrerPath = stripTrailingSlash(new URL(this.#referrerUrl).pathname)
if (!allowedPaths.includes(referrerPath)) { return }
link.href = this.#referrerUrl
+1 -1
View File
@@ -7,7 +7,7 @@
<% content_for :header do %>
<div class="header__actions header__actions--start">
<%= link_back_to_board @card.board, prefer_referrer: [ cards_path, board_path(@card.board) ] %>
<%= link_back_to_board @card.board, prefer_referrer: [ root_path, cards_path, board_path(@card.board) ] %>
</div>
<% end %>
+1 -1
View File
@@ -2,8 +2,8 @@
id: dom_id(event, "timelined"),
class: "event event--#{ event.action } #{ "golden-effect" if event.card.golden? } center-block flex flex-column full-width align-start justify-start position-relative",
style: "--card-color: #{ card.closed? ? "var(--color-card-complete)" : card.color };",
target: "_top",
data: {
turbo_frame: "_top",
related_element_target: "related",
related_element_group_value: card.id,
action: "mouseover->related-element#highlight mouseout->related-element#unhighlight" } do %>