Skip to content

♻️Move VariableService to doc level#22137

Merged
calebcordry merged 1 commit intoampproject:masterfrom
calebcordry:vars-doc-level
May 6, 2019
Merged

♻️Move VariableService to doc level#22137
calebcordry merged 1 commit intoampproject:masterfrom
calebcordry:vars-doc-level

Conversation

@calebcordry
Copy link
Copy Markdown
Member

h/t to @torch2424 from whom I copypasta'd a lot of this code :)

@calebcordry
Copy link
Copy Markdown
Member Author

This implements part of #19737. It moves the variable service to the doc level, but does not try to move any variables.

@calebcordry calebcordry merged commit 54afc8c into ampproject:master May 6, 2019
@calebcordry calebcordry deleted the vars-doc-level branch May 6, 2019 18:24
Copy link
Copy Markdown
Member

@mattwomple mattwomple left a comment

Choose a reason for hiding this comment

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

Was this commit tested in a PWA with an AMP page that uses amp-analytics? Here's a simple test PWA where installVariableServiceForDoc fails because AMP.ampdoc does not identify the AMP document (it is undefined): https://android.cmphys.com/temp/analytics-referrer-pwa.html . The following stack trace is printed to the console (3 times):

service.js:354 Uncaught (in promise) TypeError: Cannot read property 'nodeType' of undefined
    at getAmpdoc (service.js:354)
    at registerServiceBuilderForDoc (service.js:162)
    at installVariableServiceForDoc (variables.js:297)
    at amp-analytics.js:716
    at Object.global.AMP.extension (runtime.js:189)
    at Object.push.f.2.../../../src/dom (amp-analytics.js:711)
    at o (_prelude.js:1)
    at r (_prelude.js:1)
    at f (_prelude.js:1)
    at Extensions.registerExtension (extensions-impl.js:179)

'amp-analytics-instrumentation', InstrumentationService);
AMP.registerServiceForDoc('activity', Activity);
installVariableService(AMP.win);
installVariableServiceForDoc(AMP.ampdoc);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AMP.ampdoc does not identify the AMP document in a PWA

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for reporting. Will work on the fix tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants