-
-
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
track assignment locations for infinite loop reporting #13344
base: main
Are you sure you want to change the base?
Conversation
|
I'm also not really sure if I like it too. It seems useful, but if it is fragile then will it just cause more frustrations in the long term? |
Knowing which assignment it was exactly last is useful, but for more involved loops I also want to know the stack. What about doing this as an additional thing rather than replacing what was there before? i.e. you get the "last ten effects were ..." (maybe with a note that you'll see the transformed contents and can look up the source by exanding it) + what we have here. |
@dummdidumm Having used the last 10 effects logic since it landed, I've actually not found it terribly useful at all. Firstly, 10 is far too many and many of them are internal effects which are just confusing to present to a user – then then effects I look at don't really tell me anything. Like, you really need to know the effect and the dependency, without the dependency it's lost. |
All that happens is you don't get the location — for example if you do |
"all that happens" sounds like it's no big deal, but it's basically impossible to know what caused this then just by looking at the error message.
what do you mean by "you need to know the dependency"? How could we present that?
we can filter them out. I didn't do that originally because I feared that it could make loops harder to debug where a render effect plays a role (AFAIK it could happen if you have a binding that is repeatedly set from above and the below again, but maybe that's not true / not worth for the common case where it's noisy) |
One thing we could do is annotate user effects, so that if an update happens that isn't tracked (because it's an
but if it does
We'd miss cases like |
That sounds like a good idea. |
I'd still like to see a list of effects leading up to this. I'm confident we can get that on the effect object to then print it out. |
I also had an infinite loop scenario and I feel like this is chicken / egg problem to solve. let page = $state({
props: { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
})
$effect(async () => {
const props = { method: 'post', body: JSON.stringify(page)}
const res = await (await fetch(url, props)).json()
Object.assign(page.props, res)
}) And so this causes an infinite loop. I kind of have to hash the result and the page to see if neither has changed for me not to do an object assign. This feels wrong, maybe there is another solution for this in svelte 5. anyways for the time being I switched to onMount, but of course now page changes won't get fresh information from the server. still, what I did not expect is there to be 6 page state changes on top of the initial event when I traced this with $inspect. why isn't object.assign one reactive operation? |
What's the thing that should cause a re-fetch? Url changing? In that case you can use
|
An idea to close #13256. I haven't completely worked out if I like it or not.
Basically, it's tricky to add location information to effects, because sometimes template effects are grouped together (and the assignment that causes the infinite loop could be in a
<span>{n++}</span>
or whatever). But we can add location information for the assignments that cause the infinite loops, which gives us more granular information:Caveats:
.svelte
/.svelte.js
files (though it fails gracefully in these cases)Object.assign(...)
orset.add(blah)
Notwithstanding those caveats, I kinda prefer this to what we have currently.
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