1import { Controller } from "@hotwired/stimulus" 2import { Turbo } from "@hotwired/turbo-rails" 3 4// Turbo Drive preserves module scope across visits, so this tracks in-app history. 5// site_view.js eagerly imports this controller to record pages before Stimulus connects. 6let previousUrl = null 7// Seed the landing page immediately. Turbo's first turbo:load doesn't fire until 8// window.load (seconds, on image-heavy pages), so waiting for it loses the origin 9// page when a reader clicks a link before then. 10let currentUrl = document.querySelector('meta[name="back-skip"]') ? null : window.location.href 11 12// Redirecting pages, such as the password form, should not become return destinations. 13document.addEventListener("turbo:load", () => { 14 if (document.querySelector('meta[name="back-skip"]')) return 15 if (window.location.href === currentUrl) return 16 17 previousUrl = currentUrl 18 currentUrl = window.location.href 19}) 20 21export default class extends Controller { 22 navigate(event) { 23 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { 24 return 25 } 26 27 if (this.hasReturnDestination) { 28 event.preventDefault() 29 Turbo.visit(previousUrl) 30 } 31 } 32 33 get hasReturnDestination() { 34 if (!previousUrl || previousUrl === currentUrl) return false 35 36 return new URL(previousUrl).origin === window.location.origin 37 } 38};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.