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

Add DevMode helper and keep devmode nodes during optimization #4371

Merged
merged 4 commits into from
Mar 9, 2020

Conversation

schlessera
Copy link
Collaborator

Summary

This PR makes the following changes:

  • Adds a new AmpProject\DevMode helper class (with tests);
  • Deprecates the devmode-related methods in AMP_Base_Sanitizer;
  • Moves usage of the deprecated AMP_Base_Sanitizer methods over to the new AmpProject\DevMode helper class;
  • Ensures that the AmpBoilerplate transformer does not remove nodes that are marked as being in devmode.

The AmpProject\DevMode helper class was introduced (and the AMP_BaseSanitizer code deprecated) because the ampproject/optimizer cannot have a dependency pointing to the plugin package. Dependencies can only ever be allowed the other way around.

Fixes #4369

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot googlebot added the cla: yes Signed the Google CLA label Mar 9, 2020
@schlessera schlessera added Optimizer Bug Something isn't working labels Mar 9, 2020
while ($headNode) {
$nextSibling = $headNode->nextSibling;
if ($headNode instanceof DOMElement) {
if ($headNode instanceof DOMElement && (! $devMode || ! DevMode::hasExemptionForNode($headNode))) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not use isExemptFromValidation?

Suggested change
if ($headNode instanceof DOMElement && (! $devMode || ! DevMode::hasExemptionForNode($headNode))) {
if ($headNode instanceof DOMElement && ! DevMode::isExemptFromValidation($headNode)) {

Then $devMode variable could be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it's a loop, and that would do the check against the document multiple times although it's only needed once.

Copy link
Member

Choose a reason for hiding this comment

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

OK. But that's almost always true for other instances of where isExemptFromValidation is used currently.

I don't feel strongly about this.

@@ -74,9 +75,10 @@ public function transform(Document $document, ErrorCollection $errors)
private function removeStyleAndNoscriptTags(Document $document)
{
$headNode = $document->head->firstChild;
$devMode = DevMode::isActiveForDocument($document);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$devMode = DevMode::isActiveForDocument($document);

Copy link
Contributor

@pierlon pierlon left a comment

Choose a reason for hiding this comment

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

Agreed with @westonruter's comments, otherwise looks good!

@westonruter westonruter added this to the v1.5 milestone Mar 9, 2020
@westonruter westonruter merged commit 60ad49b into develop Mar 9, 2020
@westonruter westonruter deleted the 4369-keep-ampdevmode-elements-in-optimizer branch March 9, 2020 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working cla: yes Signed the Google CLA Optimizer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimizer strips admin bar style[data-ampdevmode]
4 participants