fix: improve deep_read performance (#10624)

pull/10625/head
Dominic Gannaway 10 months ago committed by GitHub
parent 1822396a55
commit aa28ac3c7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve deep_read performance

@ -1929,12 +1929,12 @@ export function out(dom, get_transition_fn, props, global = false) {
export function action(dom, action, value_fn) { export function action(dom, action, value_fn) {
/** @type {undefined | import('./types.js').ActionPayload<P>} */ /** @type {undefined | import('./types.js').ActionPayload<P>} */
let payload = undefined; let payload = undefined;
let needs_deep_read = false;
// Action could come from a prop, therefore could be a signal, therefore untrack // 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 // TODO we could take advantage of this and enable https://github.com/sveltejs/svelte/issues/6942
effect(() => { effect(() => {
if (value_fn) { if (value_fn) {
const value = value_fn(); const value = value_fn();
let needs_deep_read = false;
untrack(() => { untrack(() => {
if (payload === undefined) { if (payload === undefined) {
payload = action(dom, value) || {}; payload = action(dom, value) || {};

@ -1252,7 +1252,13 @@ export function pop(component) {
* @returns {void} * @returns {void}
*/ */
export function deep_read(value, visited = new Set()) { 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); visited.add(value);
for (let key in value) { for (let key in value) {
try { try {

Loading…
Cancel
Save