editor: don't lay out the editor part during state restore before it is shown#323342
Merged
Conversation
…is shown When restoring a working set into an editor part that has never been laid out (e.g. the Agents window editor area after a reload with the side pane closed), `_contentDimension` is still undefined. `doApplyGridState` called `doLayout(this._contentDimension)` unconditionally, which threw and aborted before the `onDidAddGroup` events were fired. The restored editor groups were therefore never registered with the editor service, so their `onWillOpenEditor` had no listeners and the Agents window never revealed the editor part when a Changes editor was opened. Guard the layout call so it only runs once the part has a content dimension; the grid is laid out later when the part is first shown. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @benibenjMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an editor working-set restore crash by avoiding an early layout pass when the editor part has never been laid out (hidden/not-yet-shown), ensuring restored groups still emit onDidAddGroup and get properly registered (notably impacting the Agents window restore flow).
Changes:
- Guard
EditorPart.doApplyGridStatelayout so it only runs when_contentDimensionis available. - Add a regression unit test that applies state into a never-laid-out editor part and asserts restore completes and group-added events fire.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/browser/parts/editor/editorPart.ts | Avoids calling doLayout during state restore when _contentDimension is still undefined, preventing a restore-time crash and ensuring group events still fire. |
| src/vs/workbench/services/editor/test/browser/editorGroupsService.test.ts | Adds a regression test covering state restore into an editor part that has never been laid out, validating no throw and that restored groups are registered via onDidAddGroup. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Low
Address PR review: tighten the never-laid-out restore test to assert exactly two onDidAddGroup events so unintended duplicate emissions during state restore are caught. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dbaeumer
approved these changes
Jun 28, 2026
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.
What
EditorPart.doApplyGridStatecalledthis.doLayout(this._contentDimension)unconditionally while applying an editor working set (state restore). When the editor part has never been laid out —_contentDimensionis stillundefined— that call throws (Cannot read properties of undefined (reading 'width')) and aborts the method before theonDidAddGroupevents are fired for the recreated groups.As a result, the restored editor groups are never registered with
IEditorService(itsonDidAddGroup→registerGroupListenersnever runs), so theironWillOpenEditorhas no listeners.This guards the layout call so it only runs when the part already has a content dimension. The grid is laid out later when the part is first shown.
Why
In the Agents window, the editor part can stay hidden across a reload (e.g. the user closed the whole side pane). On reload the per-session layout controller restores the session's editor working set into that still-hidden, never-laid-out editor part, hitting the crash above. Because the restored group was never registered with the editor service, the Agents window's
onWillOpenEditor-driven editor-part reveal never fired — so clicking Changes opened the editor into an orphaned group without ever revealing the editor part.Repro (Agents window):
Notes for reviewers
!this._contentDimensionguard already used elsewhere ineditorPart.ts(e.g.updateTopRightGroupContextKey)._contentDimensionis defined there and behavior is unchanged. This only affects the case where state is applied into a part that has never been shown.editorGroupsService.test.tsthat applies state into a never-laid-out part and asserts it does not throw and still firesonDidAddGroupfor the restored groups (verified it fails with the originalTypeErrorwithout the fix).Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com