Skip to content
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

Merged
merged 9 commits into from Feb 22, 2019

Conversation

cjdeleon62
Copy link

@cjdeleon62 cjdeleon62 commented Feb 4, 2019

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

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Feb 4, 2019
@torch2424
Copy link
Contributor

Triaging to @jridgewell , Feel free to re-assign 😄

Copy link
Contributor

@jridgewell jridgewell left a 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 Show resolved Hide resolved
src/dom.js Outdated Show resolved Hide resolved
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
Copy link
Contributor

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.

Copy link
Author

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 👍

@cjdeleon62
Copy link
Author

@jridgewell I am unsure if this is what you meant for using onDocumentReady inside of the waitForBody function?

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)
Copy link
Contributor

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.

Copy link
Author

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

@jridgewell
Copy link
Contributor

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.

@cjdeleon62
Copy link
Author

@jridgewell no problem, thanks for helping out!

@jridgewell
Copy link
Contributor

I pushed some updated tests to your branch, let's see if this fixes it.

@jridgewell
Copy link
Contributor

And that did it. Thanks!

@jridgewell jridgewell merged commit 81f0c14 into ampproject:master Feb 22, 2019
@cjdeleon62
Copy link
Author

Thank you @jridgewell for working to get this merged in and helping out!

noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
…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
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Mar 22, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change waitForBody and waitForHead
4 participants