-
Notifications
You must be signed in to change notification settings - Fork 756
Description
I got a question about how to integrate view transitions with Mithril, and it's very awkward to integrate. In fact, in the face of frame-timed updates, it ends up actively causing glitchiness, and that very thread ran into such a real-world integration problem.
Mithril, like many frameworks, batches its DOM updates to run all at once within animation frame callbacks for performance.
One of the cause of problems I suspect is exactly that animation frame batching. Microtasks scheduled within renders are delayed until after the DOM is consumed for paint. And I could see this causing timing delays and other glitches during update.
Update: even the "obvious" way to integrate doesn't work:
- Kick off the transition, save the update callback's promise resolver.
- Wait for next animation frame.
- Update the page via new render.
- Resolve the update promise in the post-update callback (
oncreate/onupdatefor Mithril,onLayoutEffectfor React, etc.).
The API really needs to tolerate this kind of batching and scheduling. It should not be doing its own scheduling and replacing requestAnimationFrame.
Mithril is not alone. Even React and Svelte are almost certainly impacted as they batch renders very similarly.