S
SolidJS2mo ago
xxttt

Cleanup function

https://stackblitz.com/edit/solidjs-templates-unzazc?file=src%2FuseFloating.tsx 1. When you hover over the box, you'll see three console logs with the message "Update." 2. If you scroll while your mouse is over the box, you'll notice that it's reacting and automatically updating. This is because the autoUpdate function with the elementResize option returns a ResizeObserver. 3. When you move the mouse away from the box and try to scroll the page, you'll see that there are no more logs. This indicates that the cleanup has occurred. The question is: Why does the update function get invoked three times? I believe the issue might be in the second createEffect. I tried to implement cleanup at the first level, but it didn't work well. Is there a way to improve this behavior? I treid to make cleanup fn for days, but I just don't understand where is the problem now. Thanks!
16 Replies
Danny
Danny2mo ago
I'm not really familiar with floating-ui but from what I can see, autoUpdate() calls the update funtion 3 times by itself if you do nothing. If you immediatly call the clean up function, it is only called once.
xxttt
xxttt2mo ago
Yes, I know, but the problem is that I cannot cleanup fn right away. I tried to copy Vue library, but let variable is not reactive. So I just don't know what to do.
Madaxen86
Madaxen862mo ago
What’s the problem of calling it 3x times?
xxttt
xxttt2mo ago
It shouldn't work that way :D. And it is bad for old devices.
bigmistqke
bigmistqke2mo ago
pretty confusing code... what is the goal of @floating-ui's autoUpdate?
lxsmnsyc
lxsmnsyc2mo ago
floating-ui is pretty confusing alright. Popper is a bit more "exactly what I need" package, Floating UI is too bare bones, it's "here, you manage it" package
xxttt
xxttt2mo ago
https://floating-ui.com/docs/autoupdate you can read more about it here or hover over its options.
autoUpdate | Floating UI
A JavaScript library to position floating elements and create interactions for them.
xxttt
xxttt2mo ago
I don't think it is confusing. React library for floating-ui are 😄
bigmistqke
bigmistqke2mo ago
I think it has something to do with that autoUpdate call, if you simply call update inside whileElementsMounted it is called once. if I do const cl = autoUpdate(refrence, floating, update, { elementResize: false }) it is called once too. so it has something to do with the resizing of refrence/float
xxttt
xxttt2mo ago
No way
xxttt
xxttt2mo ago
Well, in Vue its called two times ;/
No description
xxttt
xxttt2mo ago
and updates almost 2 times more compared to Solid.
No description
No description
xxttt
xxttt2mo ago
I think that there's no way to optimize it. Is there's a way to make cleanup() fn reactive at the top level somehow? Just like that. Or it is better to tie it with isOpen() in createEffect? What do you think?
No description
mdynnl
mdynnl2mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
mdynnl
mdynnl2mo ago
though you might wanna look at stores for granularly updating along the data
Want results from more Discord servers?
Add your server