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

SPT: preview into an iFrame element #39628

Merged
merged 30 commits into from
Feb 28, 2020
Merged

SPT: preview into an iFrame element #39628

merged 30 commits into from
Feb 28, 2020

Conversation

retrofox
Copy link
Contributor

@retrofox retrofox commented Feb 24, 2020

Changes proposed in this Pull Request

This PR injects starter page template blocks into an iframe in order to more accurately preview what the templates look like.

A user wants the starter page template previews to match what they will see when they apply the template selection and are moved into the editor.

Related issues:

Fixes #39341.
Fixes #38779.
Related #39348, #39352, #39355.

Dev Setup For Testing

See existing documentation for setting up FSE plugin development. In addition, you will need these plugins active on your local environment, likely via a mounted volume:

  • Compile SPT plugin from apps/full-site-editing directory in calypso:
npx lerna run dev --scope='@automattic/full-site-editing' --stream --no-prefix
  • Have WPCOM sandbox running

Testing instructions

Once the env dev is set up:

  1. Create a new page. The templates selector should appear.
  2. Switch the template. See the template in the Large Preview.

WIP...

TODO

We need to test each starter template to see if the preview matches the editor view. (select the template, then apply the layout by selecting the top right "Use ___ Layout" button). If one of them is broken, please document:

  • which template it is,
  • which block is not rendering correctly,
  • and which theme you are using.
  • if this error is also in master or not.
  • if you consider this error blocking or not

Template Sections to Check

  • About
  • Blog
  • Contact
  • Menu
  • Portfolio
  • Services
  • Team
  • Home Pages

Other

  • Identify other bugs related to Starter Template preview that are not present in master
  • Fixing any identified bugs :)
  • core/cover block previewing
  • Post Title preview should respect theme settings for alignment (centered vs left aligned, etc)

@retrofox retrofox requested a review from a team as a code owner February 24, 2020 14:54
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

content: __( 'Select a layout to preview.', 'full-site-editing' ),
} )
: [
createBlock( 'core/heading', {
Copy link
Member

@simison simison Feb 25, 2020

Choose a reason for hiding this comment

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

Note that core/site-title is now available too, if it helps. :-)

Copy link
Contributor Author

@retrofox retrofox Feb 25, 2020

Choose a reason for hiding this comment

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

makes a lot of sense. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it available?

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 mean I'm not able to create a core/site-title block.

> wp.data
  .select( 'core/blocks' )
  .getBlockTypes()
  .map( block => block.name )
  .filter( name => name.match( /title/ ) );

it returns an empty [] array

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right. We have Gutenberg 7.3.0 on wpcom currently (about to be updated to 7.6.0, p7DVsv-8c5-p2) and it likely doesn't have it yet.

Even once that's rolled out, I'd expect to have Atomic sites which are on an older versions of Gutenberg or have disabled it completely. I don't know if the whole FSE plugin with SPTs loads in that case tho.

Copy link
Contributor

Choose a reason for hiding this comment

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

@simison Can you spin out a separate Issue for this one so it can be tracked? I think it's unlikely that we'll tackle it here. Much appreciated.

@noahtallen
Copy link
Contributor

It looks like the FSE plugin test failures are only because the behavior of FSE has changed :)

}

