From a109ccfec8af214e615cbc3eb1fa25544e330b8f Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Thu, 10 Oct 2024 16:33:48 -0400 Subject: [PATCH] Fix new tab bug that would remove terminal block (#1006) --- frontend/layout/lib/layoutAtom.ts | 2 +- frontend/layout/lib/layoutModel.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/layout/lib/layoutAtom.ts b/frontend/layout/lib/layoutAtom.ts index 53d0526f2..d732ab146 100644 --- a/frontend/layout/lib/layoutAtom.ts +++ b/frontend/layout/lib/layoutAtom.ts @@ -43,7 +43,7 @@ export function withLayoutTreeStateAtomFromTab(tabAtom: Atom): WritableLayo waveObjVal.magnifiednodeid = value.magnifiedNodeId; waveObjVal.focusednodeid = value.focusedNodeId; waveObjVal.leaforder = value.leafOrder; // only set leaforder, never get it, since this value is driven by the frontend - waveObjVal.pendingbackendactions = value.pendingBackendActions?.length + waveObjVal.pendingbackendactions = value?.pendingBackendActions?.length ? value.pendingBackendActions : undefined; set(generationAtom, value.generation); diff --git a/frontend/layout/lib/layoutModel.ts b/frontend/layout/lib/layoutModel.ts index dc830047f..1288262bd 100644 --- a/frontend/layout/lib/layoutModel.ts +++ b/frontend/layout/lib/layoutModel.ts @@ -389,7 +389,7 @@ export class LayoutModel { ) { this.treeState = treeState; - if (this.treeState.pendingBackendActions?.length) { + if (this.treeState?.pendingBackendActions?.length) { const actions = this.treeState.pendingBackendActions; this.treeState.pendingBackendActions = undefined; for (const action of actions) { @@ -631,7 +631,7 @@ export class LayoutModel { // Remove duplicates and stale entries from focus stack. const newFocusedNodeIdStack: string[] = []; for (const id of this.focusedNodeIdStack) { - if (leafOrder.find((leafEntry) => leafEntry.nodeid === id) && !newFocusedNodeIdStack.includes(id)) + if (leafOrder.find((leafEntry) => leafEntry?.nodeid === id) && !newFocusedNodeIdStack.includes(id)) newFocusedNodeIdStack.push(id); } this.focusedNodeIdStack = newFocusedNodeIdStack; @@ -640,7 +640,7 @@ export class LayoutModel { if (!this.treeState.focusedNodeId) { if (this.focusedNodeIdStack.length > 0) { this.treeState.focusedNodeId = this.focusedNodeIdStack.shift(); - } else { + } else if (leafOrder.length > 0) { // If no nodes are in the stack, use the top left node in the layout. this.treeState.focusedNodeId = leafOrder[0].nodeid; }