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

Try using AMP Optimizer if available #1780

Closed
wants to merge 1 commit into from
Closed

Conversation

swissspidy
Copy link
Collaborator

Summary

Relevant Technical Choices

To-do


Fixes #1276

@codecov
Copy link

codecov bot commented May 14, 2020

Codecov Report

Merging #1780 into main will increase coverage by 14.45%.
The diff coverage is 14.28%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1780       +/-   ##
===========================================
+ Coverage   69.11%   83.56%   +14.45%     
===========================================
  Files         714      770       +56     
  Lines       12498    12997      +499     
===========================================
+ Hits         8638    10861     +2223     
+ Misses       3860     2136     -1724     
Flag Coverage Δ
#karmatests 67.71% <ø> (ø)
#unittests 66.05% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
includes/Story_Renderer.php 64.89% <14.28%> (-21.48%) ⬇️
...ts/src/dashboard/app/views/shared/storyListView.js 93.93% <0.00%> (-2.94%) ⬇️
assets/src/activation-notice/index.js 0.00% <0.00%> (ø)
assets/src/date/getDateObjectWithTimezone.js 100.00% <0.00%> (ø)
bin/utils/constants.js 100.00% <0.00%> (ø)
assets/src/date/index.js 100.00% <0.00%> (ø)
...src/activation-notice/app/config/configProvider.js 100.00% <0.00%> (ø)
...ts/src/story-embed-block/block/embedPlaceholder.js 100.00% <0.00%> (ø)
assets/src/dashboard/app/api/useCategoriesApi.js 91.66% <0.00%> (ø)
assets/src/edit-story/utils/useWhyDidYouUpdate.js 0.00% <0.00%> (ø)
... and 311 more

@github-actions

This comment has been minimized.

@swissspidy swissspidy force-pushed the add/amp-optimizer-ssr branch 3 times, most recently from 100387d to e080946 Compare May 19, 2020 16:49
@swissspidy swissspidy added the AMP Output Issues related to AMP output and validation label May 19, 2020
@swissspidy swissspidy force-pushed the add/amp-optimizer-ssr branch 3 times, most recently from 1cc6acd to b8f3943 Compare May 19, 2020 16:53
@schlessera
Copy link
Contributor

Let me know if you need any assistance with getting the Optimizer to work.

includes/Story_Renderer.php Outdated Show resolved Hide resolved
Comment on lines +382 to +272
// Needed for \AmpProject\Optimizer\Transformer\AmpRuntimeCss.
$content = str_replace( '</head>', '<style amp-runtime></style></head>', $content );
Copy link
Collaborator

Choose a reason for hiding this comment

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

The TransformedIdentifier transformer is what is is responsible for flagging a document as being transformed which would then allow style[amp-runtime], which you are including. So that seems OK. But injecting the element in this way seems not ideal.

Flagging a document as being transformed is normally bound up with a document also going through SSR. Hence the AmpRuntimeCss, ServerSideRendering, and TransformedIdentifier form a pair: https://github.com/ampproject/amp-wp/blob/8d5f29f1f22e6623789dca250901cff0a559e590/includes/class-amp-theme-support.php#L2182-L2194

The ServerSideRendering transformer adds the style[amp-runtime] element. However, why is this not the responsibility of the AmpRuntimeCss transformer?

@schlessera Should this logic be moved from ServerSideRendering to AmpRuntimeCss?

// Emit the amp-runtime marker to indicate that we're applying server side rendering in the document.
$ampRuntimeMarker = $document->createElement(Tag::STYLE);
$ampRuntimeMarker->setAttribute(Attribute::AMP_RUNTIME, '');
$document->head->insertBefore($ampRuntimeMarker, $document->head->hasChildNodes() ? $document->head->firstChild : null);

Copy link
Contributor

Choose a reason for hiding this comment

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

The ServerSideRendering does all the checks to see if SSR can be done, and then tags the runtime to denote that it should be inlined.

The AmpRuntimeCss is responsible for inlining (or linking) the runtime CSS, but only does so if the SSR gave its okay.

That models the way it is also handled in the amp-toolbox implementation.

If we move the generation of the element into the AmpRuntimeCss transformer, we'd need another element/attribute of some sort to provide the information whether inlining should happen or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that stories can't do SSR, should the AmpRuntimeCss be done?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Given that stories can't do SSR, should the AmpRuntimeCss be done?

I don't know too much about AMP SSR, so if you can give me some guidance that would be great :-)

@swissspidy swissspidy changed the base branch from master to main July 20, 2020 10:22
@swissspidy swissspidy added Type: Enhancement New feature or improvement of an existing feature Group: WordPress Changes related to WordPress or Gutenberg integration Pod: WP & Infra labels Jul 29, 2020
@swissspidy swissspidy closed this Aug 6, 2020
@swissspidy swissspidy deleted the add/amp-optimizer-ssr branch August 6, 2020 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP Output Issues related to AMP output and validation Group: WordPress Changes related to WordPress or Gutenberg integration Type: Enhancement New feature or improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leverage AMP Optimizer if possible
4 participants