diff --git a/lib/diagnostics_channel.js b/lib/diagnostics_channel.js index 61d310d383a..2d37336e373 100644 --- a/lib/diagnostics_channel.js +++ b/lib/diagnostics_channel.js @@ -100,10 +100,10 @@ class RunStoresScope { #stack; constructor(activeChannel, data) { - using stack = new DisposableStack(); + if (activeChannel._stores?.size) { + using stack = new DisposableStack(); - // Enter stores using withScope - if (activeChannel._stores) { + // Enter stores using withScope for (const entry of activeChannel._stores.entries()) { const store = entry[0]; const transform = entry[1]; @@ -122,17 +122,19 @@ class RunStoresScope { DisposableStackPrototypeUse(stack, store.withScope(newContext)); } - } - // Publish data - activeChannel.publish(data); + // Publish data + activeChannel.publish(data); - // Transfer ownership of the stack - this.#stack = DisposableStackPrototypeMove(stack); + // Transfer ownership of the stack + this.#stack = DisposableStackPrototypeMove(stack); + } else { + activeChannel.publish(data); + } } [SymbolDispose]() { - this.#stack[SymbolDispose](); + this.#stack?.[SymbolDispose](); } }