From 9cc9857d526b1b062bec94deeab14b0b51fbf015 Mon Sep 17 00:00:00 2001 From: TripleU <182648541+TripleU613@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:33:39 -0500 Subject: [PATCH] Topic cards: a click on the title opens the topic in the app The card's title link is core's TopicLink, which now wraps the words in a span. Core opens a topic in the app only when the click lands on the raw-topic-link itself, and its click interceptor leaves raw links to the row's handler; so a click on the words (nearly every click) did a full page load: the whole app booted again for every topic opened, about 550 ms instead of about 230 ms on dev. The row transformer now opens it with core's navigateToTopic when the click is inside the link; modifier keys and middle-click still open a new tab. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs --- spec/system/jtech_theme_part1_spec.rb | 16 ++++++++++++++++ .../api-initializers/jt-topic-cards.gts | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/spec/system/jtech_theme_part1_spec.rb b/spec/system/jtech_theme_part1_spec.rb index 032edb0d..fe514c47 100644 --- a/spec/system/jtech_theme_part1_spec.rb +++ b/spec/system/jtech_theme_part1_spec.rb @@ -365,6 +365,22 @@ end end + # The title's words sit in a span inside the link; a click on them loaded + # the whole page again instead of opening the topic in the app + it "opens a topic from its card's title without reloading the page" do + sign_in(member) + visit("/latest") + expect(page).to have_css(".jt-card") + page.execute_script("window.__jtSamePage = true") + link = find(".jt-card .raw-topic-link", text: topic.title, match: :first) + # core's current TopicLink wraps the words in a span; older ones don't + (link.has_css?("span", wait: 0) ? link.find("span", match: :first) : link).click + expect(page).to have_css("#post_1") + expect(page).to have_current_path(%r{/t/}) + expect(page.evaluate_script("window.__jtSamePage === true")).to eq(true) + expect_no_theme_errors + end + # "Skip to main content", the first Tab on a page, was core's square chip # jammed against the window's top edge, over the logo it "rounds the skip link and keeps it off the window's edge" do diff --git a/themes/jtech/javascripts/discourse/api-initializers/jt-topic-cards.gts b/themes/jtech/javascripts/discourse/api-initializers/jt-topic-cards.gts index 5fea57ce..75024227 100644 --- a/themes/jtech/javascripts/discourse/api-initializers/jt-topic-cards.gts +++ b/themes/jtech/javascripts/discourse/api-initializers/jt-topic-cards.gts @@ -4,6 +4,7 @@ import { settings } from "virtual:theme"; import HeaderTopicCell from "discourse/components/topic-list/header/topic-cell"; import { apiInitializer } from "discourse/lib/api"; import type DAG from "discourse/lib/dag"; +import { wantsNewWindow } from "discourse/lib/intercept-click"; import type Category from "discourse/models/category"; import type Topic from "discourse/models/topic"; import JtTopicCard, { @@ -45,6 +46,8 @@ interface TopicListTransformerArgs { interface TopicListItemClickContext { event: MouseEvent & { target: Element }; + topic: Topic; + navigateToTopic: (topic: Topic, href: string) => void; } // Discovery lists (latest/new/top/category/tag, group + user activity), the @@ -136,6 +139,21 @@ export default apiInitializer((api) => { if (window.getSelection()?.toString()) { return; } + // The title's text sits in a span inside the link. Core opens the topic + // in the app only when the click lands on the link itself, and its + // click interceptor leaves raw links to the row; so a click on the + // words loaded the whole page again, every time. + const own = event.target.closest( + "a.raw-topic-link, a.post-activity, a.badge-posts" + ); + if (own && own !== event.target) { + if (wantsNewWindow(event)) { + return; + } + event.preventDefault(); + context.navigateToTopic(context.topic, own.href); + return; + } if ( (event.target.closest("a, button, input, label") && !event.target.closest(".topic-excerpt")) ||