fix: cancel pane initial fit on dispose (#3395)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { ManagedPaneInternal } from './pane-manager-types'
|
||||
import { disposePane } from './pane-lifecycle'
|
||||
|
||||
function createPane(pendingInitialFitRafId: number | null): ManagedPaneInternal {
|
||||
const leafId = '11111111-1111-4111-8111-111111111111' as never
|
||||
return {
|
||||
id: 1,
|
||||
leafId,
|
||||
stablePaneId: leafId,
|
||||
terminal: {
|
||||
element: null,
|
||||
dispose: vi.fn()
|
||||
} as never,
|
||||
container: {} as never,
|
||||
xtermContainer: {} as never,
|
||||
linkTooltip: {} as never,
|
||||
terminalGpuAcceleration: 'off',
|
||||
gpuRenderingEnabled: false,
|
||||
webglAttachmentDeferred: false,
|
||||
webglDisabledAfterContextLoss: false,
|
||||
hasComplexScriptOutput: false,
|
||||
fitAddon: { dispose: vi.fn() } as never,
|
||||
fitResizeObserver: null,
|
||||
pendingInitialFitRafId,
|
||||
pendingObservedFitRafId: null,
|
||||
searchAddon: { dispose: vi.fn() } as never,
|
||||
serializeAddon: { dispose: vi.fn() } as never,
|
||||
unicode11Addon: { dispose: vi.fn() } as never,
|
||||
webLinksAddon: { dispose: vi.fn() } as never,
|
||||
webglAddon: null,
|
||||
ligaturesAddon: null,
|
||||
compositionHandler: null,
|
||||
pendingSplitScrollState: null,
|
||||
pendingSplitScrollBufferDisposable: null,
|
||||
debugLabel: null
|
||||
}
|
||||
}
|
||||
|
||||
describe('pane initial fit lifecycle', () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('cancels pending initial fit when the pane is disposed before paint', () => {
|
||||
const cancelAnimationFrame = vi.fn()
|
||||
vi.stubGlobal('cancelAnimationFrame', cancelAnimationFrame)
|
||||
const pane = createPane(17)
|
||||
const panes = new Map([[pane.id, pane]])
|
||||
|
||||
disposePane(pane, panes)
|
||||
|
||||
expect(cancelAnimationFrame).toHaveBeenCalledWith(17)
|
||||
expect(pane.pendingInitialFitRafId).toBeNull()
|
||||
expect(panes.has(pane.id)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -119,6 +119,7 @@ export function createPaneDOM(
|
||||
hasComplexScriptOutput: false,
|
||||
fitAddon,
|
||||
fitResizeObserver: null,
|
||||
pendingInitialFitRafId: null,
|
||||
pendingObservedFitRafId: null,
|
||||
searchAddon,
|
||||
serializeAddon,
|
||||
@@ -230,7 +231,11 @@ export function openTerminal(pane: ManagedPaneInternal): void {
|
||||
attachPaneFitResizeObserver(pane)
|
||||
|
||||
// Initial fit (deferred to ensure layout has settled)
|
||||
requestAnimationFrame(() => {
|
||||
if (pane.pendingInitialFitRafId != null) {
|
||||
cancelAnimationFrame(pane.pendingInitialFitRafId)
|
||||
}
|
||||
pane.pendingInitialFitRafId = requestAnimationFrame(() => {
|
||||
pane.pendingInitialFitRafId = null
|
||||
safeFit(pane)
|
||||
})
|
||||
}
|
||||
@@ -290,6 +295,10 @@ export function disposePane(
|
||||
pane: ManagedPaneInternal,
|
||||
panes: Map<number, ManagedPaneInternal>
|
||||
): void {
|
||||
if (pane.pendingInitialFitRafId != null) {
|
||||
cancelAnimationFrame(pane.pendingInitialFitRafId)
|
||||
pane.pendingInitialFitRafId = null
|
||||
}
|
||||
detachPaneFitResizeObserver(pane)
|
||||
if (pane.compositionHandler) {
|
||||
pane.terminal.element?.removeEventListener('compositionstart', pane.compositionHandler, true)
|
||||
|
||||
@@ -105,6 +105,8 @@ export type ManagedPaneInternal = {
|
||||
// value means "currently disabled".
|
||||
ligaturesAddon: LigaturesAddon | null
|
||||
fitResizeObserver: ResizeObserver | null
|
||||
// Stored so disposePane() can cancel the first post-open fit if a pane closes before paint.
|
||||
pendingInitialFitRafId?: number | null
|
||||
pendingObservedFitRafId: number | null
|
||||
serializeAddon: SerializeAddon
|
||||
unicode11Addon: Unicode11Addon
|
||||
|
||||
Reference in New Issue
Block a user