angular/builtwith.angularjs.org

race condition on load with modal open

eyston opened this issue · 0 comments

If you refresh a page with the modal open sometimes it works, sometimes the modal flashes open and instantly closes leaving the url in a wrong state.

The issue is in bwa.js line 39 and 99.

The popstate event fires in chrome on the first load with an ev.state of null. This would set lightbox to null which results in the modal being closed.

The success handler for the get request on project.json also updates lightbox checking if a project matches the current url. If there is a match it sets the lightbox to the project which results in the modal being open.

What I think happens is that the project.json file request finishes first and sets the lightbox to the project which has the modal begin to open. Then the onpopstate event handler fires which immediately closes the modal leaving the url in a wrong state. Using the chrome debugger with breakpoints on 39 and 99 seems to confirm this (if 99 is first, it breaks).

Looking at this stack overflow post (http://stackoverflow.com/questions/6421769/popstate-on-pages-load-in-chrome) it seems like checking if ev.state === null and ignoring that popstate event if so might work, but I'm not sure if that is fully cross browser or would ignore legit events (I've never used the popstate event so don't really know whats valid or not).