#how to have a reactive current time?
22 messages ยท Page 1 of 1 (latest)
In what scenario would you need something like that? It feels to me like the wrong solution to the right problem potentially
Do you need sub-second resolution?
I don't think I've heard of it ๐ค
Is that caused by setInterval's scheduling slipping over time?
Is it caused by the main thread blocking for long enough that we can't update the countdown quickly enough? ๐ค
๐
If setInterval is precise and the main thread is not blocked I'm not sure what else it could be though
we have a primitive for that use
https://github.com/solidjs-community/solid-primitives/tree/main/packages/date#createdatenow
but it's also based on polling
But where is this jerky time issue originating from? ๐ค
a bit of an hack, but would updating your countdowns inside a requestAnimationFrame loop solve the problem?
๐ค problem solved ๐ always good to take some measurements
I think setInterval is known to slip over time or something like that, I haven't looked into it myself, but there are packages on npm that supposedly give you a more robust interval, maybe that's the problem
Maybe on startup the main thread was blocked for too long
like I'm not sure another explanation is possible if this problem actually exists
Oh like you start the timer at 1500 milliseconds so you show the next second 500 milliseconds late?
I guess in that case one would need to do an initial setTimeout + a setInterval after that, or probably just scheduling a setTimeout for every second to be sure
it's probably worth addressing imo, because if the user spots that kind of thing it's a bit of a maddening issue for OCD people ๐คฃ
yeah 1 second is eternity
Vue has a useTimestamp primitive that updates the current time using requestAnimationFrame. This is probably as close as you can get to the actual current time. https://vueuse.org/core/useTimestamp/
depending on how crazy how wants to go with this one can get into nanoseconds-level precision
I guess you could have an effect that only updates now signal when a full second has passed.