-
Notifications
You must be signed in to change notification settings - Fork 295
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
Detect AMP modes correctly #7444
Conversation
Build files for 46ef775 have been deleted. |
Size Change: +2.44 kB (0%) Total Size: 1.41 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kuasha420, this is generally looking good. I've left a few comments, please take a look.
} ); | ||
it.each( [ AMP_MODE_PRIMARY, AMP_MODE_SECONDARY ] )( | ||
'should be labeled as "Web Container" in a %s AMP context', | ||
( mode ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a small change, but let's rename mode
to ampMode
, it's more explicit and means the provideSiteInfo()
args below can use the shorthand { ampMode }
:)
( mode ) => { | |
( ampMode ) => { |
registry | ||
.dispatch( MODULES_TAGMANAGER ) | ||
.finishResolution( 'getContainers', [ accountID ] ); | ||
provideSiteInfo( registry, { ampMode: mode } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above:
provideSiteInfo( registry, { ampMode: mode } ); | |
provideSiteInfo( registry, { ampMode } ); |
} | ||
|
||
const label = isSecondaryAMP | ||
const label = ampMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot here. We should do the same thing in AMPContainerSelect
to keep the labels in sync:
site-kit-wp/assets/js/modules/tagmanager/components/common/AMPContainerSelect.js
Lines 98 to 100 in 269748d
const label = isSecondaryAMP | |
? __( 'AMP Container', 'google-site-kit' ) | |
: __( 'Container', 'google-site-kit' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's no scenario where it would render as only container, as we're rendering Web Container unconditionally. I'll remove this logic so it is always AMP Container
.
@@ -323,13 +321,14 @@ public function is_amp() { | |||
* false if AMP not active, or unknown mode | |||
*/ | |||
public function get_amp_mode() { | |||
// If the Web Stories plugin is enabled, consider the site to be running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With regard to the changes in this file, IMHO it would be a little cleaner to move the non-web stories code into a separate function, say get_amp_mode_from_amp_plugin()
, and then this function could be simplified along these lines. What do you think?
public function get_amp_mode() {
$amp_mode = $this->get_amp_mode_from_amp_plugin();
if ( false === $amp_mode ) {
// If the Web Stories plugin is enabled, consider the site to be running
// in Secondary AMP mode.
if ( defined( 'WEBSTORIES_VERSION' ) ) {
return self::AMP_MODE_SECONDARY;
}
}
return $amp_mode;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice one @kuasha420!
Summary
Addresses issue:
secondary
rather thanprimary
AMP mode (V2 AMP plugin). #5118Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist