Repository navigation
fix: guard notebook cursor-selection reveal during cell disposal (fixes #328986) - #329000
Conversation
microsoft#328986) Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts:383
- This inline explanation still exceeds the project's one-line hard limit for method-body comments. Condense it to the non-obvious lifecycle constraint.
// Do not react to selection changes once the cell is being disposed. Disposal
// synchronously detaches the text editor (see `dispose` -> `detachTextEditor`),
// which fires cursor/decoration events while a list render transaction may still
// be active. Revealing the cell here would re-enter `ListView.render` and throw
// "Already in transaction".
…ent to one line Co-authored-by: Copilot <[email protected]>
Driver cycle recordederrors-fix-driver:cycle head:ce44cd5932d484769d866e6405776b9bd4437779 |
|
The required checks Screenshots & Tests and Playwright Fixture Tests failed; both are unrelated to this notebook cell disposal guard (flaky infra), and the driver lacks |
|
The required checks Screenshots & Tests (failed in ~2s — infra/harness, never reached the test body) and Playwright Fixture Tests (flaky E2E) failed again on the latest run; both are unrelated to this 5-line notebook disposal guard and need a manual rerun, as the driver lacks |
b01bd04
into
microsoft:main

Summary
RowCache.transactthrows "Already in transaction" (rowCache.ts:63) becauseListView.renderis re-entered while an outer render transaction is still active. The re-entry originates in a notebook code cell being disposed:CodeCell.dispose()sets_isDisposed = trueand then synchronously detaches the text editor, which fires anonDidChangeCursorSelectionevent whose listener is still registered. That listener callsrevealRangeInViewAsync, which updates element height and re-entersListView.render→RowCache.transacta second time, throwing. New anomaly in 1.131.0 (absent in 1.130.0), ~1182 affected users, component "notebook cell list".Fixes #328986
Recommended reviewer:
@DonJayamanneCulprit Commit
The re-entrancy surfaced through the notebook cell layout/reveal reworks landing in the 1.131.0 window, authored by
@DonJayamanneoncodeCell.ts(e.g.a45fa66"Fix notebook cell height on opening notebooks",d87d06f"Fix Notebook Cell Editor height calc when pasting and scrolling"). These changes tightened the layout/reveal path that runs from the cursor-selection listener but did not add a disposal guard before the reveal call, allowing the listener to fire during disposal-drivendetachTextEditor(). The underlyingtransactre-entrancy assertion itself dates to4133f2d(rowCache transactions), but that is the detector, not the regression.Code Flow
Affected Files
src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts— theonDidChangeCursorSelectionlistener (producer of the re-entrant reveal). Modified.src/vs/base/browser/ui/list/rowCache.ts— crash site (transact); NOT modified.src/vs/base/browser/ui/list/listView.ts—render/updateElementHeightre-entry path; NOT modified.src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts—_revealRangeCommon; NOT modified.Repro Steps
detachTextEditor()firesonDidChangeCursorSelection; the reveal re-entersListView.renderand throws "Already in transaction".How the Fix Works
Chosen approach (
codeCell.ts): add an earlyif (this._isDisposed) { return; }at the very top of theonDidChangeCursorSelectionlistener, before it can reachrevealRangeInViewAsync. This is a fix at the data producer — the disposing cell is what emits the re-entrant reveal.dispose()sets_isDisposed = truebefore callingdetachTextEditor(), so the flag is already true when the synchronous cursor event fires; the guard therefore reliably prevents the disposing cell from initiating a reveal/relayout while the outer render transaction is active. The pre-existing_isDisposedcheck at line 405 only covered the height-change branch and fell through to the unconditional reveal at line 410; this hoists the check to cover the whole handler. After this change,codeCell.tscannot produce a re-entrantrevealRangeInViewAsynccall during disposal because the listener returns immediately once_isDisposedis set, soListView.renderis never re-entered.This is a lifecycle guard clause, not a try/catch, and it does not touch the crash site (
rowCache.ts), thelogService.errortelemetry path, or any typed utility body.Alternatives considered:
_revealRangeCommon/revealRangeInCellinnotebookCellList.tsagainstinRenderingTransaction— rejected: that guards a consumer downstream of the real producer (the disposing cell's listener) and would silently suppress legitimate reveals requested during a render, masking rather than fixing the disposal race.rowCache.ts— rejected: that is the crash site and would swallow the assertion that legitimately detects re-entrant transactions.Recommended Owner
@DonJayamanne— primary author ofcodeCell.tsand the notebook cell layout/reveal logic whose 1.131.0 changes exercise this path.errors-fix-driver — cycle 1
Trigger: cron_review_comments · Head:
6f47d1f44b621d40baff73a6d4a472532bcec923(6f47d1f)codeCell.ts:383(in scope)6f47d1f(replied + resolved)VS Code PR Check,Community PR ApprovalsPush: yes —
6f47d1f· Copilot rerequested: okReady gate: ci pending after push → not marking ready this cycle