From 33d51c165c2c496c6131652a4a3e0fe531e1d420 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sat, 11 Jul 2026 17:51:14 +0900 Subject: [PATCH] Opt markdown links out of Turbo to escape turbo-frames Links inside internal comments live within the rating widget's turbo-frame, so clicking a comment URL triggered a frame navigation whose response lacked that frame, rendering "Content missing". Since Turbo Drive is disabled app-wide, links are only ever intercepted when inside a turbo-frame. Marking rendered links data-turbo="false" makes those frame-internal links navigate natively in the same tab (fixing the bug) while being a no-op everywhere else -- no new-tab side effects on other markdown surfaces (public guidelines, anchor links, autolinked emails, mail preview) and no tabnabbing surface to mitigate. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/helpers/application_helper.rb | 2 +- spec/helpers/application_helper_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4237ac32c..a2a0b2e80 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,7 +7,7 @@ def block_code(code, language) end MARKDOWN_RENDERER = Redcarpet::Markdown.new( - MarkdownRenderer.new(filter_html: true, hard_wrap: true), + MarkdownRenderer.new(filter_html: true, hard_wrap: true, link_attributes: { 'data-turbo' => 'false' }), fenced_code_blocks: true, no_intra_emphasis: true, autolink: true, diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..621b1db99 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe ApplicationHelper, type: :helper do + describe '#markdown' do + it 'opts explicit links out of Turbo so they escape a surrounding turbo-frame' do + html = helper.markdown('see [example](https://example.com)') + + expect(html).to include('href="https://example.com"') + expect(html).to include('data-turbo="false"') + end + + it 'applies the same attribute to autolinked bare URLs' do + html = helper.markdown('visit https://example.com now') + + expect(html).to include('data-turbo="false"') + end + end +end