Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race Condition in App Bootstrap #62

Closed
mike-thompson-day8 opened this issue Nov 18, 2017 · 3 comments
Closed

Race Condition in App Bootstrap #62

mike-thompson-day8 opened this issue Nov 18, 2017 · 3 comments

Comments

@mike-thompson-day8
Copy link
Contributor

mike-thompson-day8 commented Nov 18, 2017

I believe there's a race condition in the way the application bootstrap is written:
https://github.com/Day8/re-frame-template/blob/master/src/leiningen/new/re_frame/resources/public/index.html#L15-L16

app.js must be fully loaded before init() can be called. If it isn't, then there'll be an Reference Error (because the necessary js just isn't loaded yet). And yet the current code doesn't guarantee this fully-loaded-before-call requirement.

The solution is easy - change the script part to be:

<script>
   window.onload = function () { 
       {{sanitized}}.core.init(); 
   }
</script>

Now init() doesn't happen before app.js is fully loaded.

So ...

I'm completely shocked that this hasn't come up before now. How has this not failed all the time before now? I'm Baffled. I must be missing something - which accounts for me not doing a PR. (Was just reported as a problem in Clojurians)

@thheller
Copy link
Contributor

Saw this in Clojurians.

There is no race condition.

<script> without async will ensure that the .js is loaded completely before subsequent <script> tags run.

@mike-thompson-day8
Copy link
Contributor Author

Thanks @thheller. You've both educated me and put me out of my misery. I was baffled.

@gadfly361
Copy link
Contributor

@thheller +1 Thanks! I didn't know that either :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants