Skip to content

Commit 6f3fcc0

Browse files
authored
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
1 parent 81a4d87 commit 6f3fcc0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

sites/svelte-5-preview/src/lib/Output/Viewer.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,18 @@
133133
{
134134
const { mount, unmount, App, untrack } = __repl_exports;
135135
136-
const console_log = console.log
136+
const console_methods = ['log', 'error', 'trace', 'assert', 'warn', 'table', 'group'];
137137
138-
console.log = function (...v) {
139-
return untrack(() => console_log.apply(this, v));
138+
// The REPL hooks up to the console to provide a virtual console. However, the implementation
139+
// needs to stringify the console to pass over a MessageChannel, which means that the object
140+
// can get deeply read and tracked by accident when using the console. We can avoid this by
141+
// ensuring we untrack the main console methods.
142+
143+
for (const method of console_methods) {
144+
const original = console[method];
145+
console[method] = function (...v) {
146+
return untrack(() => original.apply(this, v));
147+
}
140148
}
141149
const component = mount(App, { target: document.body });
142150
window.__unmount_previous = () => unmount(component);

0 commit comments

Comments
 (0)