fix(entry): prevent TypeError when scrolling to comment box#1238
Open
sentry[bot] wants to merge 1 commit into
Open
fix(entry): prevent TypeError when scrolling to comment box#1238sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Greptile SummaryAdds optional chaining (
Confidence Score: 5/5Single-line defensive guard on a DOM lookup — safe to merge. The change adds a null-safety guard ( Files Needing Attention: No files require special attention.
|
| 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
Reviews (1): Last reviewed commit: "fix(entry): prevent TypeError when scrol..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
scrollIntoViewmethod was called ondocument.getElementsByClassName("comment-box")[0]without ensuring that the element actually existed in the DOM. If the comments section or the targetcomment-boxelement had not yet rendered or was not present,[0]would returnundefined, leading to the TypeError.The fix introduces optional chaining (
?.) to thescrollIntoViewcall. This ensures that the method is only invoked if thecomment-boxelement is successfully found, preventing the error and gracefully handling cases where the element might not be immediately available.Fixes ECENCY-NEXT-1GJG