Skip to content

fix(diffEditor): guard against null model in diffEditorHelper#318316

Open
SpencerJung wants to merge 1 commit into
microsoft:mainfrom
SpencerJung:fix/318310-diff-helper-null-model
Open

fix(diffEditor): guard against null model in diffEditorHelper#318316
SpencerJung wants to merge 1 commit into
microsoft:mainfrom
SpencerJung:fix/318310-diff-helper-null-model

Conversation

@SpencerJung
Copy link
Copy Markdown

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 caused Cannot read properties of null (reading 'modified') errors when users clicked these buttons.

Changes

  • Added null checks before accessing model.modified.uri in both click handlers
  • The configuration update is skipped if no model is available

Verification Evidence

  • npm run compile-check-ts-native: PASSED (no TypeScript errors)
  • No additional tests needed (defensive null guard)

Community Rules Review

  • CONTRIBUTING.md reviewed; it points code contributors to the VS Code wiki.
  • Base branch: main

Checklist

  • Base branch is main
  • No unauthorized version bump
  • All feasible verification checks attempted
  • No unintended schema or lockfile changes

…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
Copilot AI review requested due to automatic review settings May 26, 2026 09:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
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.

Cannot read properties of null (reading 'modified')

3 participants