Skip to content

Commit 3616828

Browse files
fix: ensure snapshot logs don't affect dependency graph (#13286)
* fix: ensure snapshot logs don't affect dependency graph untrack the whole function See #13142 (comment) * try-catch * appease eslint --------- Co-authored-by: Rich Harris <[email protected]>
1 parent e7f51e4 commit 3616828

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

.changeset/eleven-peaches-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure snapshot logs don't affect dependency graph
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
import { STATE_SYMBOL } from '../constants.js';
22
import { snapshot } from '../../shared/clone.js';
33
import * as w from '../warnings.js';
4+
import { untrack } from '../runtime.js';
45

56
/**
67
* @param {string} method
78
* @param {...any} objects
89
*/
910
export function log_if_contains_state(method, ...objects) {
10-
let has_state = false;
11-
const transformed = [];
11+
untrack(() => {
12+
try {
13+
let has_state = false;
14+
const transformed = [];
1215

13-
for (const obj of objects) {
14-
if (obj && typeof obj === 'object' && STATE_SYMBOL in obj) {
15-
transformed.push(snapshot(obj, true));
16-
has_state = true;
17-
} else {
18-
transformed.push(obj);
19-
}
20-
}
16+
for (const obj of objects) {
17+
if (obj && typeof obj === 'object' && STATE_SYMBOL in obj) {
18+
transformed.push(snapshot(obj, true));
19+
has_state = true;
20+
} else {
21+
transformed.push(obj);
22+
}
23+
}
2124

22-
if (has_state) {
23-
w.console_log_state(method);
25+
if (has_state) {
26+
w.console_log_state(method);
2427

25-
// eslint-disable-next-line no-console
26-
console.log('%c[snapshot]', 'color: grey', ...transformed);
27-
}
28+
// eslint-disable-next-line no-console
29+
console.log('%c[snapshot]', 'color: grey', ...transformed);
30+
}
31+
} catch {}
32+
});
2833

2934
return objects;
3035
}

0 commit comments

Comments
 (0)