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

Improve handling of Tumblr embeds #5926

Merged
merged 28 commits into from
Mar 4, 2021

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Feb 25, 2021

Summary

Fixes #4757

Changes are adapted from 21ae657.

Checklist

  • 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).

@pierlon pierlon added the WS:Core Work stream for Plugin core label Feb 25, 2021
@pierlon pierlon added this to the v2.1 milestone Feb 25, 2021
@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #5926 (69e35cb) into develop (0ac7064) will increase coverage by 0.34%.
The diff coverage is 93.35%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #5926      +/-   ##
=============================================
+ Coverage      74.96%   75.31%   +0.34%     
- Complexity      5675     5703      +28     
=============================================
  Files            212      214       +2     
  Lines          17049    17242     +193     
=============================================
+ Hits           12781    12985     +204     
+ Misses          4268     4257      -11     
Flag Coverage Δ Complexity Δ
javascript 79.44% <96.49%> (+4.31%) 0.00 <0.00> (ø)
php 75.14% <91.44%> (+0.18%) 0.00 <49.00> (ø)

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

Impacted Files Coverage Δ Complexity Δ
assets/src/block-editor/helpers/index.js 39.28% <ø> (+11.42%) 0.00 <0.00> (ø)
assets/src/block-validation/error/error-content.js 93.54% <ø> (ø) 0.00 <0.00> (ø)
...c/block-validation/error/get-error-source-title.js 93.75% <ø> (ø) 0.00 <0.00> (ø)
src/AmpWpPlugin.php 100.00% <ø> (ø) 8.00 <0.00> (ø)
includes/cli/class-amp-cli-validation-command.php 18.51% <20.00%> (ø) 33.00 <0.00> (+1.00)
...cludes/validation/class-amp-validation-manager.php 81.52% <50.00%> (-0.84%) 309.00 <0.00> (-10.00)
includes/embeds/class-amp-base-embed-handler.php 48.93% <84.21%> (+24.79%) 21.00 <11.00> (+10.00)
...k-validation/use-validation-error-state-updates.js 84.50% <91.66%> (-9.25%) 0.00 <0.00> (ø)
src/Validation/URLValidationRESTController.php 92.39% <92.39%> (ø) 18.00 <18.00> (?)
includes/embeds/class-amp-tumblr-embed-handler.php 94.28% <96.96%> (+82.52%) 13.00 <11.00> (+8.00)
... and 18 more

@github-actions
Copy link
Contributor

github-actions bot commented Feb 25, 2021

Plugin builds for ad2e9be are ready 🛎️!

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Any idea why this Tumblr post doesn't expand like the other does?

image

includes/embeds/class-amp-base-embed-handler.php Outdated Show resolved Hide resolved
includes/embeds/class-amp-base-embed-handler.php Outdated Show resolved Hide resolved
includes/embeds/class-amp-tumblr-embed-handler.php Outdated Show resolved Hide resolved
includes/embeds/class-amp-tumblr-embed-handler.php Outdated Show resolved Hide resolved
@pierlon
Copy link
Contributor Author

pierlon commented Feb 25, 2021

Any idea why this Tumblr post doesn't expand like the other does?

It should, as the iframe document is sending a embed-size request:

window.parent.postMessage({
	sentinel: "amp",
	type: "embed-size",
	height: document.body.scrollHeight
}, "*")

Ref: https://assets.tumblr.com/client/prod/standalone/embeddable-internal/index.build.js

@pierlon
Copy link
Contributor Author

pierlon commented Feb 25, 2021

From the docs on resizing amp-iframe:

Here are some factors that affect how fast the resize will be executed:

  • Whether the resize is triggered by the user action.
  • Whether the resize is requested for a currently active iframe.
  • Whether the resize is requested for an iframe below the viewport or above the viewport.

So it seems neither of those were happening in your case.

'overflow' => '',
'tabindex' => 0,
'role' => 'button',
'aria-label' => __( 'See more', 'amp' ),
Copy link
Member

Choose a reason for hiding this comment

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

Why is the aria-label needed if the button text is the same?

