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
🐛 Implement waitForHead and change waitForBody to use documentReady #20658
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
fbc5b72
to
d4d1ae9
Compare
CLAs look good, thanks! |
Triaging to @jridgewell , Feel free to re-assign 😄 |
c9d417e
to
9765d80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else looks good
src/dom.js
Outdated
* Will be deprecated soon; use {@link AmpDoc#whenBodyAvailable} or | ||
* @{link DocumentState#onBodyAvailable} instead. | ||
* @param {!Document} doc | ||
* @param {function()} callback | ||
*/ | ||
export function waitForBody(doc, callback) { | ||
waitForChild(doc.documentElement, () => !!doc.body, callback); | ||
waitForChild(doc.documentElement, () => ( | ||
isDocumentReady(doc) && !!doc.body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it appears this is failing tests for some obscure reasons (MutationObserver inside waitForChild
doesn't fire during parsing). The fix is to just call onDocumentReady
from src/document-ready.js
. We can also change waitForBodyPromise
to just call whenDocumentReady
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh okay, will use those functions 👍
@jridgewell I am unsure if this is what you meant for using |
src/dom.js
Outdated
@@ -116,7 +116,7 @@ export function waitForHeadPromise(doc) { | |||
*/ | |||
export function waitForBody(doc, callback) { | |||
waitForChild(doc.documentElement, () => ( | |||
isDocumentReady(doc) && !!doc.body | |||
onDocumentReady(doc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, waitForBody
just calls onDocumentReady
. There're essentially aliases at this point:
export function waitForBody(doc, callback) {
return onDocumentReady(doc, callback);
}
Same for waitForBodyPromise
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my most recent commit has that change, but tests still seem to be failing for some reason
Agh, I'm sorry the tests are making this simple change so difficult to land. I'll review the test failures soon to figure out what to do. |
@jridgewell no problem, thanks for helping out! |
I pushed some updated tests to your branch, let's see if this fixes it. |
And that did it. Thanks! |
Thank you @jridgewell for working to get this merged in and helping out! |
…mpproject#20658) * check for body along with the document ready check * remove console.log * reset whitespace * one more whitespace * wait until body is present to to show head is fully parsed * use onDocumentReady for document ready detection * add callback * Fix tests
…mpproject#20658) * check for body along with the document ready check * remove console.log * reset whitespace * one more whitespace * wait until body is present to to show head is fully parsed * use onDocumentReady for document ready detection * add callback * Fix tests
Implement waitForHead and change waitForBody to wait for documentReady. This change is for preventing bugs from occurring when using the waitForBody function and allows the body and it's children to render before the Promise resolves. Another method, waitForHead was implemented for cases where waiting for DOMReady would take too long for certain actions.
Resolves: #20377