Skip to content

Commit aa28ac3

Browse files
authored
fix: improve deep_read performance (#10624)
1 parent 1822396 commit aa28ac3

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/wise-apples-care.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: improve deep_read performance

packages/svelte/src/internal/client/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,12 @@ export function out(dom, get_transition_fn, props, global = false) {
19291929
export function action(dom, action, value_fn) {
19301930
/** @type {undefined | import('./types.js').ActionPayload<P>} */
19311931
let payload = undefined;
1932+
let needs_deep_read = false;
19321933
// Action could come from a prop, therefore could be a signal, therefore untrack
19331934
// TODO we could take advantage of this and enable https://github.com/sveltejs/svelte/issues/6942
19341935
effect(() => {
19351936
if (value_fn) {
19361937
const value = value_fn();
1937-
let needs_deep_read = false;
19381938
untrack(() => {
19391939
if (payload === undefined) {
19401940
payload = action(dom, value) || {};

packages/svelte/src/internal/client/runtime.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,13 @@ export function pop(component) {
12521252
* @returns {void}
12531253
*/
12541254
export function deep_read(value, visited = new Set()) {
1255-
if (typeof value === 'object' && value !== null && !visited.has(value)) {
1255+
if (
1256+
typeof value === 'object' &&
1257+
value !== null &&
1258+
// We don't want to traverse DOM elements
1259+
!(value instanceof EventTarget) &&
1260+
!visited.has(value)
1261+
) {
12561262
visited.add(value);
12571263
for (let key in value) {
12581264
try {

0 commit comments

Comments
 (0)