Skip to content

Fix amp-bind in PWA#10131

Merged
dreamofabear merged 8 commits intoampproject:masterfrom
dreamofabear:bind-in-pwa
Jun 28, 2017
Merged

Fix amp-bind in PWA#10131
dreamofabear merged 8 commits intoampproject:masterfrom
dreamofabear:bind-in-pwa

Conversation

@dreamofabear
Copy link
Copy Markdown

@dreamofabear dreamofabear commented Jun 24, 2017

Fixes #9916.

  • Scan ampdoc.getBody(), not ampdoc.win.document.body (doesn't work for shadow docs)
  • Do not fallback to top window when retrieving the Bind element service (instead, fallback to ampdoc since it's a doc-scope service)
  • Add relevant tests for element-service.js and bind-impl.js

This PR also requires passing a boolean opt_fallbackToTopWin to allow crossing FIE boundary when getting services. I think this is a safer default, e.g. for A4A.

@dreamofabear dreamofabear changed the title [WIP] Fix amp-bind in PWA Fix amp-bind in PWA Jun 27, 2017
} else {
return null;
}
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just moved below for consistent ordering.

* @return {T}
*/
export function getService(win, id) {
win = getTopWindow(win);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just moved below for consistent ordering.

@dreamofabear
Copy link
Copy Markdown
Author

/to @jridgewell PTAL 👀

@dreamofabear dreamofabear requested a review from jridgewell June 27, 2017 21:41
this.viewer_ = viewerForDoc(this.ampdoc);

/**
const bodyReadyPromise = (opt_win)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this resolve to a body?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenBodyAvailable does, but waitForBodyPromise doesn't. Changed it to use resolve value but not sure it's cleaner.

nodeOrDoc.ownerDocument || nodeOrDoc).defaultView;
return elementServicePromiseOrNull(win, id, extension);
const topWin = getTopWindow(win);
// Don't return promise unless this is definitely FIE to avoid covfefe.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this comment clearer. The current system is pretty confusing and I'm planning on refactoring this soon.


/**
const bodyPromise = (opt_win)
? waitForBodyPromise(opt_win.document)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make it resolve to a body. 😉

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😩 How about in fix-it next week?

return this.initialize_(rootNode);
});
this.initializePromise_ =
this.viewer_.whenFirstVisible().then(bodyPromise).then(body => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the then(bodyPromise) does not return a Promise, it returns whenFirstVisible's again. You have to pass in a function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, done.

nodeOrDoc.ownerDocument || nodeOrDoc).defaultView;
return elementServicePromiseOrNull(win, id, extension);
const topWin = getTopWindow(win);
// In embeds, doc-scope services are window-scope. But make sure to
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand it, but ok.

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.

3 participants