Repository navigation
Make app() function synchronous. - #275
Conversation
Codecov Report
@@ Coverage Diff @@
## master #275 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 3 3
Lines 146 143 -3
Branches 44 44
=====================================
- Hits 146 143 -3
Continue to review full report at Codecov.
|
FlorianWendelborn
left a comment
There was a problem hiding this comment.
LGTM
What's the recommended event to attach to when the script is loaded in the header? load?
|
I like this, simplifies ssr won't need to add document.readyState. |
I think using "DOMContentLoaded" is good enough. 🤔 addEventListener("DOMContentLoaded", () => app({ state, view, actions })@SkaterDad Can you have a look? 🙏 |
| } else { | ||
| addEventListener("DOMContentLoaded", load) | ||
| } | ||
| return emit("loaded", emit, render(state, view)) |
There was a problem hiding this comment.
Is this guaranteed to fire only when DOMContentLoaded?
There was a problem hiding this comment.
No, it won't. You need to use DOMContentLoaded if you are unsure like if you are loading your app bundle inside the <head>. You don't often do that, yes?
There was a problem hiding this comment.
isn't defer supported by like 95%+ of browsers now? http://caniuse.com/#search=defer
stupid Opera Mini dragging their feet on so much.
There was a problem hiding this comment.
Haha, that is fine.. you are right. I don't do it often. Some people might, for them it will break so I guess some explicit makes sure to put the script before the closing body tag wording in the docs wouldn't go a miss.
There was a problem hiding this comment.
or put defer in your script tag if it's in the head, they become equivalent ;) I really like putting scripts in head so I can just target document.body for render
|
@andyrj Yes, very likely. |
SkaterDad
left a comment
There was a problem hiding this comment.
Looks good to me! As @andyrj said, this will simplify SSR, and should simplify testing also.
I did like the original behavior for ease-of-use, but the benefits seem worth the trade-off.
Will sites like Codepen require the DOMContentLoaded callback?
I don't know, but I don't think so. We used to have pens before this feature was originally added. @lukejacksonn Do you approve of these changes? |
jamen
left a comment
There was a problem hiding this comment.
I would have thought to keep it async. But, it does knock off a few bytes, gives more user choice, and helps SSR... So I'm for it. 👍
|
Thanks @jamen. |
7740da8 to
e2583a5
Compare
The recommended way is to use: <script defer src="my-hyper-app-bundle.js"></script>This little chart made it click for me. |
lukejacksonn
left a comment
There was a problem hiding this comment.
We should probably be discouraging scripts (without defer) in the head, the DOMContentLoaded solution is available for those who need it and ready is better than loaded so I say ship it.
This next release is going to have one hell of a change log 📝
2004e26 to
f8942b4
Compare
- Now that app is sync and DOMContentLoaded is not being used, events.loaded was renamed to events.ready, which makes more sense.
f8942b4 to
feb0caf
Compare
|
@lukejacksonn Not true, I can't control the way the scripts I write will be embedded. Any restriction I add is one restriction too much. I hope |
|
@dodekeract You can always use DOMContentLoaded. To summarize, here are your three options:
|
….ready`. (#275) - Since app() is now sync and DOMContentLoaded is not being used, events.loaded was also renamed to events.ready, which makes more sense.

This will break your app if you were loading your bundle inside the
<head>instead of at the bottom of<body>.If your use case involves loading an app in the
<head>, you can simply do follows:Also,
loadedwas renamed toready. Now that app is sync and DOMContentLoaded is not being used, events.ready makes more sense.