From ed3d9a8e1113ac19fea1ec6a1e79197633311524 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 22 Sep 2026 19:41:40 +0200 Subject: [PATCH 1/3] feat(v2): shorten the changelog's pull request links to #nnnn GitHub's generated release notes credit each change with the pull request's full URL, which the changelog dialog printed in full: every entry wrapped onto a second line of `https://github.com/...`. Bare pull request and issue URLs are now rewritten the way GitHub renders them, `#4252` here and `owner/name#12` for another repository, before the notes reach the markdown preview. A URL that is already a link, and a deeper page of one (`/files`, `#issuecomment-1`), are left as they are. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK --- .../v2/components/Dialogs/ChangelogDialog.vue | 13 ++-- frontend/src/v2/utils/githubLinks.test.ts | 60 +++++++++++++++++++ frontend/src/v2/utils/githubLinks.ts | 22 +++++++ 3 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 frontend/src/v2/utils/githubLinks.test.ts create mode 100644 frontend/src/v2/utils/githubLinks.ts diff --git a/frontend/src/v2/components/Dialogs/ChangelogDialog.vue b/frontend/src/v2/components/Dialogs/ChangelogDialog.vue index 90085e262..78b277d0d 100644 --- a/frontend/src/v2/components/Dialogs/ChangelogDialog.vue +++ b/frontend/src/v2/components/Dialogs/ChangelogDialog.vue @@ -12,6 +12,7 @@ import { computed, inject, onBeforeUnmount, ref } from "vue"; import { useI18n } from "vue-i18n"; import type { Events } from "@/types/emitter"; import { useThemeMode } from "@/v2/composables/useThemeMode"; +import { shortenGithubLinks } from "@/v2/utils/githubLinks"; defineOptions({ inheritAttrs: false }); @@ -25,9 +26,9 @@ type Release = { draft: boolean; }; -const RELEASES_URL = - "https://api.github.com/repos/rommapp/romm/releases?per_page=10"; -const RELEASES_PAGE_URL = "https://github.com/rommapp/romm/releases"; +const REPO = "rommapp/romm"; +const RELEASES_URL = `https://api.github.com/repos/${REPO}/releases?per_page=10`; +const RELEASES_PAGE_URL = `https://github.com/${REPO}/releases`; const { t, locale } = useI18n(); const emitter = inject>("emitter"); @@ -69,7 +70,9 @@ async function fetchReleases() { }); if (!res.ok) throw new Error(`GitHub ${res.status}`); const data: Release[] = await res.json(); - releases.value = data.filter((r) => !r.draft && !r.prerelease); + releases.value = data + .filter((r) => !r.draft && !r.prerelease) + .map((r) => ({ ...r, body: shortenGithubLinks(r.body ?? "", REPO) })); } catch (e) { console.error("Changelog fetch failed", e); error.value = true; @@ -162,7 +165,7 @@ function closeDialog() { no-highlight no-katex no-mermaid - :model-value="r.body || ''" + :model-value="r.body" :theme="mdTheme" language="en-US" preview-theme="vuepress" diff --git a/frontend/src/v2/utils/githubLinks.test.ts b/frontend/src/v2/utils/githubLinks.test.ts new file mode 100644 index 000000000..83a79a6e4 --- /dev/null +++ b/frontend/src/v2/utils/githubLinks.test.ts @@ -0,0 +1,60 @@ +import { describe, expect, it } from "vitest"; +import { shortenGithubLinks } from "./githubLinks"; + +const REPO = "rommapp/romm"; +const PR = "https://github.com/rommapp/romm/pull/4654"; + +describe("shortenGithubLinks", () => { + it("shortens a pull request to its number", () => { + expect( + shortenGithubLinks(`* Fix the list by @contributor in ${PR}`, REPO), + ).toBe(`* Fix the list by @contributor in [#4654](${PR})`); + }); + + it("shortens an issue the same way", () => { + const issue = "https://github.com/rommapp/romm/issues/942"; + + expect(shortenGithubLinks(`Fixes ${issue}`, REPO)).toBe( + `Fixes [#942](${issue})`, + ); + }); + + it("keeps the repository on another repository's reference", () => { + const other = "https://github.com/RetroRealm/playmatch/pull/12"; + + expect(shortenGithubLinks(other, REPO)).toBe( + `[RetroRealm/playmatch#12](${other})`, + ); + }); + + it("reads the repository without regard to case", () => { + const shouting = "https://github.com/RommApp/RomM/pull/7"; + + expect(shortenGithubLinks(shouting, REPO)).toBe(`[#7](${shouting})`); + }); + + it("shortens every reference on a line", () => { + const second = "https://github.com/rommapp/romm/pull/4655"; + + expect(shortenGithubLinks(`${PR} and ${second}`, REPO)).toBe( + `[#4654](${PR}) and [#4655](${second})`, + ); + }); + + // Rewriting these would nest a link inside a link. + it("leaves a reference that is already a link alone", () => { + const notes = [`[the fix](${PR})`, `[${PR}](${PR})`, `<${PR}>`].join("\n"); + + expect(shortenGithubLinks(notes, REPO)).toBe(notes); + }); + + it("leaves a deeper page of a pull request alone", () => { + const notes = [ + `${PR}/files`, + `${PR}#issuecomment-1`, + "https://github.com/rommapp/romm/compare/5.0.0...5.1.0", + ].join("\n"); + + expect(shortenGithubLinks(notes, REPO)).toBe(notes); + }); +}); diff --git a/frontend/src/v2/utils/githubLinks.ts b/frontend/src/v2/utils/githubLinks.ts new file mode 100644 index 000000000..a246b2947 --- /dev/null +++ b/frontend/src/v2/utils/githubLinks.ts @@ -0,0 +1,22 @@ +// A bare pull request or issue URL, not one already inside a markdown link +// (as its text or its target) or an ``, and not a deeper page of it. +const REFERENCE_URL = + /(? { + const prefix = target.toLowerCase() === repo.toLowerCase() ? "" : target; + return `[${prefix}#${number}](${url})`; + }, + ); +} From a717e2e81a9698e200d625fca48091f8ea5696a4 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 22 Sep 2026 20:15:00 +0200 Subject: [PATCH 2/3] fix(v2): keep the changelog's link rewrite out of code and queries Addresses Greptile's review of #4705. The rewrite matched a reference anywhere but right after a link's bracket, so one written inside code was turned into markdown the preview then printed verbatim, and one inside a longer link label nested a link in a link. Code spans, fenced blocks and whole existing links are now matched first and handed back untouched. A trailing query no longer splits a reference either: `?` joins the guard that already kept `/files` and `#issuecomment-1` whole. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK --- frontend/src/v2/utils/githubLinks.test.ts | 20 +++++++++++++++++++- frontend/src/v2/utils/githubLinks.ts | 14 ++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/frontend/src/v2/utils/githubLinks.test.ts b/frontend/src/v2/utils/githubLinks.test.ts index 83a79a6e4..855d42dc5 100644 --- a/frontend/src/v2/utils/githubLinks.test.ts +++ b/frontend/src/v2/utils/githubLinks.test.ts @@ -43,7 +43,24 @@ describe("shortenGithubLinks", () => { // Rewriting these would nest a link inside a link. it("leaves a reference that is already a link alone", () => { - const notes = [`[the fix](${PR})`, `[${PR}](${PR})`, `<${PR}>`].join("\n"); + const notes = [ + `[the fix](${PR})`, + `[${PR}](${PR})`, + `[see ${PR} for the details](${PR})`, + `<${PR}>`, + ].join("\n"); + + expect(shortenGithubLinks(notes, REPO)).toBe(notes); + }); + + // Code reads as written, so a rewrite would show the markdown itself. + it("leaves a reference inside code alone", () => { + const notes = [ + `Compare it with \`${PR}\`:`, + "```sh", + `curl ${PR}`, + "```", + ].join("\n"); expect(shortenGithubLinks(notes, REPO)).toBe(notes); }); @@ -52,6 +69,7 @@ describe("shortenGithubLinks", () => { const notes = [ `${PR}/files`, `${PR}#issuecomment-1`, + `${PR}?diff=split`, "https://github.com/rommapp/romm/compare/5.0.0...5.1.0", ].join("\n"); diff --git a/frontend/src/v2/utils/githubLinks.ts b/frontend/src/v2/utils/githubLinks.ts index a246b2947..f01623098 100644 --- a/frontend/src/v2/utils/githubLinks.ts +++ b/frontend/src/v2/utils/githubLinks.ts @@ -1,7 +1,8 @@ -// A bare pull request or issue URL, not one already inside a markdown link -// (as its text or its target) or an ``, and not a deeper page of it. -const REFERENCE_URL = - /(?\s]*>)|https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:pull|issues)\/(\d+)(?![\w/#?])/g; /** * Rewrites bare pull request and issue URLs in `markdown` the way GitHub @@ -13,8 +14,9 @@ const REFERENCE_URL = */ export function shortenGithubLinks(markdown: string, repo: string): string { return markdown.replace( - REFERENCE_URL, - (url, target: string, number: string) => { + VERBATIM_OR_REFERENCE, + (url, verbatim: string | undefined, target: string, number: string) => { + if (verbatim !== undefined) return verbatim; const prefix = target.toLowerCase() === repo.toLowerCase() ? "" : target; return `[${prefix}#${number}](${url})`; }, From 62a44c44357341064f10c07b942e8bac6082bc55 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 22 Sep 2026 21:19:16 +0200 Subject: [PATCH 3/3] fix(v2): cap how far the changelog's link rewrite scans A `[` needs no closing bracket, so on notes carrying unclosed ones the skip-the-existing-link alternative scanned to the end of the text for each of them: quadratic, and measurably so, 2s over 100KB of them and 33s over 400KB. Capping the label and the target, far above the longest link the notes actually carry (134 characters), holds it to a line's worth of work per bracket: 42ms and 159ms for the same two, and the same output on every published release. Raised by @gantoine in review of #4705. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK --- frontend/src/v2/utils/githubLinks.test.ts | 11 +++++++++++ frontend/src/v2/utils/githubLinks.ts | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/src/v2/utils/githubLinks.test.ts b/frontend/src/v2/utils/githubLinks.test.ts index 855d42dc5..8cde0f6f6 100644 --- a/frontend/src/v2/utils/githubLinks.test.ts +++ b/frontend/src/v2/utils/githubLinks.test.ts @@ -75,4 +75,15 @@ describe("shortenGithubLinks", () => { expect(shortenGithubLinks(notes, REPO)).toBe(notes); }); + + // Without the caps on the link label and target this takes ~2s, four times + // that for twice the text: every unclosed bracket scans what follows it. + it("does not slow to a crawl on a flood of unclosed brackets", () => { + const notes = "[x".repeat(50_000); + + const started = performance.now(); + shortenGithubLinks(notes, REPO); + + expect(performance.now() - started).toBeLessThan(1_000); + }); }); diff --git a/frontend/src/v2/utils/githubLinks.ts b/frontend/src/v2/utils/githubLinks.ts index f01623098..83ac080c8 100644 --- a/frontend/src/v2/utils/githubLinks.ts +++ b/frontend/src/v2/utils/githubLinks.ts @@ -1,8 +1,12 @@ // Either a span that reads as written (code, or a link that is already one), // which the first alternative claims before the second can reach into it, or a // bare pull request / issue URL, which the trailing guard keeps to a plain one. +// +// A `[` needs no closing bracket, so an unclosed one would scan to the end of +// the notes and the search would cost O(n^2); the caps, far above any real +// label or URL, hold it to a line's worth of work per bracket. const VERBATIM_OR_REFERENCE = - /(```[\s\S]*?```|`[^`]*`|\[[^\]]*\]\([^)]*\)|<[^>\s]*>)|https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:pull|issues)\/(\d+)(?![\w/#?])/g; + /(```[\s\S]*?```|`[^`]*`|\[[^\]]{0,300}\]\([^)]{0,600}\)|<[^>\s]{0,600}>)|https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:pull|issues)\/(\d+)(?![\w/#?])/g; /** * Rewrites bare pull request and issue URLs in `markdown` the way GitHub