diff --git a/docs/autoredraw.md b/docs/autoredraw.md index ec4c5945..b3ac9c18 100644 --- a/docs/autoredraw.md +++ b/docs/autoredraw.md @@ -89,7 +89,7 @@ m.route(document.body, "/", { ### When Mithril does not redraws -Mithril does not redraw after 3rd party library event handlers. In those cases, you must manually call [`m.redraw()`](redraw.md). +Mithril does not redraw after `setTimeout`, `setInterval`, `requestAnimationFrame` and 3rd party library event handlers (e.g. Socket.io callbacks). In those cases, you must manually call [`m.redraw()`](redraw.md). Mithril also does not redraw after lifecycle methods. This is because lifecycle methods run within the redraw cycle and allowing a nested redraw to run could cause loss of stability or even stack overflows. If you need to trigger a redraw within a lifecycle method, you should call `m.redraw` from within the callback of an asynchronous function such as `requestAnimationFrame`, `Promise.resolve` or `setTimeout`. diff --git a/docs/redraw.md b/docs/redraw.md index ebc17283..9fe72feb 100644 --- a/docs/redraw.md +++ b/docs/redraw.md @@ -14,6 +14,8 @@ You DON'T need to call it if data is modified within the execution context of an You DO need to call it in `setTimeout`/`setInterval`/`requestAnimationFrame` callbacks, or callbacks from 3rd party libraries. +Typically, `m.redraw` triggers an asynchronous redraws, but it may trigger synchronously if Mithril detects it's possible to improves performance by doing so. You should write code assuming that it always redraws asynchronously. + --- ### Signature @@ -32,4 +34,4 @@ When callbacks outside of Mithril run, you need to notify Mithril's rendering en To trigger a redraw, call `m.redraw()`. Note that `m.redraw` only works if you used `m.mount` or `m.route`. If you rendered via `m.render`, you should use `m.render` to redraw. -You should not call m.redraw from a [lifecycle method](lifecycle-methods.md). Doing so will result in undefined behavior. \ No newline at end of file +You should not call m.redraw from a [lifecycle method](lifecycle-methods.md). Doing so will result in undefined behavior.