fix: guard against race condition in notebook find revealCellRange (#225578)#320405
Open
Mr-Ahmadi wants to merge 1 commit into
Open
fix: guard against race condition in notebook find revealCellRange (#225578)#320405Mr-Ahmadi wants to merge 1 commit into
Mr-Ahmadi wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a defensive guard in the notebook find model to avoid dereferencing an undefined match entry while revealing a cell range.
Changes:
- Add an early return in
revealCellRangewhen_findMatches[cellIndex]is missing.
Comment on lines
274
to
+278
| private async revealCellRange(cellIndex: number, matchIndex: number, outputOffset: number | null) { | ||
| const findMatch = this._findMatches[cellIndex]; | ||
| if (!findMatch) { | ||
| return; | ||
| } |
…icrosoft#225578) When find matches are being revealed and the underlying _findMatches array is replaced between the cellIndex computation and the async callback (e.g. via research() triggered by onDidChangeContent), findMatch can be undefined. Add an early return guard to prevent 'Cannot read properties of undefined (reading contentMatches)'. Fixes microsoft#225578
db606b1 to
4b50b99
Compare
Author
|
Thanks for the review. Both callers ( |
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 PR fixes #225578 — a TypeError where
contentMatchesis read onundefinedin notebookfindModel.ts.Root Cause
Both callers of
revealCellRange(find()andrefreshCurrentMatch()) call it inside a.then()callback afterhighlightCurrentFindMatchDecoration(). Between the synchronous computation ofcellIndexand execution of the microtask,this._findMatchescan be replaced byresearch()→set()(triggered byonDidChangeContentor other events), making the cachedcellIndexout of bounds.Fix
Added an early return guard in
revealCellRangewhenfindMatchis undefined, matching the defensive pattern used elsewhere in the codebase.Validation