Closed mgol closed 6 years ago
PR: #83.
Can anyone look at this PR? With version 6.0.0-beta.3 the race conditions are quite apparent. With the preboot module my app will randomly transition from a full server page to a blank client page with no errors in the console. Without the preboot module there's a flash but everything loads fine. I would love to be able to use this!
@arutnik It's a WIP, and @mgol is OOTO for most of the month. I apologize for the delay, but that's the unfortunate nature of open source projects.
Note: for support questions, please use the Universal Slack Channcel or https://gitter.im/angular/universal
I'm submitting a ...
[x] bug report
[ ] feature request
Which parts of preboot are affected by this issue?
[x] server side
[x] client side
[x] inline
[ ] build process
[ ] docs
[ ] tests
Do you want to request a feature or report a bug?
A bug.
Currently Preboot suffers from various race conditions:
document.body
to be available and then applies its logic. However, the application root may not be available at this point - see issue #72.serverNode
, it may skip some of them if the server node hasn't loaded fully. This is especially common if the internet connection is slow.body
in a tight loop, checking every 10 milliseconds. This starves the browser but may also be clamped by it to a larger delay (around 1 second); that's what happens in modern browsers if the tab where the page loads is inactive, e.g. if you open a link in a new tab in Chrome or Firefox. This means Preboot may start listening for events after Angular reports the app is stable and thePrebootComplete
event fires. This then leaves the server node active, never transferring to the client one which makes for a broken site.I don't have a quick test case at hand; however, the description from the previous point shows how to reproduce it.
Preboot shouldn't suffer from race conditions.
The current behavior is buggy as described above.
Please tell us about your environment:
Browser: all
Language: all
OS: all
Platform: all
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
document
instead of on specific nodes.getInlinePrebootCode
into two parts: function definitions to be put in<head>
and the invocation separate for each app root put just after the app root opening tag. We'll maintaingetInlinePrebootCode
for backwards compatibility but we'll no longer use it internally.document.currentScript
is a good way to find the currently running script but it doesn't work in IE. We'll need to apply a fallback behavior for IE, perhaps by tagging each script with a unique attribute value and injecting this value as a variable into the script.waitUntilReady
as there's no reliable way to wait; we'll invoke the init code immediately instead.document.documentElement
instead ofdocument.body
so that we don't have to wait forbody
.