DocInfo: replace metaTags with viewport in API#26687
DocInfo: replace metaTags with viewport in API#26687mdmower merged 2 commits intoampproject:masterfrom
Conversation
|
Alternatives to this PR:
|
src/service/ampdoc-impl.js
Outdated
|
|
||
| // Retain only the first meta content value for a given name, consistent | ||
| // with getMetaByName. | ||
| if (metaMap[name] === undefined) { |
There was a problem hiding this comment.
If metaMap[name] !== undefined), should we emit user().warn('AmpDoc', 'Only the first <meta> tag with a given name is retained');?
| 'amp-consent-blocking' | ||
| ]; | ||
|
|
||
| let content = ampdoc.getMetaByName('amp-consent-blocking'); |
There was a problem hiding this comment.
Nice! I see a lot of other dedupe opportunities when searching for "meta[name=" in the codebase. Would you mind filing a cleanup issue for this?
src/service/ampdoc-impl.js
Outdated
| } | ||
|
|
||
| // Retain only the first meta content value for a given name, consistent | ||
| // with getMetaByName. |
There was a problem hiding this comment.
Not sure this is safe to do since there may be code that's relying on the existing "concat" behavior (instead of only retaining the first meta content).
There was a problem hiding this comment.
I think it is safe, actually. There are very few uses of DocInfo.metaTags, and the array output is never used (in fact, in one place, the array behavior isn't even considered and I was surprised type checking didn't report an error).
Appears so. The only other one I saw was in link-rewriter-manager.js which probably should use I'd be cool with this alternative:
|
|
Actually looks like we send amphtml/src/service/resources-impl.js Lines 783 to 793 in 082e2d6 Added in #14137. Let me follow up internally to see if this is actually used. |
|
It's only used for We should also update amp-doc-viewer-api.md to reflect this change. |
Let me know if the latest version of this PR matches your description, or if you had something else in mind. Thanks! |
|
Oh sorry for the delay, will take a look soon! 👍 |
| 'serverLayout': doc.documentElement.hasAttribute('i-amphtml-element'), | ||
| 'linkRels': documentInfo.linkRels, | ||
| 'metaTags': documentInfo.metaTags, | ||
| 'viewport': documentInfo.viewport, |
There was a problem hiding this comment.
Ah, sorry I meant we still need metaTags in the message contents, but it's OK if it only contains meta[name=viewport].
I.e. I think this should be:
'metaTags': {'viewport': documentInfo.viewport},
'viewport': documentInfo.viewport,Feel free to drop a TODO (or new issue) to rename this once the callers have been migrated to use viewport instead of metaTags.
There was a problem hiding this comment.
I'm happy to do this, but I'm curious where this request to retain DocumentInfo.metaTags['viewport'] is coming from? After this PR, if you grep for metaTags in this repository, you won't find a single hit. So apparently there's a consumer of this API outside of AMPHTML?
Ohhh, oops. I see now. It's not that DocumentInfo.metaTags needs to be retained, it's that the documentLoaded message sent in src/service/resources-impl.js needs to avoid an API breaking change (between the document and the viewer). Got it, sorry, should have looked closer.
|
FYI, it looks like the bundle size test on Travis is not going to complete unless I rebase, but all code comments will be wiped out if I force push. I'll wait for a "go ahead" before rebasing. Until then, code comments threads can continue. |
- Add getMeta to AmpDoc - Replace metaTags with viewport in DocInfo API and propagate change - Update 'documentLoaded' message to viewer to include viewport property, but still provide metaTags.viewport for backwards compatibility - Update amp-doc-viewer documentation - Update unit tests with phony document to include head
|
This is ready for review by an OWNER of |
|
@jridgewell Can you approve |
src/consent.js
Outdated
| .toUpperCase() | ||
| .replace(/\s/g, '') | ||
| .split(','); | ||
| content = content.toUpperCase().replace(/\s/g, ''); |
There was a problem hiding this comment.
Nit: for faster execution
| content = content.toUpperCase().replace(/\s/g, ''); | |
| content = content.toUpperCase().replace(/\s+/g, ''); |
src/service/ampdoc-impl.js
Outdated
| * @return {!Object<string, string>} | ||
| */ | ||
| getMeta() { | ||
| const metaMap = map(); |
There was a problem hiding this comment.
Commit 555d668 takes a stab at this. Let me know if you agree with the implementation.
src/service/ampdoc-impl.js
Outdated
| /** @override */ | ||
| getMeta() { | ||
| const copy = map(); | ||
| for (const k in this.meta_) { |
There was a problem hiding this comment.
Thanks, adopted your suggestion by way of map(opt_initial)
| } | ||
| return metaTags; | ||
| function getViewport(doc) { | ||
| const viewportEl = doc.head.querySelector('meta[name="viewport"]'); |
There was a problem hiding this comment.
Why is this being specialized to viewport metas?
There was a problem hiding this comment.
It's the only meta that's currently being used.
- Cache name/content pairs - Minor optimizations
Cached meta tags feature requires stubbing AmpDoc.getMeta to ensure old meta tags are reused in future tests.
* master: (54 commits) inabox-resources: Minor test improvement (ampproject#26916) DocInfo: replace metaTags with viewport in API (ampproject#26687) 🐛 SwG now uses AMP sendBeacon interface (ampproject#26970) 🏗 Allow array destructuring on preact hooks (ampproject#26901) Gulp Dep Check: fail on unused entries (ampproject#26981) Update no-import lint rule to forbid sub-paths (ampproject#26531) 🐛 amp-ad type blade - fix bladeOnLoad callback (ampproject#26627) 📖 Clarify when max-age is required (ampproject#26956) ♻️ Consolidate players as .i-amphtml-media-component (ampproject#26967) Add Preact Enzyme tests (ampproject#26529) Fixes `update_tests` flag on `gulp validator` (ampproject#26965) 📦 Update dependency google-closure-library to v20200224 (ampproject#26986) 🏗 Transform aliased configured components (ampproject#26541) ✨ InaboxResources: Observe intersections for some elements' viewportCallbacks (ampproject#26942) variable substitutions: Support allowlist lookup in AmpDocShadow (ampproject#26731) cl/297197875 Revision bump for ampproject#26877 (ampproject#26982) Json fix (ampproject#26971) 📦 Update dependency mocha to v7.1.0 (ampproject#26976) Add documentation for amp-access-scroll (ampproject#26782) make controls always shown in amp for email (ampproject#25714) ...
* master: Launch `amp-next-page` v2 & clean up experiment (ampproject#27035) ✨Implement Display Locking on amp-accordion (ampproject#25867) 📖<amp-next-page> documentation and validation (ampproject#26841) Improve visibility event tests (ampproject#26847) amp-geo: Fall back to API for country (ampproject#26407) ✨ Add customization options to <amp-story-quiz> (ampproject#26714) navigation: Minor test improvements (ampproject#26926) ♻️ Alias video.fullscreen action for symmetry with interface names (ampproject#27017) ✨ Implements `amp-analytics` support for `amp-next-page` (ampproject#26451) ✨ amp-video-iframe integration: global jwplayer() singleton by default (ampproject#26969) Fix unit tests broken by ampproject#26687 (ampproject#27000) Filter redirect info from emails (ampproject#27012) 📖 Make amp-bind doc valid, fix amp-form stories filter (ampproject#27003) url-replacements: Minor test improvement (ampproject#26930) viewport: Minor test improvement (ampproject#26931) amp-consent fullscreen warning (ampproject#26467) dep-check: USE CAPS FOR IMPORTANCE (ampproject#26993) fix img url (ampproject#26987) # Conflicts: # extensions/amp-next-page/amp-next-page.md
getMetatoAmpDocmetaTagswithviewportinDocInfoAPI and propagate changedocumentLoadedmessage to viewer to includeviewportproperty,but still provide
metaTags.viewportfor backwards compatibilitydocumentto includehead