includes/embeds/class-amp-tumblr-embed-handler.php Outdated Show resolved Hide resolved
Comment on lines 82 to 86
'div',
[
'width' => $this->args['width'],
'height' => $this->args['height'],
'layout' => 'responsive',
'sandbox' => 'allow-scripts allow-popups', // The allow-scripts is needed to allow the iframe to render; allow-popups needed to allow clicking.
'src' => $matches['href'],
],
sprintf( '<a placeholder href="%s">Tumblr</a>', $url )
'overflow' => '',
'tabindex' => 0,
'role' => 'button',
Copy link
Member

Choose a reason for hiding this comment

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

I think we can rather use a button here. Then we won't need the role nor tabindex attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 7df8bbe. Here's how it looks in Twenty Twenty with the button:

image

Copy link
Member

Choose a reason for hiding this comment

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

Very good.

includes/embeds/class-amp-tumblr-embed-handler.php Outdated Show resolved Hide resolved
includes/embeds/class-amp-base-embed-handler.php Outdated Show resolved Hide resolved
@westonruter
Copy link
Member

So it seems neither of those were happening in your case.

Oh, of course. It's because the embed was in the initial viewport.

The problem is that the overflow button is not being shown:

image

It needs some positioning to ensure it appears. It already has position:absolute from AMP. I think it just needs bottom:0 for example.

@westonruter
Copy link
Member

I just checked in Twenty Twenty One and the button on hover has a transparent background:

button-background-tt1.mov

Should we consider this a theme bug?

@westonruter
Copy link
Member

Also, for some reason I sometimes am seeing the button positioned outside the container making it invisible:

Screen Shot 2021-02-25 at 21 31 17

It's strange because I didn't see it this way when testing a bit ago. But now I am. The issue is fixed for me via 3323625.

@pierlon
Copy link
Contributor Author

pierlon commented Feb 26, 2021

I just checked in Twenty Twenty One and the button on hover has a transparent background...

It seems that is intentional as the button wasn't meant to be displayed over a dark background.

I wonder if we should set a background color for the button as well.

@westonruter
Copy link
Member

I wonder if we should set a background color for the button as well.

I tried setting white as the background of the button without success:

white-background-on-light-mode.mov
white-background-on-dark-mode.mov

I guess we'd have to set the color on a wrapper element instead? Or add a ::before pseudo element that is positioned absolutely behind the element? Ugh.

],
sprintf( '<a placeholder href="%s">Tumblr</a>', $url )
'overflow' => '',
'style' => 'bottom:0',
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this might as well be moved to amp-default.css via this new rule:

button[overflow] {
	bottom: 0;
}

This will have low specificity which will allow it to be easily overridden by themes/plugins.

Suggested change
'style' => 'bottom:0',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm no longer able to replicate the button being outside of the amp-iframe. Can you confirm if this is still needed? It seems the rule is already being set by the browser:

image

Copy link
Member

Choose a reason for hiding this comment

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

I'm not seeing that:

image

Nevertheless, I did seem to see that previously, but now I'm not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, OK it won't hurt to add it as a rule in amp-default.css then.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't it already have position: absolute from AMP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes but that specific rule does not apply for me all the time, which is weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I was using a modified version of ampshared.css. So all that needs to be set as you mentioned earlier is:

button[overflow] {
    bottom: 0;
}

Copy link
Member

Choose a reason for hiding this comment

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

Very good. Make it so.

Copy link
Member

Choose a reason for hiding this comment

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

Filed Optimizer issue upstream: ampproject/amp-toolbox#1155.

@pierlon pierlon requested a review from westonruter March 4, 2021 04:04
@westonruter westonruter changed the title Sanitize Tumblr embeds Improve handling of Tumblr embeds Mar 4, 2021
@westonruter westonruter merged commit 1a1ad95 into develop Mar 4, 2021
@westonruter westonruter deleted the fix/4757-tumblr-embed-validation-error branch March 4, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WS:Core Work stream for Plugin core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tumblr embeds cause validation errors and fail to embed
2 participants