Skip to content

fix(entry): prevent TypeError when scrolling to comment box#1238

Open
sentry[bot] wants to merge 1 commit into
developfrom
seer/fix/entry-scroll-into-view
Open

fix(entry): prevent TypeError when scrolling to comment box#1238
sentry[bot] wants to merge 1 commit into
developfrom
seer/fix/entry-scroll-into-view

Conversation

@sentry

@sentry sentry Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

This commit addresses a TypeError: Cannot read properties of undefined (reading 'scrollIntoView') that occurred when clicking the 'Quote' button in the selection popover.

The error happened because the scrollIntoView method was called on document.getElementsByClassName("comment-box")[0] without ensuring that the element actually existed in the DOM. If the comments section or the target comment-box element had not yet rendered or was not present, [0] would return undefined, leading to the TypeError.

The fix introduces optional chaining (?.) to the scrollIntoView call. This ensures that the method is only invoked if the comment-box element is successfully found, preventing the error and gracefully handling cases where the element might not be immediately available.

Fixes ECENCY-NEXT-1GJG

@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown

Greptile Summary

Adds optional chaining (?.) to a scrollIntoView call inside the Quote button's click handler in SelectionPopover, preventing a TypeError crash when the comment-box DOM element has not yet rendered (or is not present on the page) at the time the user clicks.

  • The fix is minimal, targeted, and correct — document.getElementsByClassName("comment-box")[0] returns undefined when the class is absent, and ?.scrollIntoView now safely no-ops in that case instead of throwing.
  • No behavioral change for the happy path where the comment-box element is already in the DOM.

Confidence Score: 5/5

Single-line defensive guard on a DOM lookup — safe to merge.

The change adds a null-safety guard (?.) to a scrollIntoView call that was previously crashing when the target element was absent. The fix is correct, narrow in scope, and has no side effects on the happy path.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
apps/web/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/selection-popover/index.tsx Adds optional chaining to guard the scrollIntoView call when comment-box element is absent from the DOM, fixing a TypeError crash.

Sequence Diagram

sequenceDiagram
    participant User
    participant SelectionPopover
    participant onQuotesClick
    participant DOM

    User->>SelectionPopover: Click "Quote" button
    SelectionPopover->>SelectionPopover: setSelectedText("")
    SelectionPopover->>onQuotesClick: onQuotesClick(selectedText)
    SelectionPopover->>DOM: getElementsByClassName("comment-box")[0]
    alt element exists
        DOM-->>SelectionPopover: HTMLElement
        SelectionPopover->>DOM: "scrollIntoView({ block: "center" })"
    else element not found (undefined)
        DOM-->>SelectionPopover: undefined
        Note over SelectionPopover: ?. optional chaining skips scrollIntoView
    end
Loading

Reviews (1): Last reviewed commit: "fix(entry): prevent TypeError when scrol..." | Re-trigger Greptile

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.

0 participants