franciscop/react-plain-router

Alternatives to setInterval?

Closed this issue · 3 comments

Hi! I like your library but I just traced down the setInterval call https://github.com/franciscop/react-plain-router/blob/master/router.js#L67 as it was showing up in my performance snapshots.

Is there any alternative to having this? Does it really need to check for URL changes every 10 milliseconds?

Hi Dave, thanks! Unfortunately browsers are very inconsistent with triggering the event popstate and other URL events, so the setInterval is definitely needed. But it could be changed to 100ms since it's the fallback situation (so it's okay if it's not so accurate). Would that work for you?

Maybe it could be a user configurable option? If not, 100ms is better than 10 :)

Or how about using a MutationObserver? IE11 minimum though.

Fixed, set to 100ms and bumped version to 0.5.0 👍