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

Detect AMP modes correctly #7444

Merged
merged 7 commits into from
Aug 21, 2023
Merged

Conversation

kuasha420
Copy link
Contributor

@kuasha420 kuasha420 commented Aug 16, 2023

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 5.6.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Build files for 46ef775 have been deleted.

@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Size Change: +2.44 kB (0%)

Total Size: 1.41 MB

Filename Size Change
./dist/assets/js/35-********************.js 3.12 kB -1 B (0%)
./dist/assets/js/googlesitekit-activation-********************.js 22.4 kB -8 B (0%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 54.5 kB +2.96 kB (+6%) 🔍
./dist/assets/js/googlesitekit-adminbar-********************.js 33 kB -11 B (0%)
./dist/assets/js/googlesitekit-api-********************.js 9.83 kB -13 B (0%)
./dist/assets/js/googlesitekit-components-gm2-********************.js 5.62 kB +6 B (0%)
./dist/assets/js/googlesitekit-components-gm3-********************.js 9.99 kB +2 B (0%)
./dist/assets/js/googlesitekit-data-********************.js 2.18 kB +2 B (0%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.25 kB -10 B (0%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.09 kB +1 B (0%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 16.6 kB -20 B (0%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 9.35 kB -6 B (0%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 23.5 kB -49 B (0%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 65.2 kB +66 B (0%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 81.8 kB +152 B (0%)
./dist/assets/js/googlesitekit-modules-********************.js 21.3 kB -409 B (-2%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 107 kB -317 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 66.7 kB +69 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-********************.js 88.7 kB -86 B (0%)
./dist/assets/js/googlesitekit-modules-optimize-********************.js 19.6 kB +60 B (0%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 21.3 kB +6 B (0%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 60.3 kB +322 B (+1%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 31.6 kB -39 B (0%)
./dist/assets/js/googlesitekit-polyfills-********************.js 379 B -1 B (0%)
./dist/assets/js/googlesitekit-settings-********************.js 48 kB +27 B (0%)
./dist/assets/js/googlesitekit-splash-********************.js 65.3 kB +52 B (0%)
./dist/assets/js/googlesitekit-user-input-********************.js 40.8 kB +69 B (0%)
./dist/assets/js/googlesitekit-vendor-********************.js 317 kB -439 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 26.7 kB -3 B (0%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 63.1 kB +54 B (0%)
./dist/assets/js/runtime-********************.js 1.3 kB +3 B (0%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 51.4 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.2 kB
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 7.55 kB
./dist/assets/js/30-********************.js 2.8 kB
./dist/assets/js/31-********************.js 2.28 kB
./dist/assets/js/32-********************.js 3.72 kB
./dist/assets/js/33-********************.js 929 B
./dist/assets/js/34-********************.js 888 B
./dist/assets/js/analytics-advanced-tracking-********************.js 769 B
./dist/assets/js/googlesitekit-i18n-********************.js 3.92 kB

compressed-size-action

Copy link
Collaborator

@techanvil techanvil left a 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 ) => {
Copy link
Collaborator

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 } :)

Suggested change
( mode ) => {
( ampMode ) => {

registry
.dispatch( MODULES_TAGMANAGER )
.finishResolution( 'getContainers', [ accountID ] );
provideSiteInfo( registry, { ampMode: mode } );
Copy link
Collaborator

Choose a reason for hiding this comment

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

As mentioned above:

Suggested change
provideSiteInfo( registry, { ampMode: mode } );
provideSiteInfo( registry, { ampMode } );

}

const label = isSecondaryAMP
const label = ampMode
Copy link
Collaborator

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:

const label = isSecondaryAMP
? __( 'AMP Container', 'google-site-kit' )
: __( 'Container', 'google-site-kit' );

Copy link
Contributor Author

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
Copy link
Collaborator

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;
	}

Copy link
Collaborator

@techanvil techanvil left a 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!

@techanvil techanvil merged commit 4ae5c57 into develop Aug 21, 2023
@techanvil techanvil deleted the enhancement/#5118-correct-amp-mode branch August 21, 2023 16:31
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.

2 participants