Skip to content

Don't open two browser tabs when clicking the pull request number - #8962

Merged
Alex Ross (alexr00) merged 5 commits into
microsoft:mainfrom
L4XB:fix/8955-pr-number-opens-two-tabs
Oct 8, 2026
Merged

Alex Ross (alexr00) merged 5 commits into
microsoft:mainfrom
L4XB:fix/8955-pr-number-opens-two-tabs

Conversation

@L4XB

@L4XB Lukas (L4XB) commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8955

Cause

Not #8919, which the issue guesses at — that PR does not touch link handling. The
regression is 02ac4de ("Fix various things in the webview that don't work correctly in
Agents window", #8935), which fixed #8934 by giving the #<number> links in
webviews/components/header.tsx and webviews/components/stickyHeader.tsx an onClick:

onClick={event => {
	event.preventDefault();
	void openOnGitHub();
}}

Both anchors keep their href, and the webview host opens any anchor with an href on its
own. handleInnerClick in
src/vs/workbench/contrib/webview/browser/pre/index.html (microsoft/vscode) is registered
with contentWindow.addEventListener('click', handleInnerClick) and posts did-click-link
for the first anchor in the click's composed path. It does not check
event.defaultPrevented — the contextmenu handler registered a few lines below it does.
React 16 delegates onClick at document, so preventDefault() runs and the event then
carries on bubbling to the content window, where the host handler runs regardless.

One click therefore produces two opens:

  • did-click-link → IOpenerService.open
  • pr.openOnGitHub → openItemOnGitHub (src/commands.ts) → openWithDefaultExternalOpener

With githubPullRequests.openPullLinks off — its default since #8942 — nothing claims the
first one, so both reach the browser: the two tabs in the report. With the setting on, the
extension's own external URI opener claims the did-click-link and re-reveals the overview
instead, so the duplicate is less visible but still there.

These two anchors are the only ones under webviews/ that carry both an href and an
onClick; every other <a onClick> in the tree has no href, which is why they were never
affected.

Fix

Stop the click from reaching the host, so exactly one code path opens the URL.
webviews/editorWebview/app.tsx already does this for code reference links, with a
capture-phase listener that calls preventDefault() and stopPropagation().

Keeping the href preserves the hover target, keyboard activation and the copy-link context
menu; dropping the onClick instead would bring #8934 back, so the Agents-window path stays
exactly as #8935 left it.

Arguably the deeper defect is that handleInnerClick should honour defaultPrevented the
way the neighbouring contextmenu handler does. That lives in microsoft/vscode, so this
change does not wait on it.

Test

webviews/editorWebview/test/overview.test.tsx gains opens a PR number link exactly once.
It registers the host's behaviour on window: it opens any anchor with an href that the click reaches, without checking defaultPrevented. The test then clicks each number link and asserts one openOnGitHub call and no host open, so exactly one external open per click.

Update after merging main (35ab0ca): main now runs the webview tests in npm test through test:webviews (scripts/test-webviews.js), so the section that used to be here, saying these tests ran nowhere, no longer applies. main also moved the title's number link into TitleText (#9009), and the fix moved with it. On this branch, node scripts/test-webviews.js gives 39 passing, 0 failing, including the new test and applies deferred pull request updates, which used to fail on its own. With the stopPropagation() in TitleText removed, the new test fails (38 passing, 1 failing).

Validation

  • npm run compile — success (extension:node, extension:webworker, webviews)
  • npm run lint — exit 0, no files changed
  • npm run hygiene — exit 0
  • npm run check:commands — all declared commands are registered
  • npm test — 559 passing, 0 failing (test:scripts 75 passing, extension host suite exit 0)
  • npx tsc --noEmit for tsconfig.json, tsconfig.webviews.json and tsconfig.test.json — all clean

File and line references are against main @ 2f06150a, and microsoft/vscode main @
f80869ac.

02ac4de gave the pull request number links in the overview header and the
sticky header an onClick that calls preventDefault and opens the item on
GitHub, so that the link also works in the Agents window. The webview host
opens any anchor with an href as well, and its click handler does not check
defaultPrevented, so in a regular window the click is handled twice and the
browser gets two tabs for the same URL.

Stop the click from reaching the host, the way the code reference link handler
in webviews/editorWebview/app.tsx already does.

Fixes microsoft#8955
Copilot AI lite review requested due to automatic review settings September 16, 2026 12:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…ens-two-tabs

main moved the title's PR number link into TitleText (microsoft#9009), so the
stopPropagation this branch adds to that link moves with it. The test
file keeps both sides' new tests.
Copilot AI lite review requested due to automatic review settings October 5, 2026 14:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Reconcile webview test-runner behavior and address the potentially failing test before approval.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread webviews/editorWebview/test/overview.test.tsx

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR (and for your patience)!

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR (and for your patience)!

@alexr00
Alex Ross (alexr00) enabled auto-merge (squash) October 8, 2026 12:59
@alexr00 Alex Ross (alexr00) added this to the 1.142.0 milestone Oct 8, 2026
Copilot AI lite review requested due to automatic review settings October 8, 2026 13:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

All reviewed changes are covered by regression tests with no unresolved issues.

0 open findings

1 resolved since last review

🧠 Review effort: Lite


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@alexr00

Copy link
Copy Markdown
Member

/AzurePipelines run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.

@alexr00
Alex Ross (alexr00) merged commit b6d319e into microsoft:main Oct 8, 2026
3 checks passed
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.

clicking PR number opens two github tabs since 0.166.0 Pressing on the PR link in the agents window doesn't open the browser

4 participants