From 0799fdedda8ce211529abe24a80b78a23007c72b Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Mon, 27 Oct 2025 21:06:01 -0700 Subject: [PATCH] perspective-workspace: safer isVisible() callbacks I've been seeing "cannot read properties of null" errors in these isVisible() callbacks while developing a React application which wraps ``. The error message details suggest getWidgetByName() is returning null at some point. Make these isVisible() callbacks safer with the null coalescing operator, to avoid null 'dereferences' when `getWidgetByName()` returns null. In this case, the command is considered not visible. I didn't pin down reliable repro steps. Although from a look at this code's context, it might be related to a viewer widget being deleted from the workspace, or perhaps the viewer being renamed, while at the same time Lumino is rendering workspace commands (such as in the context menu). Signed-off-by: Tom Jakubowski --- packages/workspace/src/ts/workspace/commands.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/workspace/src/ts/workspace/commands.ts b/packages/workspace/src/ts/workspace/commands.ts index bee24fc111..be0824e62a 100644 --- a/packages/workspace/src/ts/workspace/commands.ts +++ b/packages/workspace/src/ts/workspace/commands.ts @@ -154,9 +154,9 @@ export const createCommands = ( isVisible: (args) => { const target_widget = workspace.getWidgetByName( args.target_widget_name as string, - )!; + ); - return target_widget.title.label !== ""; + return target_widget?.title.label !== ""; }, label: (args) => { const target_widget = workspace.getWidgetByName( @@ -194,9 +194,9 @@ export const createCommands = ( isVisible: (args) => { const widget = workspace.getWidgetByName( args.widget_name as string, - )!; + ); - return widget.parent! === (workspace.get_dock_panel() as Widget) + return widget?.parent === (workspace.get_dock_panel() as Widget) ? true : false; }, @@ -220,8 +220,10 @@ export const createCommands = ( ), // iconClass: "menu-duplicate", isVisible: (args) => { - return workspace.getWidgetByName(args.widget_name as string)! - .parent! === (workspace.get_dock_panel() as Widget) + const parent = workspace.getWidgetByName( + args.widget_name as string, + )?.parent; + return parent === (workspace.get_dock_panel() as Widget) ? true : false; },