diff --git a/.changeset/wise-apples-care.md b/.changeset/wise-apples-care.md new file mode 100644 index 0000000000..1583d753ec --- /dev/null +++ b/.changeset/wise-apples-care.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: improve deep_read performance diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index ed08d9e974..0861acdfce 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -1929,12 +1929,12 @@ export function out(dom, get_transition_fn, props, global = false) { export function action(dom, action, value_fn) { /** @type {undefined | import('./types.js').ActionPayload

} */ let payload = undefined; + let needs_deep_read = false; // Action could come from a prop, therefore could be a signal, therefore untrack // TODO we could take advantage of this and enable https://github.com/sveltejs/svelte/issues/6942 effect(() => { if (value_fn) { const value = value_fn(); - let needs_deep_read = false; untrack(() => { if (payload === undefined) { payload = action(dom, value) || {}; diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 6aae3eedbb..79eed38d25 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -1252,7 +1252,13 @@ export function pop(component) { * @returns {void} */ export function deep_read(value, visited = new Set()) { - if (typeof value === 'object' && value !== null && !visited.has(value)) { + if ( + typeof value === 'object' && + value !== null && + // We don't want to traverse DOM elements + !(value instanceof EventTarget) && + !visited.has(value) + ) { visited.add(value); for (let key in value) { try {