Skip to content

fix(copy-page): scope table cell queries to direct children - #3066

Open
dj-jarvis wants to merge 1 commit into
MetaMask:mainfrom
dj-jarvis:fix/copy-page-table-scope
Open

dj-jarvis wants to merge 1 commit into
MetaMask:mainfrom
dj-jarvis:fix/copy-page-table-scope

Conversation

@dj-jarvis

Copy link
Copy Markdown

Problem

In src/components/CopyPageButton/CopyPageButton.jsx, tableToMarkdown collected each row's cells with a descendant selector:

const firstRowCells = Array.from(rows[0].querySelectorAll('th, td'))
const cells = Array.from(tr.querySelectorAll('th, td')).map(td => td.textContent.trim())

'th, td' matches at any depth, not just direct children. The row selection a few lines above already uses :scope > correctly, so the two were inconsistent.

Impact

  • Shifted columns. For a table with a table nested inside a cell, the inner table's cells are DOM descendants of the outer <tr>. They get collected as extra columns, so the emitted row has more cells than the header row and is not valid Markdown.
  • Broken export everywhere. buildMarkdown() feeds the "Copy page as Markdown for LLMs", "View as Markdown", and "Open in Claude/ChatGPT/Perplexity" actions. A malformed table therefore reaches the clipboard, the preview window, and the AI query string, where the model can misread which value belongs to which parameter.
  • Fails silently. No exception and no log — the output is simply wrong, which makes the bug easy to miss.

Fix

Add :scope > to both cell selectors so only the row's own cells are used:

const firstRowCells = Array.from(rows[0].querySelectorAll(':scope > th, :scope > td'))
const cells = Array.from(tr.querySelectorAll(':scope > th, :scope > td')).map(td =>
  td.textContent.trim()
)

This aligns cell selection with the existing :scope > thead > tr row selection.

@dj-jarvis
dj-jarvis requested review from a team as code owners October 3, 2026 21:34
@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Consensys Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant