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.
This commit is contained in:
Matt Godbolt
2025-06-06 17:11:56 -05:00
parent f8974b4f5f
commit 17e43e2551
+6 -1
View File
@@ -227,7 +227,12 @@ export abstract class Pane<S> {
/** 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();
}
});
}
}