This repository was archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
This repository was archived by the owner on Mar 20, 2024. It is now read-only.
Preboot suffers from race conditions #82
Copy link
Copy link
Closed
Description
Note: for support questions, please use the Universal Slack Channcel or https://gitter.im/angular/universal
- I'm submitting a ...
- bug report
- feature request
- Which parts of preboot are affected by this issue?
- server side
- client side
- inline
- build process
- docs
- tests
- Do you want to request a feature or report a bug?
A bug.
- What is the current behavior?
Currently Preboot suffers from various race conditions:
- It waits for the
document.bodyto be available and then applies its logic. However, the application root may not be available at this point - see issue add condition to check that the application root is available in the DOM before prebooting #72. - Even if application root exists when Preboot starts listening for events the server node may not be available in full yet. Since Preboots searches for nodes matching desired selectors inside of the existsing
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. - Preboot waits for
bodyin 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 thePrebootCompleteevent fires. This then leaves the server node active, never transferring to the client one which makes for a broken site.
- If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo.
I don't have a quick test case at hand; however, the description from the previous point shows how to reproduce it.
- What is the expected behavior?
Preboot shouldn't suffer from race conditions.
- What is the motivation / use case for changing the behavior?
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)
- Since we want to attach event listeners as soon as possible when the server node starts being available (so that it can be shallow-cloned) we cannot wait for it to be available in full. Therefore, we need to use delegated event handlers on
documentinstead of on specific nodes. - As we support multiple app roots, to not duplicate large inline preboot code, we'll split
getInlinePrebootCodeinto 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 maintaingetInlinePrebootCodefor backwards compatibility but we'll no longer use it internally. - To maintain children offset numbers (otherwise selectors won't match between the client & the server) we'll remove the in-app-root script immediately when it starts executing; this won't stop execution.
document.currentScriptis 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. - We'll remove
waitUntilReadyas there's no reliable way to wait; we'll invoke the init code immediately instead. - We'll attach the overlay used for freeing the UI to
document.documentElementinstead ofdocument.bodyso that we don't have to wait forbody.
iam4x
Metadata
Metadata
Assignees
Labels
No labels