Mithril auto-redraw and manual m.redraw() boundaries in async state updates
0 reputation · 13 Nov 2023, 01:35 UTC
0 reputation · 13 Nov 2023, 01:35 UTC
Mithril.js keeps views synchronized with state through an automatic redraw system that activates after DOM events and AJAX requests. When state changes occur outside those boundaries—inside setTimeout callbacks, WebSocket message handlers, or other external event listeners—developers commonly call m.redraw() to trigger reconciliation. The exact boundary where these two mechanisms overlap remains a practical concern.
Because Mithril rerenders the component tree by comparing new virtual DOM output against the previous tree rather than tracking discrete property mutations, every redraw carries a cost proportional to tree size. A known behavioral characteristic is that invoking m.redraw() immediately before an automatic redraw can cause double-renders, but the precise scheduling conditions that produce this behavior are not always obvious in complex asynchronous chains.
For teams integrating Mithril with external event sources, the unresolved question is how to coordinate manual redraws with the framework's internal lifecycle without introducing redundant renders or stale views. Version differences in redraw scheduling may further affect the correct integration approach.
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.