-
-
Notifications
You must be signed in to change notification settings - Fork 928
Description
Description:
Using the rewrite, I am setting up user authentication in a method that is very much the same as seen here:
https://github.com/tivac/anthracite/blob/master/src/lib/require-auth.js
Expected:
I expected m.route.setPath to route me to /login and erase the current page contents. It does not appear to matter which lifecycle method I put the routing logic in.
Actual:
m.route.setPath routed me to /login but left the current page contents intact, displaying both pages simultaneously.
I was able to fix this issue by wrapping m.route.setPath('/login') in a requestAnimationFrame. I think it makes sense that mithril should handle this logic on the next frame, but if the library itself can handle that implementation detail I think it makes more sense being handled there than in component code.
Edit:
I've created a minimal demo of this bug here using the rewrite:
https://jsfiddle.net/y8m56cg3/3/
There are interesting properties when combining this with a redraw:
https://jsfiddle.net/qs6b7qot/1/
https://jsfiddle.net/qs6b7qot/5/
https://jsfiddle.net/qs6b7qot/6/
And in some cases it can be fixed by wrapping m.route.setPath in a setTimeout or requestAnimationFrame.
https://jsfiddle.net/qs6b7qot/4/
This isn't always the case, but I haven't been able to reproduce the case where setTimeout doesn't solve the problem in a jsfiddle.
And here it is working properly with 0.2.0:
https://jsfiddle.net/8zybnxf6/1