fix(diffEditor): guard against null model in diffEditorHelper#318316
Open
SpencerJung wants to merge 1 commit into
Open
fix(diffEditor): guard against null model in diffEditorHelper#318316SpencerJung wants to merge 1 commit into
SpencerJung wants to merge 1 commit into
Conversation
…oft#318310) The diffEditorHelper's 'Remove Limit' and 'Show Whitespace Differences' click handlers accessed getModel() with a non-null assertion, but the model can be null if disposed or not yet set. This caused 'Cannot read properties of null (reading modified)' errors. - Add null checks before accessing model.modified.uri - Skip the configuration update if no model is available Fixes microsoft#318310
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates Diff Editor helper actions to avoid relying on non-null assertions when reading the diff editor model, preventing potential runtime errors when the model is unavailable.
Changes:
- Replaced
getModel()!usage with null-checked access in whitespace-diff hint click handler. - Replaced
getModel()!usage with null-checked access in “Remove Limit” computation-time action.
Comment on lines
+48
to
+53
| store.add(helperWidget.onClick(() => { | ||
| const model = this._diffEditor.getModel(); | ||
| if (model) { | ||
| this._textResourceConfigurationService.updateValue(model.modified.uri, 'diffEditor.ignoreTrimWhitespace', false); | ||
| } | ||
| })); |
Comment on lines
+68
to
+71
| const model = this._diffEditor.getModel(); | ||
| if (model) { | ||
| this._textResourceConfigurationService.updateValue(model.modified.uri, 'diffEditor.maxComputationTime', 0); | ||
| } |
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.
Related Issue
Closes #318310
Summary
The diffEditorHelper's click handlers for "Remove Limit" and "Show Whitespace Differences" accessed
getModel()with a non-null assertion (!), but the model can be null if the diff editor model is disposed or not yet set. This causedCannot read properties of null (reading 'modified')errors when users clicked these buttons.Changes
model.modified.uriin both click handlersVerification Evidence
npm run compile-check-ts-native: PASSED (no TypeScript errors)Community Rules Review
Checklist