Skip to content

canvases: reveal native canvas view only after its bounds are applied - #343516

Merged
Ulugbek Abdullaev (ulugbekna) merged 2 commits into
mainfrom
ulugbekna-canvas-reveal-after-layout
Oct 22, 2026
Merged

Ulugbek Abdullaev (ulugbekna) merged 2 commits into
mainfrom
ulugbekna-canvas-reveal-after-layout

Conversation

@ulugbekna

@ulugbekna Ulugbek Abdullaev (ulugbekna) commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #343491, addressing the Copilot review comment r4348785085.

Problem

After #343491, CanvasEditor.layout() sent bounds with the async model.layout(...) and then revealed the native view right away with host.setVisible(true). Today the bounds still land first: BrowserViewModel.layout/setVisible forward over the same IPC channel, and the main-process BrowserView.layout/setVisible apply synchronously. But that ordering was only implied. If layout ever completes after an await, 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, after model.layout(...) resolves.
  • In the visible path, the host overlay refresh (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.
  • A layoutSequence generation is bumped by every layout(), by setEditorVisible(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.
  • On completion the pane is re-measured, so an editor part hidden (display: none) while bounds were in flight stays hidden.
  • If model.layout rejects, 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 layout IPC round trip.

Tests

CanvasEditor suite in canvasEditor.test.ts: the fake model's layout can now be deferred (DeferredPromise), and a show() helper drains the scheduled visible layout so the tests are deterministic. New tests cover:

  • no reveal until layout resolves
  • an overlay refresh during a resize waits for the new bounds
  • rejection keeps the view hidden and logs
  • only the latest pending layout reveals
  • hiding the pane while a layout is pending
  • detaching the model while a layout is pending
  • hiding the editor part while a layout is pending

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 records host.layout, so the snapshots check the overlay-refresh ordering. The new resize test fails against the first commit of this PR (cfde70d). That commit ran host.layout() before sending bounds; a code review caught it.

Validation

All commands were run under Node 24.22.0.

  • npm run install-fast: passed
  • npm 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: passed
  • npm run typecheck-client: passed

Not 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.

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>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:30

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.

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
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 _layoutAndReveal that runs after model.layout(...) resolves and is guarded by layoutSequence.
  • Rework layout measurement into _measure() returning { rect, bounds, visible }, and update presentationVisible only when the view is actually revealed.
  • Extend CanvasEditor tests 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>
@github-actions

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: a70aac7d Current: e1bb4241

Changed (1)

sessions/artifactDetails/CommentsInformation/Light
Before After
before after

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