Skip to content

editor: don't lay out the editor part during state restore before it is shown#323342

Merged
sandy081 merged 2 commits into
mainfrom
sandy081/fix-editor-part-restore-hidden
Jun 28, 2026
Merged

editor: don't lay out the editor part during state restore before it is shown#323342
sandy081 merged 2 commits into
mainfrom
sandy081/fix-editor-part-restore-hidden

Conversation

@sandy081

Copy link
Copy Markdown
Member

What

EditorPart.doApplyGridState called this.doLayout(this._contentDimension) unconditionally while applying an editor working set (state restore). When the editor part has never been laid out_contentDimension is still undefined — that call throws (Cannot read properties of undefined (reading 'width')) and aborts the method before the onDidAddGroup events are fired for the recreated groups.

As a result, the restored editor groups are never registered with IEditorService (its onDidAddGroupregisterGroupListeners never runs), so their onWillOpenEditor has 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):

  1. Open a session, click Changes (editor + aux bar visible), open the sessions list (all four parts visible).
  2. Toggle the side pane closed (hides editor + aux bar).
  3. Reload the window.
  4. Click Changes → editor part did not open.

Notes for reviewers

  • The fix mirrors the existing defensive !this._contentDimension guard already used elsewhere in editorPart.ts (e.g. updateTopRightGroupContextKey).
  • Low risk for the main workbench: the main editor part is always laid out at startup, so _contentDimension is defined there and behavior is unchanged. This only affects the case where state is applied into a part that has never been shown.
  • Added a regression unit test in editorGroupsService.test.ts that applies state into a never-laid-out part and asserts it does not throw and still fires onDidAddGroup for the restored groups (verified it fails with the original TypeError without the fix).

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…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>
Copilot AI review requested due to automatic review settings June 28, 2026 13:13
@sandy081 sandy081 self-assigned this Jun 28, 2026
@sandy081 sandy081 enabled auto-merge (squash) June 28, 2026 13:14
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@benibenj

Matched files:

  • src/vs/workbench/browser/parts/editor/editorPart.ts
  • src/vs/workbench/services/editor/test/browser/editorGroupsService.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.doApplyGridState layout so it only runs when _contentDimension is 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

Comment thread src/vs/workbench/services/editor/test/browser/editorGroupsService.test.ts Outdated
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>
@sandy081 sandy081 merged commit b2e8d2a into main Jun 28, 2026
29 checks passed
@sandy081 sandy081 deleted the sandy081/fix-editor-part-restore-hidden branch June 28, 2026 15:29
@vs-code-engineering vs-code-engineering Bot added this to the 1.127.0 milestone Jun 28, 2026
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.

3 participants