Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only call onchange once for array mutations #15073

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Jan 21, 2025

small addition to #15069 — only call onchange once for array mutations

This isn't just about avoiding unnecessary work — it's about correctness. Without something like this, the callback will fire when the array mutation is incomplete, which could lead to all sorts of bad things.

I thought we were already doing something like this in the context of $inspect, but it turns out we weren't. Perhaps we should?

Copy link

changeset-bot bot commented Jan 21, 2025

⚠️ No Changeset found

Latest commit: de827fb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15073

@Rich-Harris
Copy link
Member Author

(I didn't add any tests yet, was just noodling around. Also: maybe we would want to expose the batching function at some point, though I didn't do that preemptively)

@paoloricciuti
Copy link
Member

(I didn't add any tests yet, was just noodling around. Also: maybe we would want to expose the batching function at some point, though I didn't do that preemptively)

I can add tests in my pr, I was waiting to find a solution for the tests...looks good to me!

@paoloricciuti paoloricciuti merged commit 807ffbb into state-onchange Jan 21, 2025
10 checks passed
@paoloricciuti paoloricciuti deleted the state-onchange-arrays branch January 21, 2025 12:29
@dummdidumm
Copy link
Member

Will this have a non-trivial impact on performance? We're now doing array.includes everytime we get anything from a proxied array

@szymeo
Copy link

szymeo commented Jan 22, 2025

@dummdidumm wdyt about adding performance tests? I'm not that deep in ecosystem yet, so maybe it got addressed somehow already? If not I can have a look on poc

@paoloricciuti
Copy link
Member

@dummdidumm wdyt about adding performance tests? I'm not that deep in ecosystem yet, so maybe it got addressed somehow already? If not I can have a look on poc

We have a series of benchmarks already that runs on CI. But i refer to @trueadm for that 😄

@trueadm
Copy link
Contributor

trueadm commented Jan 22, 2025

Our benchmarks doesn't cover deep reactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants