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

Fix amp-bind in PWA #10131

Merged
merged 8 commits into from
Jun 28, 2017
Merged

Fix amp-bind in PWA #10131

merged 8 commits into from
Jun 28, 2017

Conversation

dreamofabear
Copy link

@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
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.

*/
export function getService(win, id) {
win = getTopWindow(win);
return getServiceInternal(win, id);
Copy link
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
Author

/to @jridgewell PTAL 👀

@@ -135,15 +136,21 @@ export class Bind {
/** @const @private {!../../../src/service/viewer-impl.Viewer} */
this.viewer_ = viewerForDoc(this.ampdoc);

/**
const bodyReadyPromise = (opt_win)
Copy link
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
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.

const win = /** @type {!Document} */ (
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
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
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.

@@ -135,17 +136,19 @@ export class Bind {
/** @const @private {!../../../src/service/viewer-impl.Viewer} */
this.viewer_ = viewerForDoc(this.ampdoc);

/**
const bodyPromise = (opt_win)
? waitForBodyPromise(opt_win.document)
Copy link
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
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
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
Author

Choose a reason for hiding this comment

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

Oops, done.

if (nodeOrDoc.nodeType) {
const win = /** @type {!Document} */ (
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
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