What does it mean when $inspect.trace shows no source for the trigger? #18286
Replies: 4 comments 2 replies
|
When Two common causes in practice: 1. Fine-grained reactivity loss through object spreading or destructuring If you have something like: let derived1 = $derived({ ...someStore, extra: computed });
let derived2 = $derived(doSomething(derived1));Every time Fix: make 2. The
If you can share even a simplified version of the dependency chain (derived A depends on derived B depends on state C), I can probably spot where the spurious invalidation is coming from. The pattern is almost always: somewhere in the chain, a derived creates a new reference without the value actually changing. |
|
Thank you for both your answers, they're both very helpful. I started reading the source code to get a better understanding and from what I understand the s = with_parent(() => {
var p = has ? proxy(target[prop]) : UNINITIALIZED;
var s = source(p, stack);
if (DEV) {
tag(s, get_label(path, prop));
}
return s;
});I suppose this is a compromise of some sort. If it subscribed to the Anyway, thanks for all your help, it actually explained quite a lot about what's going on in my code-base. I still haven't fully solved the mystery of missing dependencies but now I at least know what to look for with the help of your answers. |
|
I made the following change in my local --- a/packages/svelte/src/internal/client/proxy.js
+++ b/packages/svelte/src/internal/client/proxy.js
@@ -226,34 +226,10 @@ export function proxy(value) {
return true;
}
+ get(version);
var s = sources.get(prop);
var has = (s !== undefined && s.v !== UNINITIALIZED) || Reflect.has(target, prop);
- if (
- s !== undefined ||
- (active_effect !== null && (!has || get_descriptor(target, prop)?.writable))
- ) {
- if (s === undefined) {
- s = with_parent(() => {
- var p = has ? proxy(target[prop]) : UNINITIALIZED;
- var s = source(p, stack);
-
- if (DEV) {
- tag(s, get_label(path, prop));
- }
-
- return s;
- });
-
- sources.set(prop, s);
- }
-
- var value = get(s);
- if (value === UNINITIALIZED) {
- return false;
- }
- }
-
return has;
}, |
|
The patch shouldn't silently break anything, deletes and new keys both bump For the trace, the blue highlight just means that dep was written since the reaction's last run. No highlight anywhere means no dep changed at all, the scheduler re-ran your derived for its own reasons. The earlier comment has that part backwards by the way, derived deps are logged recursively and highlighted like everything else. Are you on |
Uh oh!
There was an error while loading. Please reload this page.
Hi, first of all sorry for no reproducible example but I've only been able to capture this behavior in the project I'm working on which I'm sadly not able to share. Basically I noticed that a lot of derived values are being recalculated a lot more than expected. I started using $inspect.trace to find the issues. Generally speaking, the root cause of the recalculation was usually highlighted in the produced log. With that I was able to fix some issues including the fact that apparently
if ('someKey' in someObj) { /* ... */ }will re-trigger even if the keys ofsomeObjdoesn't change - updatingsomeObj.someKey = /* ... */also triggers a recalculation but I was able to fix that withuntrack. At some point I hit a wall, all the extra recalculations I have now do not highlight any particular state variable in the output of $inspect.trace. How am I supposed to interpret that? Does that mean that the derived value got recalculated for no reason? Sorry for rambling but I have a tight deadline for this project and I'm getting really stressed out by not being able to get Svelte to do what I want it to do. I just want to know if this is normal behavior and if so, how am I supposed to interpret it? Thanks :)All reactions