fix(terminal): clear stale parked frame on empty snapshot

This commit is contained in:
Brennan Benson
2026-08-05 14:23:59 -07:00
parent dcdde2a285
commit 72de2f6765
2 changed files with 21 additions and 2 deletions
@@ -889,6 +889,25 @@ describe('createRemoteRuntimePtyTransport', () => {
transport.destroy?.()
})
it('forwards an empty authoritative snapshot so a cached parked viewport clears', async () => {
const { createRemoteRuntimePtyTransport } = await import('./remote-runtime-pty-transport')
const onReplayData = vi.fn()
const transport = createRemoteRuntimePtyTransport('env-1', {
worktreeId: 'wt-1',
tabId: 'web-terminal-host-tab-1',
leafId: 'pane:1'
})
const connect = transport.connect({ url: '', callbacks: { onReplayData } })
await vi.waitFor(() => expect(subscriptionSendBinary).toHaveBeenCalled())
emitSnapshot(latestSubscribePayload().streamId, '')
await connect
expect(onReplayData).toHaveBeenCalledOnce()
expect(onReplayData).toHaveBeenCalledWith('')
transport.destroy?.()
})
it('keeps the current mirror input queue when an older connect settles', async () => {
const healthyRuntimeCall = runtimeCall.getMockImplementation()
let releaseFirstActivation = (): void => {}
@@ -1858,8 +1858,8 @@ export function createRemoteRuntimePtyTransport(
}
},
onSnapshot: (data, meta) => {
// Why: an empty snapshot can still carry a pending mid-escape tail that must replay so the next live chunk completes it.
if ((data || meta?.pendingEscapeTailAnsi) && isCurrentSubscription()) {
// Why: an empty snapshot is still authoritative and must clear a cached parked viewport.
if (isCurrentSubscription()) {
if (subscribedPtyId && bufferPtyShutdownReplayData(subscribedPtyId, data)) {
return
}