Skip to content

check for parentNode before using#896

Open
Nikhil1489 wants to merge 1 commit intonamespace-ee:mainfrom
Nikhil1489:getSumScroll_Function_Issue
Open

check for parentNode before using#896
Nikhil1489 wants to merge 1 commit intonamespace-ee:mainfrom
Nikhil1489:getSumScroll_Function_Issue

Conversation

@Nikhil1489
Copy link

@Nikhil1489 Nikhil1489 commented Feb 2, 2023

in the getSumScroll function in the dom-helpers file
92423709-62ffbd00-f1c5-11ea-971a-d62971ccd68f

Error Traceback:

92423714-66934400-f1c5-11ea-9005-e457f6fa0b4d

@lnagel
Copy link
Member

lnagel commented Feb 5, 2026

@developer-ocansey — Flagging this for your review.

Recommendation: The bug still exists — apply as a quick fix to the current codebase

The bug

getSumScroll in dom-helpers.ts recursively traverses node.parentNode but doesn't guard against it being null. If a node is detached from the DOM or inside a shadow DOM, parentNode can be null, causing a crash on the next recursion.

The current code (line ~33 of dom-helpers.ts):

export function getSumScroll(node: HTMLElement): { scrollLeft: number; scrollTop: number } {
  if (node === document.body) {
    return { scrollLeft: 0, scrollTop: 0 }
  } else {
    const parent = getSumScroll(node.parentNode as HTMLElement)
    // ...
  }
}

Note that the sibling function getSumOffset already has an analogous guard (!node.offsetParent) at line ~50, so adding !node.parentNode to getSumScroll would be consistent.

Why it can't merge directly

The PR targets the old dom-helpers.js — the fix needs to be re-applied to dom-helpers.ts. It's a 1-line guard addition.

I'd suggest just applying the fix directly to dom-helpers.ts rather than trying to rebase this PR.

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.

3 participants