-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
$inspect.trace() is missing information or Svelte is running effects unnecessarily #14794
Comments
This is a way minimal reproduction https://svelte.dev/playground/1119fe0a689544d58c0c89f71fdbe016?version=5.15.0 However I feel like this is how it should work. I think you should be more interested about which dependencies your effect actively has rather than "was this dependency dirty when the effect ran". I fear that if we include something that is not a dependency just to say "this was dirty" might get confusing. I'll try to see if there's a decent way to add this |
Actually better reproduction even tho is the same problem https://svelte.dev/playground/32f6a2d5ae114955bf126a27f2457ec5?version=5.15.0 |
I don't understand your first minimal, but the second one I think I do: The effect changes My original issue is: I suspected my last effect run. I run the column algorithm in my head and I don't see a reason for the last run. This is why I added the trace. My expectation was that the coloring would tell me which signal or signals triggers this last run, but to my surprise (dismay), there are no blue signals. So the trace is being unhelpful for me. It is not fulfilling its purpose. |
The first minimal is showing an effect rerun where in the end no dependencies where tracked so nothing is shown (but something had to trigger the rerun). |
Ok, got it. This confirms my suspicion that the docs are incorrect: What's printed is the list of signals that are read during the run, not the list of signals that made the effect run. Still, I think that tracing is not fulfilling its purpose: I need to know which signal triggered my last effect, and the list is all gray. I understand that if the signal that triggered the effect is not re-read, then there would be nothing to highlight, and this would be missing information that I wish we could still get. Otherwise my question still goes unanswered. Basically I'm still as I was when I wrote this issue: Either the trace is missing information, or Svelte is running effects when it shouldn't. In my case, I am suspecting the latter, but I agree: That's unlikely. So which signal triggered the last effect of ID parent in my repro? |
I don't know, I tried to follow a bit but it's jumping into too many hoops for me to follow from the phone. I'm trying to figure out what the right behavior should be because it really depends on what you are looking for...in your case you want to know which source triggered your effect but in other cases the thing you might look for is "which are the dependencies of my effect?". |
To further explain why I think Svelte might be running the last effect unnecessarily, the algorithm converges for a synchronization pair when |
Exploring this the problem really is that the effect version is set to |
Ok, I think I know where the extra effect run comes from. Synchronization produces a reset of I suppose this solves that mystery. What's still fuzzy for me is the rules as to when the signal is shown blue vs gray in the trace. It is safe to say that the docs are wrong, so what would be a better documentation for tracing, and what would be an accurate explanation for the highlighting feature? Paolo can probably explain why the last trace shows all gray signals, so I'll leave him to decide if this behavior is correct or not. We just need to come up with accurate documentation about the highlighting behavior. |
I kinda already explained it in my last comment but yeah I think there's a slight bug here and maybe some behavioral change to made. So first thing first is that you will get a log for each signal read in the current run. So if the signal that triggered the effect is not read during this run it will not show up at all. Secondly: each source/derived has a version based on a global counter, whenever the source/derived changes the counter is increased and the version of that source/derived is set to the increased version. When an effect finishes the version of the effect is set to the current version (without increasing). Normally when you set a value to a source you increase the version, then the effect run so the version of the source is greater than the version of the effect. When the effect finish they will be equal. But if you set a variable within the effect that re-triggers the same effect, the version of the effect is set to your version before rerunning so your version is effectively equal (which generally means that that signal did not trigger the effect). This is the normal flow (when effect is not re triggered)
And here's the one when effect is re-triggered
|
Thanks for the explanations. Much appreciated. For others: This makes me wonder: Can a utility function like |
The documentation needs to be tweaked a bit here. What The colouring of the different properties has a bug in it though – and I believe I have a fix. |
Describe the bug
It seems that there might be room for improvement for
$inspect.trace()
. There are cases where the trace doesn't highlight anything as changed. If nothing really changed, then why did the effect fire, right?My current possibilities are:
$inspect.trace()
doesn't always show the signals that change, or its highlighting algorithm is sometimes failing to indicate which signals changed.One possibility that occurs to me: The trace is shown after the effect runs, and it contains all the signals read during that execution. This list is then shown using data from before the effect run to show which signals made the effect fire to begin with by highlighting them in cornflower blue. The potential fail might come here: What if the run doesn't read the signal that made the effect fire? Then there's nothing to highlight.
Reproduction
REPL
Instructions
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: