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

Site Editor Compatibility: Fix layout of latest instagram posts cross browser #19529

Merged
merged 7 commits into from
Apr 21, 2021

Conversation

aaronrobertshaw
Copy link
Contributor

Fixes #19466

Changes proposed in this Pull Request:

  • Updates the latest instagram posts' styles to prevent the images stretching out to 100% height with the FSE

Does this pull request change what data or activity we track or use?

No change.

Testing instructions:

  1. With the Gutenberg plugin active (>=10.4.0-rc1), activate a block-ready theme (like tt1-blocks)
  2. In the site editor, insert an Instagram Latest Posts block into the Footer template part
  3. Connect an account, and note that the images are loaded much too tall vertically
  4. Checkout this PR, rebuild, then reload the site editor
  5. The images should now be the expected square layout
  6. Confirm the latest instagram posts block still displays correctly in the normal post editor and on the frontend
  7. Test across different browsers. Especially Safari as it behaves slightly differently in terms of calculating dimensions of flex/grid layouts.

Screenshots

Before After
Screen Shot 2021-04-14 at 12 46 52 pm Screen Shot 2021-04-14 at 12 49 12 pm

@aaronrobertshaw aaronrobertshaw added [Block] Latest Instagram Posts [Focus] FSE Issues related to the site editor / Full Site Editing / FSE feature in Gutenberg labels Apr 14, 2021
@aaronrobertshaw aaronrobertshaw requested a review from a team April 14, 2021 03:03
@aaronrobertshaw aaronrobertshaw self-assigned this Apr 14, 2021
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello aaronrobertshaw! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D60136-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Apr 14, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: May 4, 2021.
  • Scheduled code freeze: April 26, 2021.

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Apr 14, 2021
@aaronrobertshaw aaronrobertshaw added [Status] Needs Team Review and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Apr 14, 2021
@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Apr 14, 2021
@aaronrobertshaw aaronrobertshaw removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Apr 14, 2021
@andrewserong
Copy link
Member

andrewserong commented Apr 14, 2021

Thanks for working on this one @aaronrobertshaw! It's looking good when the feed is made up of square images. On my Instagram, though, I've got a range of image sizes from square to portrait and landscape. On the front end (and in the post editor before this change), the images get the portrait layout (perhaps because the first image is portrait?) and the height: 100% paired with object-fit: cover causes the remaining images to fill out the container. With this change, in the editor, the images retain their height resulting in below (tested in Chrome on macOS):

Front end view Editor view
image image

I'm not quite sure what the solution is... would it be possible for the img tag to retain height: 100%, but for the height on .wp-block-jetpack-instagram-gallery__placeholder.is-loaded to be set to something else?

@aaronrobertshaw
Copy link
Contributor Author

I'm not quite sure what the solution is... would it be possible for the img tag to retain height: 100%, but for the height on .wp-block-jetpack-instagram-gallery__placeholder.is-loaded to be set to something else?

I'll take another run at it. Browsers seem to differ on how they calculate their layouts for flex and grid. In Safari for example the 100% in the editor is causing the grid rows to get the full image height.

@aaronrobertshaw
Copy link
Contributor Author

@andrewserong I believe the handling of varying aspect ratios has been fixed now if you'd like to give it another try. It's working for me across browsers with a mix of landscape, square and portrait images.

Rather than forcing 100% height, the new approach relies on letting the flex layout grow the image to the appropriate height.

@andrewserong
Copy link
Member

Nice, that's fixed that up @aaronrobertshaw. In Chrome, Firefox, and Safari, the images are rendering at the correct full height now. Unfortunately, I noticed another issue on Safari that isn't present before this change in the post editor... it looks like the image spacing slider isn't working in Safari, but is working for me in Firefox and Chrome. I also notice that in Safari click out and into the block is inconsistent as to whether or not it registers the block as being selected, but I'm not sure whether that's an issue in FSE, or with this CSS change.

@aaronrobertshaw
Copy link
Contributor Author

Unfortunately, I noticed another issue on Safari that isn't present before this change in the post editor

Thanks for the thorough testing, one step forwards...two steps back 🙂

I'll work on resolving the new issues tomorrow.

@andrewserong
Copy link
Member

Thanks for persevering with it! 🙂

@aaronrobertshaw
Copy link
Contributor Author

it looks like the image spacing slider isn't working in Safari

After a quick test, it appears for me that changing the image spacing doesn't force Safari to redraw the grid.

If I adjust the value, save the post and reload. The correct spacing is displayed. Toggling the any of the grid styles in Safari's dev tools force it to update as well.

@aaronrobertshaw
Copy link
Contributor Author

It turns out that the inline padding on grid children is required to cause Safari to redraw the grid. This padding was previously removed via a padding: 0 !important CSS rule so it didn't "double up" the grid gap once that was rendered.

The theory is with a change in the display type and the stylesheets being copied into the site editor's iframe, the order in which the inline styles are applied might be different. This results in the padding: 0 !important always taking affect now as you might expect. Without the padding changing, the redraw of the grid doesn't happen when the grid gap is updated.

The current working solution is to remove that !important rule and counter it with a negative margin in the editor only. Then simply omit the inline padding when the block is dynamically rendered on the frontend. From my testing so far this is working cross browser for me.

If anyone has any better, less hacky, ideas on solving this one, I'd be happy to hear them!

Otherwise, some extra testing would be helpful 🙂

@ramonjd
Copy link
Member

ramonjd commented Apr 19, 2021

Nice sleuthing on this one!

I've tested the following in Chrome, Firefox, Edge and Safari in both site and block editors:

✅ Instagram images appear as expected (cover, and not stretched)
✅ Controls work as expected, including column and image spacing

Apr-19-2021 15-51-14

On the frontend the correct inline style is applied for the grid gap. Here I chose 50px in the editor:

Screen Shot 2021-04-19 at 3 54 34 pm

ramonjd
ramonjd previously approved these changes Apr 19, 2021
Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

Tested across desktop browsers

Image-stretch as well as spacing adjustment is resolved in Safari. Looks good in other browsers as well.

🎉

@aaronrobertshaw aaronrobertshaw added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Team Review labels Apr 19, 2021
@andrewserong
Copy link
Member

@aaronrobertshaw this is testing well at desktop sizes for me across Safari, Chrome, FF and Edge. However, I think it introduces a regression for the Stack on mobile layout. If that's deselected, then the mobile view correctly has spacing:

image

If I select stack on mobile, and then view in a narrow viewport, I get this before and after (tested in the post editor on a Varia theme):

Before this change After this change
image image

So, I wonder if that was another thing that depended on the padding?

@aaronrobertshaw aaronrobertshaw added [Status] In Progress and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Apr 19, 2021
andrewserong
andrewserong previously approved these changes Apr 19, 2021
Copy link
Member

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Nice, that's done the trick, the responsive stacked view on mobile is working for me now. Just did a quick smoke test in desktop Safari and Chrome too, and looking good. Thanks for following up with all the edge cases @aaronrobertshaw! 👍

image

@andrewserong andrewserong added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Apr 19, 2021
@jeherve jeherve added this to the jetpack/9.7 milestone Apr 19, 2021
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This tests well for me. I only have one minor remark.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Apr 19, 2021
@aaronrobertshaw aaronrobertshaw added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Apr 20, 2021
@aaronrobertshaw aaronrobertshaw requested a review from jeherve April 20, 2021 01:33
@aaronrobertshaw aaronrobertshaw force-pushed the fix/latest-instagram-posts-layout branch from 8cc148c to 4106c6f Compare April 20, 2021 01:43
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Apr 20, 2021
@aaronrobertshaw aaronrobertshaw merged commit c933a85 into master Apr 21, 2021
@aaronrobertshaw aaronrobertshaw deleted the fix/latest-instagram-posts-layout branch April 21, 2021 04:06
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Apr 21, 2021
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D60136-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@aaronrobertshaw
Copy link
Contributor Author

Deployed: rWP224580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latest Instagram Posts [Focus] FSE Issues related to the site editor / Full Site Editing / FSE feature in Gutenberg [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site Editor Compatibility: Instagram Gallery Block styling issues in editor
5 participants