From 6f3fcc0696063aa439a1c1097fe443f29608e6af Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 11 Mar 2024 13:13:19 +0000 Subject: [PATCH] Untrack other REPL console methods and add comment (#10755) * untrack other REPL console methods and add comment * untrack other REPL console methods and add comment --- .../svelte-5-preview/src/lib/Output/Viewer.svelte | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sites/svelte-5-preview/src/lib/Output/Viewer.svelte b/sites/svelte-5-preview/src/lib/Output/Viewer.svelte index 322c68c5f0..0195e3717b 100644 --- a/sites/svelte-5-preview/src/lib/Output/Viewer.svelte +++ b/sites/svelte-5-preview/src/lib/Output/Viewer.svelte @@ -133,10 +133,18 @@ { const { mount, unmount, App, untrack } = __repl_exports; - const console_log = console.log + const console_methods = ['log', 'error', 'trace', 'assert', 'warn', 'table', 'group']; - console.log = function (...v) { - return untrack(() => console_log.apply(this, v)); + // The REPL hooks up to the console to provide a virtual console. However, the implementation + // needs to stringify the console to pass over a MessageChannel, which means that the object + // can get deeply read and tracked by accident when using the console. We can avoid this by + // ensuring we untrack the main console methods. + + for (const method of console_methods) { + const original = console[method]; + console[method] = function (...v) { + return untrack(() => original.apply(this, v)); + } } const component = mount(App, { target: document.body }); window.__unmount_previous = () => unmount(component);