Skip to content

SCM - remove the usage of querySelector#276766

Merged
lszomoru merged 2 commits intomainfrom
lszomoru/young-fox
Nov 11, 2025
Merged

SCM - remove the usage of querySelector#276766
lszomoru merged 2 commits intomainfrom
lszomoru/young-fox

Conversation

@lszomoru
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings November 11, 2025 18:33
@lszomoru lszomoru enabled auto-merge (squash) November 11, 2025 18:33
@lszomoru lszomoru self-assigned this Nov 11, 2025
@lszomoru lszomoru added the scm General SCM compound issues label Nov 11, 2025
@lszomoru lszomoru added this to the November 2025 milestone Nov 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the SCM history view to remove the usage of querySelector for accessing twistie elements, replacing it with a simpler and more direct DOM navigation approach using previousElementSibling. This makes the code more maintainable and follows better practices by avoiding deep DOM traversal.

Key Changes:

  • Replaced querySelector calls with previousElementSibling to access twistie elements in two renderers
  • Updated CSS selector to be more specific by requiring the .force-no-twistie class

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts Replaced querySelector with previousElementSibling in HistoryItemRenderer and HistoryItemLoadMoreRenderer
src/vs/workbench/contrib/scm/browser/media/scm.css Made the twistie hiding CSS selector more specific by requiring the .force-no-twistie class

Comment on lines +448 to +449
// HACK - add .force-no-twistie class to the twistie element
container.previousElementSibling?.classList.add('force-no-twistie');
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The approach using previousElementSibling assumes a specific DOM structure that may be fragile. If the tree implementation changes and adds another sibling element before the twistie (e.g., between indent and twistie), this code will silently fail or add the class to the wrong element. Consider either: 1) Adding a runtime check to verify the element has the 'monaco-tl-twistie' class before adding 'force-no-twistie', or 2) Documenting this dependency on the tree's internal DOM structure with a reference to abstractTree.ts lines 409-414.

Suggested change
// HACK - add .force-no-twistie class to the twistie element
container.previousElementSibling?.classList.add('force-no-twistie');
// HACK: Add .force-no-twistie class to the twistie element if present.
// This depends on the tree's internal DOM structure: see abstractTree.ts lines 409-414.
const prev = container.previousElementSibling;
if (prev && prev.classList.contains('monaco-tl-twistie')) {
prev.classList.add('force-no-twistie');
}

Copilot uses AI. Check for mistakes.

renderTemplate(container: HTMLElement): LoadMoreTemplate {
// HACK - add .force-no-twistie class to the twistie element
container.previousElementSibling?.classList.add('force-no-twistie');
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The approach using previousElementSibling assumes a specific DOM structure that may be fragile. If the tree implementation changes and adds another sibling element before the twistie (e.g., between indent and twistie), this code will silently fail or add the class to the wrong element. Consider either: 1) Adding a runtime check to verify the element has the 'monaco-tl-twistie' class before adding 'force-no-twistie', or 2) Documenting this dependency on the tree's internal DOM structure with a reference to abstractTree.ts lines 409-414.

Suggested change
container.previousElementSibling?.classList.add('force-no-twistie');
const prev = container.previousElementSibling;
// Defensive: Only add if previous sibling is the twistie. See abstractTree.ts lines 409-414 for structure.
if (prev && prev.classList.contains('monaco-tl-twistie')) {
prev.classList.add('force-no-twistie');
}

Copilot uses AI. Check for mistakes.
@lszomoru lszomoru merged commit 78739a4 into main Nov 11, 2025
33 of 34 checks passed
@lszomoru lszomoru deleted the lszomoru/young-fox branch November 11, 2025 19:06
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

scm General SCM compound issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants