Skip to content

Commit

Permalink
🔥 Install core services before installing builtins (#16484)
Browse files Browse the repository at this point in the history
Fixes #15759.

The core issue is a race condition between the startup chunking, and the
`buildCallback` of any of the builtin elements. In certain
circumstances, the `buildCallback` can actually be called sync after
installing the custom element. Then, it's a race between the adoption
chunk and `whenBodyAvailable`. If `whenBodyAvailable` wins, we get the
error.

So, let's just install the needed `extensions` service before installing
any of the builtins.
  • Loading branch information
jridgewell committed Jun 30, 2018
1 parent ea21a2b commit 3615fb3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/amp.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ startupChunk(self.document, function initial() {
perf.coreServicesAvailable();
maybeTrackImpression(self);
});
startupChunk(self.document, function adoptWindow() {
adopt(self);
});
startupChunk(self.document, function builtins() {
// Builtins.
installBuiltins(self);
});
startupChunk(self.document, function adoptWindow() {
adopt(self);
});
startupChunk(self.document, function stub() {
// Pre-stub already known elements.
stubElementsForDoc(ampdoc);
Expand Down

0 comments on commit 3615fb3

Please sign in to comment.