From a178aaade2287d432c614fb8cb2d3ea6db951428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 30 Sep 2026 14:48:42 +0200 Subject: [PATCH] Only prepare code blocks inside each Markdown block Every Markdown instance searched the whole page, so code blocks got an extra wrapper and copy button for each other Markdown block on the page. --- src/components/Markdown.svelte | 2 +- tests/e2e/repo/issue.spec.ts | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/Markdown.svelte b/src/components/Markdown.svelte index f91c28f8c..e9df8e545 100644 --- a/src/components/Markdown.svelte +++ b/src/components/Markdown.svelte @@ -155,7 +155,7 @@ // Replaces code blocks in the background with highlighted code. const prefix = "language-"; - const nodes = Array.from(document.body.querySelectorAll("pre code")); + const nodes = Array.from(container.querySelectorAll("pre code")); const treeChanges: Promise[] = []; diff --git a/tests/e2e/repo/issue.spec.ts b/tests/e2e/repo/issue.spec.ts index ee276b813..074aa6c76 100644 --- a/tests/e2e/repo/issue.spec.ts +++ b/tests/e2e/repo/issue.spec.ts @@ -149,3 +149,28 @@ test("shortcut does not submit an empty comment", async ({ page }) => { await expect(input).toHaveValue(" "); await expect(comments).toHaveCount(2); }); + +test("each code block gets one copy button", async ({ page }) => { + await page.goto(`/repos/${cobRid}/issues`); + await page.getByRole("button", { name: "New" }).click(); + await page.getByPlaceholder("Title").fill("Code blocks in two places"); + await page + .getByPlaceholder("Description") + .fill("First:\n\n```js\nconsole.log('one')\n```"); + await page.getByRole("button", { name: /^Save/ }).click(); + await expect( + page.getByRole("button", { name: "Code blocks in two places" }), + ).toBeVisible(); + + // A second Markdown block on the page used to wrap the first one's code + // again. + await page + .getByPlaceholder("Leave a comment") + .fill("Second:\n\n```js\nconsole.log('two')\n```"); + await page.getByRole("button", { name: /^Comment/ }).click(); + + await expect(page.locator("pre")).toHaveCount(2); + await expect(page.locator(".pre-wrapper")).toHaveCount(2); + await expect(page.locator(".pre-wrapper radicle-clipboard")).toHaveCount(2); + await expect(page.locator(".pre-wrapper .pre-wrapper")).toHaveCount(0); +});