From 36168286ba84305926d89bb7505c0ac0344adeda Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:45:18 +0200 Subject: [PATCH] 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 --- .changeset/eleven-peaches-tap.md | 5 +++ .../src/internal/client/dev/console-log.js | 35 +++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 .changeset/eleven-peaches-tap.md diff --git a/.changeset/eleven-peaches-tap.md b/.changeset/eleven-peaches-tap.md new file mode 100644 index 0000000000..5df9c70e12 --- /dev/null +++ b/.changeset/eleven-peaches-tap.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure snapshot logs don't affect dependency graph diff --git a/packages/svelte/src/internal/client/dev/console-log.js b/packages/svelte/src/internal/client/dev/console-log.js index 52a282f6d4..a578ecea45 100644 --- a/packages/svelte/src/internal/client/dev/console-log.js +++ b/packages/svelte/src/internal/client/dev/console-log.js @@ -1,30 +1,35 @@ import { STATE_SYMBOL } from '../constants.js'; import { snapshot } from '../../shared/clone.js'; import * as w from '../warnings.js'; +import { untrack } from '../runtime.js'; /** * @param {string} method * @param {...any} objects */ export function log_if_contains_state(method, ...objects) { - let has_state = false; - const transformed = []; + untrack(() => { + try { + let has_state = false; + const transformed = []; - for (const obj of objects) { - if (obj && typeof obj === 'object' && STATE_SYMBOL in obj) { - transformed.push(snapshot(obj, true)); - has_state = true; - } else { - transformed.push(obj); - } - } + for (const obj of objects) { + if (obj && typeof obj === 'object' && STATE_SYMBOL in obj) { + transformed.push(snapshot(obj, true)); + has_state = true; + } else { + transformed.push(obj); + } + } - if (has_state) { - w.console_log_state(method); + if (has_state) { + w.console_log_state(method); - // eslint-disable-next-line no-console - console.log('%c[snapshot]', 'color: grey', ...transformed); - } + // eslint-disable-next-line no-console + console.log('%c[snapshot]', 'color: grey', ...transformed); + } + } catch {} + }); return objects; }