fix: ensure snapshot logs don't affect dependency graph (#13286)

* fix: ensure snapshot logs don't affect dependency graph

untrack the whole function
See https://github.com/sveltejs/svelte/pull/13142#issuecomment-2354116248

* try-catch

* appease eslint

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/13290/head
Simon H 3 days ago committed by GitHub
parent e7f51e4982
commit 36168286ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure snapshot logs don't affect dependency graph

@ -1,30 +1,35 @@
import { STATE_SYMBOL } from '../constants.js'; import { STATE_SYMBOL } from '../constants.js';
import { snapshot } from '../../shared/clone.js'; import { snapshot } from '../../shared/clone.js';
import * as w from '../warnings.js'; import * as w from '../warnings.js';
import { untrack } from '../runtime.js';
/** /**
* @param {string} method * @param {string} method
* @param {...any} objects * @param {...any} objects
*/ */
export function log_if_contains_state(method, ...objects) { export function log_if_contains_state(method, ...objects) {
let has_state = false; untrack(() => {
const transformed = []; try {
let has_state = false;
const transformed = [];
for (const obj of objects) { for (const obj of objects) {
if (obj && typeof obj === 'object' && STATE_SYMBOL in obj) { if (obj && typeof obj === 'object' && STATE_SYMBOL in obj) {
transformed.push(snapshot(obj, true)); transformed.push(snapshot(obj, true));
has_state = true; has_state = true;
} else { } else {
transformed.push(obj); transformed.push(obj);
} }
} }
if (has_state) { if (has_state) {
w.console_log_state(method); w.console_log_state(method);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('%c[snapshot]', 'color: grey', ...transformed); console.log('%c[snapshot]', 'color: grey', ...transformed);
} }
} catch {}
});
return objects; return objects;
} }

Loading…
Cancel
Save