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 1 year 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,12 +1,15 @@
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) {
untrack(() => {
try {
let has_state = false; let has_state = false;
const transformed = []; const transformed = [];
@ -25,6 +28,8 @@ export function log_if_contains_state(method, ...objects) {
// 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