// coblocks/gallery mock
.coblocks-gallery {
Copy link
Member

Choose a reason for hiding this comment

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

Could we please not include override-CSS like this if it's normally generated by JS? Let's solve the root problem instead.

It's going to be hugely problematic for keeping this CSS updated together with CoBlocks plugin version updates.

The JS also takes into account the viewport width, number, and size of images, so this CSS will need updating each time we change anything in the template or if we want to implement mobile previews, or just scale down the page in the browser window.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a good point. It will be a tricky one to tackle.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also nervous about handling Block specific overrides in this way.

Also, can I check this is definitely within the scope of this PR? If not then I'd recommend we split this out and handle separately in order to keep your PR super focused.

@obenland
Copy link
Member

It's looking pretty good!

I noticed that in the Contact templates there are still some style issues (first, second, and fifth) and the Menu template is pretty broken.
The social media icons seem a bit off center and the linked-in one isn't always visible.
In the fifth contact page there is an empty paragraph block visible (Content…)

Could you rebase with master so the preview icons are back to being square etc?

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

I'm doing a first pass of this to try and get my head into it. As I did this I noticed some minor issues we could address together.

@@ -291,8 +281,7 @@ body.admin-bar:not( .is-fullscreen-mode ) .page-template-modal-screen-overlay {
right: $preview-right-margin;
background: $template-selector-empty-background;
border-radius: 2px;
overflow-x: hidden;
overflow-y: auto;
overflow: hidden;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why this changed to a single value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, it's not needed I think. Let me check it. Nice 👁

}

// coblocks/gallery mock
.coblocks-gallery {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also nervous about handling Block specific overrides in this way.

Also, can I check this is definitely within the scope of this PR? If not then I'd recommend we split this out and handle separately in order to keep your PR super focused.

apps/full-site-editing/package.json Outdated Show resolved Hide resolved
getdave added a commit that referenced this pull request Feb 27, 2020
@getdave
Copy link
Contributor

getdave commented Feb 27, 2020

I'm concerned that this PR touches so many files that it could introduce regressions. For example I'm seeing the Contact Forms "placeholder" state showing up again in previews.

Just a note of caution as I know we're keen to land this one.

@obenland obenland changed the title [wip] SPT: preview into an iFrame element SPT: preview into an iFrame element Feb 27, 2020
@retrofox retrofox force-pushed the add/spt-dynamic-preview branch from ac40e9b to 03e9464 Compare February 27, 2020 19:42
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello retrofox! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D39555-code before merging this PR. Thank you!

This PR performs a refactoring in the templates previewing process, among other important changes. About the previewing, it moves the rendered blocks into an iFrame in order to apply CSS queries properly into the preview viewport. Other changes: remove the template title component and adding it as a template block for the preview, reduce CSS, etc.
@retrofox retrofox force-pushed the add/spt-dynamic-preview branch from 03e9464 to 6a26bb5 Compare February 27, 2020 19:53
@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@simison
Copy link
Member

simison commented Feb 27, 2020

Aside, and no need in this PR, but you can now include many of these variables directly from a @wordpress/base-styles package:

$template-modal-background-color: #eeeeee;
$template-selector-border-color: #e2e4e7;
$template-selector-border-color-selected: #555d66;
$template-selector-border-color-active: #00a0d2;
$template-selector-border-color-hover: #c9c9ca;
$template-selector-empty-background: #fff;
$template-selector-modal-offset-bottom: 25px;
$template-selector-modal-offset-right: 32px;
$template-selector-blank-template-mobile-height: 70px;
$template-large-preview-title-height: 120px;
// Preview positioning
$preview-right-margin: 24px;
// Breakpoints
$breakpoint-mobile: 660px;
$breakpoint-tablet: 783px;
$breakpoint-desktop: 961px;
$breakpoint-huge: 1648px;
// WP.org sidebar and admin bar sizes
$wp-org-sidebar-full: 160px;
$wp-org-sidebar-collapsed: 36px;
$wp-org-admin-bar-full: 32px;
$wp-org-admin-bar-mobile: 46px;

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

The component’s new behaviour means that the BlockPreview contents are moved into the iframe on render. This means the test cannot find it. Therefore we switch to assert on the prescence of the iframe.
@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

retrofox, Your synced wpcom patch D39555-code has been updated.

Copy link
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

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

Very nice job @retrofox! Thank you for your help @jeryj @getdave @frontdevde

@getdave
Copy link
Contributor

getdave commented Feb 28, 2020

Another enhancement idea would be to avoid those flickering images when we load into the preview. I think we could solve this by:

  • Preloading the images with rel="preload" - find all images in Blocks when we hover over the preview and then create <link rel="preload" ...> for each to preload the asset.
  • Adding a loading spinner whilst the Blocks are being populated into the preview. This isn't great but it's better than seeing flickering images and layout "jank" as the Blocks are loaded into the preview.

@retrofox
Copy link
Contributor Author

Another enhancement idea would be to avoid those flickering images when we load into the preview. I think we could solve this by:

  • Preloading the images with rel="preload" - find all images in Blocks when we hover over the preview and then create <link rel="preload" ...> for each to preload the asset.
  • Adding a loading spinner whilst the Blocks are being populated into the preview. This isn't great but it's better than seeing flickering images and layout "jank" as the Blocks are loaded into the preview.

Among these changes, we should figure out how to reduce the images sizes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Layouts: Missing Margin in Layout Preview SPT: Preview background doesn’t extend when scrolling
7 participants