From 17e43e255193a3500a0605fcee3277fa2ac8813b Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Fri, 6 Jun 2025 17:11:56 -0500 Subject: [PATCH] Fix race condition in pane container closing Fixes COMPILER-EXPLORER-3W3: Prevents 'Can't remove child item' errors when attempting to close containers that have already been destroyed or removed from the layout hierarchy. Uses modern TypeScript optional chaining to check container validity before attempting close operations, preventing race conditions between compiler close events and GoldenLayout's own destruction process. --- static/panes/pane.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/static/panes/pane.ts b/static/panes/pane.ts index df260f3cf..2405fdc48 100644 --- a/static/panes/pane.ts +++ b/static/panes/pane.ts @@ -227,7 +227,12 @@ export abstract class Pane { /** Close the pane if the compiler this pane was attached to closes */ protected onCompilerClose(compilerId: number) { if (this.compilerInfo.compilerId === compilerId) { - _.defer(() => this.container.close()); + _.defer(() => { + // Check if container is still valid before attempting to close + if (this.container?.parent && this.container.layoutManager?.isInitialised) { + this.container.close(); + } + }); } }