MithrilJS / mithril.js

A JavaScript Framework for Building Brilliant Applications
https://mithril.js.org
MIT License
13.99k stars 926 forks source link

Errors are not forwarded to window.onerror #2621

Open ACXgit opened 4 years ago

ACXgit commented 4 years ago

Errors inside components do not reach window.onerror event handler while using the Mithril router, mounting components with m.route. Instead they do when the component is mounted with m.mount.

This didn't happen in 1.x.

Mithril version: 2.0.4

Browser and OS: Firefox 81 64bit, Windows 10

Code

[flems] m.route with Mithril 1.1.7, working as expected

[flems] m.route with Mithril 2.0.4, not forwarding

[flems] m.mount with Mithril 2.0.4, working as expected

Context

Without errors being forwarded to window.onerror it's impossible to catch them globally and log them, i.e. to an application monitoring and error tracking platform like Sentry.

dead-claudia commented 4 years ago

Found the issue:

I feel the issue may be mitigated in two parts:

  1. Resolve the initial route before mounting, to avoid an initial blank render. Edit: Not necessary. Just the second.
  2. Change async redraws to call requestAnimationFrame once for each root rather than once for all roots, and just use the array of scheduled roots to avoid double-scheduling roots. (It's worth noting no user code can run between animation frame callbacks, and microtasks are delayed until after paint, so this change would likely not be user-breaking.)