Repository navigation
canvases: reveal native canvas view only after its bounds are applied - #343516
Merged
Ulugbek Abdullaev (ulugbekna) merged 2 commits intoOct 22, 2026
Merged
Conversation
Follow-up to #343491. `CanvasEditor.layout` sent bounds via the async `model.layout` and revealed the native view immediately, relying on in-order IPC delivery for the bounds to land first. Reveal only after `model.layout` resolves, keep the view hidden when it rejects, and use a layout sequence so a superseded completion cannot reveal after a newer layout, a hide, or a model change. The completion re-measures the pane so an editor part hidden while bounds were in flight stays hidden. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dirk Bäumer (dbaeumer)
previously approved these changes
Oct 22, 2026
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
Visibility is toggled in_layoutAndReveal, but unlike the previous implementation, there is no… · New After awaitingmodel.layout(bounds), the code re-measures onlyvisiblebut does not verify that… · New Theshow()helper registers the animation-frame disposable intostore. Ifstoreis disposed… · New
What changed in this PR
Defers revealing the native canvas BrowserView until after its async model.layout(...) has applied bounds, preventing one-frame flashes at stale bounds.
Changes:
- Move reveal logic into an async
_layoutAndRevealthat runs aftermodel.layout(...)resolves and is guarded bylayoutSequence. - Rework layout measurement into
_measure()returning{ rect, bounds, visible }, and updatepresentationVisibleonly when the view is actually revealed. - Extend
CanvasEditortests with deferred-layout plumbing and new cases covering pending layouts, rejection, hides, and model detaches.
| File | Description |
|---|---|
| src/vs/workbench/contrib/canvases/electron-browser/canvasEditor.ts | Introduces sequence-guarded async reveal-after-layout and separates measurement from layout application. |
| src/vs/workbench/contrib/canvases/test/electron-browser/canvasEditor.test.ts | Adds deterministic deferred layout testing and new coverage for async ordering and cancellation scenarios. |
Review effort: Lite
| // The pane can be hidden or moved off-screen without a new layout while the bounds are applied. | ||
| const visible = applied && this._measure().visible; | ||
| this.presentationVisible.set(visible, undefined); | ||
| this.host.setVisible(visible); |
Comment on lines
+323
to
+337
| try { | ||
| await model.layout(bounds); | ||
| applied = true; | ||
| } catch (error) { | ||
| this.logService.error('[CanvasEditor] Failed to layout canvas', error); | ||
| } | ||
| if (sequence !== this.layoutSequence || this.model !== model) { | ||
| return; | ||
| } | ||
| // The pane can be hidden or moved off-screen without a new layout while the bounds are applied. | ||
| const visible = applied && this._measure().visible; | ||
| this.presentationVisible.set(visible, undefined); | ||
| this.host.setVisible(visible); | ||
| } | ||
|
|
| /** Shows the pane and lets its scheduled layout run, so no layout is pending afterwards. */ | ||
| show: async () => { | ||
| editor.setVisible(true); | ||
| await new Promise<void>(resolve => store.add(scheduleAtNextAnimationFrame(getWindow(parent), () => resolve()))); |
`WebContentsViewHost.layout` refreshes the overlay-obscured state and can reveal a host that is visible but was obscured. Running it before the new bounds were sent could reveal a resized canvas at its old bounds when the resize moved it out from under a notification. Run it in the layout completion, after the bounds are applied and before revealing; the hidden path still hides first and refreshes synchronously. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dirk Bäumer (dbaeumer)
approved these changes
Oct 22, 2026
Ulugbek Abdullaev (ulugbekna)
enabled auto-merge (squash)
October 22, 2026 15:00
Contributor
Ulugbek Abdullaev (ulugbekna)
deleted the
ulugbekna-canvas-reveal-after-layout
branch
October 22, 2026 15:17
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.


Follow-up to #343491, addressing the Copilot review comment r4348785085.
Problem
After #343491,
CanvasEditor.layout()sent bounds with the asyncmodel.layout(...)and then revealed the native view right away withhost.setVisible(true). Today the bounds still land first:BrowserViewModel.layout/setVisibleforward over the same IPC channel, and the main-processBrowserView.layout/setVisibleapply synchronously. But that ordering was only implied. Iflayoutever completes after anawait, the view could be revealed at stale bounds, which is the one-frame flash #343491 fixed.Change
In
canvasEditor.ts:layout()still measures and positions the container synchronously, and still hides immediately with no bounds when the pane is hidden, 0×0 or off-screen. The reveal now happens in_layoutAndReveal, aftermodel.layout(...)resolves.host.layout()) also waits for that completion and runs just before the reveal. It can reveal a visible host that was obscured, so running it earlier could show a resized canvas at its old bounds once the resize moved it out from under a notification. The hidden path still hides first and refreshes synchronously.layoutSequencegeneration is bumped by everylayout(), bysetEditorVisible(false)and by_setModel(attach, detach,clearInput, dispose). A completion reveals only if it is still the latest layout for the same model, so a newer layout, a hide or a model change supersedes it.display: none) while bounds were in flight stays hidden.model.layoutrejects, the error is logged and the current view is hidden instead of being revealed at bounds that were never applied.presentationVisible(read by the accessible view to decide whether to focus) becomes true only when the view is actually revealed, and is reset on model changes.A view that is already visible stays visible while a resize layout is in flight, so sash drags don't flicker. A first reveal now waits for one extra
layoutIPC round trip.Tests
CanvasEditorsuite incanvasEditor.test.ts: the fake model'slayoutcan now be deferred (DeferredPromise), and ashow()helper drains the scheduled visible layout so the tests are deterministic. New tests cover:Two existing ordering tests now await the asynchronous reveal. Against the previous
canvasEditor.ts, the new reveal tests and the updated "pane becomes visible again" test fail; with this change all 18 pass. The harness also recordshost.layout, so the snapshots check the overlay-refresh ordering. The new resize test fails against the first commit of this PR (cfde70d). That commit ranhost.layout()before sending bounds; a code review caught it.Validation
All commands were run under Node 24.22.0.
npm run install-fast: passednpm run build-fast -- --client-only: passed./scripts/test.sh --run src/vs/workbench/contrib/canvases/test/electron-browser/canvasEditor.test.ts --run src/vs/workbench/contrib/canvases/test/electron-browser/canvasEditorTelemetry.test.ts --run src/vs/workbench/contrib/canvases/test/electron-browser/canvasService.test.ts --run src/vs/workbench/contrib/canvases/test/electron-browser/canvasCommands.test.ts --run src/vs/workbench/contrib/canvases/test/electron-browser/editorCanvasContextService.test.ts --run src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasWorkingSet.test.ts --run src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasService.test.ts: passed (98 passing, 0 failing)npm run eslint -- src/vs/workbench/contrib/canvases/electron-browser/canvasEditor.ts src/vs/workbench/contrib/canvases/test/electron-browser/canvasEditor.test.ts: passednpm run typecheck-client: passedNot run: no manual real-app re-run of the A→B session-switch flash scenario for this follow-up. The unit tests cover the ordering.