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: spread as a dependency for every prop #11290
base: main
Are you sure you want to change the base?
fix: spread as a dependency for every prop #11290
Conversation
|
I don't think this will work - what if the dynamic bit doesn't contain the property initially, but after an update it does? Then it won't get notified anymore, leading to stale values |
Yeah that's exactly the failing tests. I pushed the code because I can't work on it now and planned to continue working on it this evening (but at the same time just wanted to get the problem out there and the possible solution validated). |
@dummdidumm could pass in a source with the keys of |
I've implemented this and it works (except for two legacy tests that i'm investigating):
The thing the i dislike the most is that to get a reliable derived that doesn't change every time i had to Object.keys(rest).join(",") otherwise the array would be a new reference each time. The tests that are not passing regards a legacy code spreading into slot. I will try to investigate this a bit further tomorrow. |
@dummdidumm i don't know if you can be of any help but the test that is breaking is this: <script>
export let a;
export function b() {}
export let c = 1;
$: length = Object.keys($$restProps).length;
$: values = Object.values($$restProps);
</script>
<div>Length: {length}</div>
<div>Values: {values.join(',')}</div>
<div {...$$restProps}></div>
<div {...$$props}></div> ith the main.svelte be <script>
import App from './App.svelte';
let a = 1, b = 2, c = 3, d = 4, e = 5;
let f = { foo: 1 };
function updateProps() {
a = 31;
b = 32;
}
function updateRest() {
d = 34;
}
function updateSpread() {
f.foo = 31;
}
function updateSpread2() {
f.bar = 2;
}
</script>
<App {a} {b} {c} {d} {e} {...f} />
<button on:click={updateProps}></button>
<button on:click={updateRest}></button>
<button on:click={updateSpread}></button>
<button on:click={updateSpread2}></button> This basically breaks only when you click |
As expected this is now all greens |
Also quick thing: I did not modify anything for server since we actually don't need to track the dependency there. This make the signature for |
Svelte 5 rewrite
Should fix #11286 the problem was that when you pass a spread and try to access a prop before the spread the code access the spread to check if the accessed prop is in there. This however register a dependency on the spread regardless if the key is in there or not. To fix this i've untracked the access of every function (this required re-accessing the function after the check if the key was in there...i don't know if there's a better way to do this).
There are some tests failing and i've yet to write the test for this so this is a draft.
Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint