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 mechanism for ensuring that all extensions share an AMP version with the main binary. #7239

Merged
merged 2 commits into from Jan 31, 2017

Conversation

cramforce
Copy link
Member

For each extension this checks the version, and if it is the wrong version, will ignore the JS file and initiate a load of the correct version.

  • experiment guarded. This is likely to break some stuff.
  • based on compiled-in version only. rtv is ignored, because we only care about code here, since config is only given in main binary.

Implements locking part of #7238

…sion with the main binary.

For each extension this checks the version, and if it is the wrong version, will ignore the JS file and initiate a load of the correct version.

- experiment guarded. This is likely to break some stuff.
- based on compiled-in version only. rtv is ignored, because we only care about code here, since config is only given in main binary.

Implements locking part of ampproject#7238
@@ -440,6 +440,7 @@ function buildExtensionJs(path, name, version, options) {
// See https://github.com/ampproject/amphtml/issues/3977
wrapper: options.noWrapper ? '' : ('(self.AMP=self.AMP||[])' +
'.push({n:"' + name + '",' + priority +
'v:"' + internalRuntimeVersion + '",' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this include RTV prefix? I always get confused where it is added and where it's not. Does it matter?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a comment at the use site for this. We care about the version of the code here, not about the version of the config.

// This is non-obvious, but we only care about the release version,
// not about the full rtv version, because these only differ
// in the config that is fully determined by the primary binary.
if ('$internalRuntimeVersion$' == version) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto...

Copy link
Member Author

Choose a reason for hiding this comment

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

Existing comment OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

src/runtime.js Outdated
// Mark the element as being replace, so that the loadExtension code
// assumes it as not-present.
scriptInHead.removeAttribute('custom-element');
scriptInHead.setAttribute('i-amphtml-replaced-with-version', fnOrStruct.n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be fnOrStruct.v?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ping on this. Otherwise LGTM.

if (!isExperimentOn(win, 'version-locking')) {
return false;
}
if (typeof fnOrStruct == 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Which extensions still use a function?

Copy link
Contributor

Choose a reason for hiding this comment

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

Bunch of code that wants AMP to initialize does, not necessarily extensions. E.g. viewer integration scripts (e.g. from Google Search) do that and bunch of PWA functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically non-AMP code.

`[custom-element="${fnOrStruct.n}"]:not([i-amphtml-inserted])`);
dev().assert(scriptInHead, 'Expected to find script for extension: %s',
fnOrStruct.n);
if (!scriptInHead) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain this one? Why wouldn't we insert one even if it didn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is an assertion above that makes this code unreachable in development. I think in prod it makes sense to just move forward as if nothing happened in this case.

src/runtime.js Outdated
// Mark the element as being replace, so that the loadExtension code
// assumes it as not-present.
scriptInHead.removeAttribute('custom-element');
scriptInHead.setAttribute('i-amphtml-replaced-with-version', fnOrStruct.n);
Copy link
Contributor

Choose a reason for hiding this comment

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

.v?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, tried a new name for the attribute :)

I want the name here for easier traceability of the DOM.

* @return {boolean}
*/
function maybeLoadCorrectVersion(win, fnOrStruct) {
if (!isExperimentOn(win, 'version-locking')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to do instead isExperimentOnAllowUrlOverride?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you explain why you think that makes sense?

@cramforce cramforce merged commit a24dbda into ampproject:master Jan 31, 2017
@cramforce cramforce deleted the version-locking branch January 31, 2017 23:51
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Feb 14, 2017
…sion with the main binary. (ampproject#7239)

For each extension this checks the version, and if it is the wrong version, will ignore the JS file and initiate a load of the correct version.

- experiment guarded. This is likely to break some stuff.
- based on compiled-in version only. rtv is ignored, because we only care about code here, since config is only given in main binary.

Implements locking part of ampproject#7238
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
…sion with the main binary. (ampproject#7239)

For each extension this checks the version, and if it is the wrong version, will ignore the JS file and initiate a load of the correct version.

- experiment guarded. This is likely to break some stuff.
- based on compiled-in version only. rtv is ignored, because we only care about code here, since config is only given in main binary.

Implements locking part of ampproject#7238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants