-
Notifications
You must be signed in to change notification settings - Fork 846
Improve Story block media loading #16663
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
Conversation
|
Caution: This PR has changes that must be merged to WordPress.com |
|
Thank you for the great PR description! When this PR is ready for review, please apply the E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-16663 Scheduled Jetpack release: September 1, 2020. |
27619fe to
a94e373
Compare
… images when available, hide play button by default
…ot reset story on slides change
… the content fits the screen its viewed on
…filter support on safari
…play poster image on load if first slide is a videopress media
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
| add_action( 'init', __NAMESPACE__ . '\register_block' ); | ||
|
|
||
| /** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for now, but I wonder if we could simplify some of this by relying on existing Jetpack features (namely Photon) to do all that work for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think photon could simplify some of the logic here. I'm still not fully convinced this block should depend on jetpack features as it could actually be moved to gutenberg core or somewhere else. For now I think trying to simply reuse the already available versions of an image makes sense.
extensions/blocks/story/story.php
Outdated
| function render_slide( $media, $index ) { | ||
| function render_slide( $media, $index = 0 ) { | ||
| $media_template = ''; | ||
| switch ( ! empty( $media['type'] ) && $media['type'] ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could return early if we don't have that information? No need to even output an empty div.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, indeed I updated this while you were reviewing 👍
extensions/blocks/story/story.php
Outdated
| <path d="M0 0h24v24H0z" fill="none"></path> | ||
| <path fill-rule="evenodd" clip-rule="evenodd" d="M6 3H14V17H6L6 3ZM4 3C4 1.89543 4.89543 1 6 1H14C15.1046 1 16 1.89543 16 3V17C16 18.1046 15.1046 19 14 19H6C4.89543 19 4 18.1046 4 17V3ZM18 5C19.1046 5 20 5.89543 20 7V21C20 22.1046 19.1046 23 18 23H10C8.89543 23 8 22.1046 8 21H18V5Z"></path> | ||
| </svg> | ||
| <span>%s</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <span>%s</span> | |
| <span>%d</span> |
extensions/blocks/story/story.php
Outdated
| */ | ||
| function render_pagination_bullet( $slide_index ) { | ||
| return sprintf( | ||
| '<button class="wp-story-pagination-bullet" aria-label="Go to slide %d"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think <button> may cause issues on WordPress.com, I'm not sure it's allowed there. It may be best to have an a instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know, do you know more about this?
In general, I try to stay away from anchor tags when there is no href attribute to point to, which is the case here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may tell you a bit more:
- p5TWut-gm-p2
- Slideshow: Replace Buttons With A Tags wp-calypso#31175 (that's back when Jetpack blocks were still developed in the Calypso monorepo, but the code still uses
atags to this day:
<a
As you can see, the no href issue was discussed in that PR as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, will convert every button, just to be on the safe side
extensions/blocks/story/story.php
Outdated
| */ | ||
| function render_pagination_bullet( $slide_index ) { | ||
| return sprintf( | ||
| '<button class="wp-story-pagination-bullet" aria-label="Go to slide %d"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend translating that string.
| */ | ||
| import { createElement } from '@wordpress/element'; | ||
|
|
||
| const CalypsoSpinner = () => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use Core's spinner here instead?
https://github.com/WordPress/gutenberg/tree/master/packages/components/src/spinner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We explored this with Megs but she preferred we use the calypso spinner which looks much better for our case here.
|
Thanks for the review @jeherve I'm going to address your comments.
Oh right I can reproduce when using drag n drop. Fixing this 👍
Not sure how you ended up with this, it seems like nor the CSS nor the JS is loaded, do you have any error in the console? |
No error in the console, no. Not quite sure what happened. this may have been a fluke of my testing site, I'll try again in my next review. |
|
@jeherve Thanks, I addressed most of your concerns. I only replaced the button elements on the server side for now. #16852 is supposed to replace the custom buttons with Other than that, I'm not sure what your error is, are we talking about the site frontend, or the calypso reader (the latter is still in progress here)? Could you double check that beta blocks is enabled and that |
jeherve
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well now, and I can't reproduce the issues I was facing earlier. 🚢
* master: (23 commits) Premium Blocks: set blocks availability (#16898) Compat Package: Fix method declaration compatibility (#16900) Jetpack Dashboard: More meaningful error notices. (#16883) Connection REST API: Unit test for the `remote_authorize` request. (#16879) use blog token to request jetpack.updateBlog (#16698) Improve Story block media loading (#16663) Simplify error notices for broken connections (#16655) Use new heartbeat package (#16285) wrap-paid-block: remove component. deprecated. (#16895) Social Previews: improve preview description handling (#16889) Stats module use blog token (#16727) Form Block: add a new Consent Field, a new Newsletter setting, and a new newsletter variation (#16808) AAG: Backup card, fall back to VP content in case of /rewind API error. (#16867) Donations: Fix dependencies (#16892) Creative Mail: update option to lowercase (#16861) Premium Blocks: Implement the new design (#16611) Requests to Stats CSV use the blog token (#16716) Update spacing around sharing buttons to avoid no bottom margin below the customize link. (#16811) Jetpack SSO: Cleaning up the `requestNonce` API request. (#16830) Donations: Update plans when currency changes (#16844) ...
* Load media dynamically to improve TTI (Time To Interaction) on page load * Show loading screen in block editor while media is uploading. Display images when available, hide play button by default * Remove comment * Make sure loading screen is 100% width in fullscreen * Allow previewing images while uploading by locking post save and do not reset story on slides change * Try to load the full video before playing using fetch * Only try full loading videos if no CORS * Show loading state if ANY slide is still uploading * [Design update] Reduce embed size and show slide count * Box shadow animation on hover * Disable box shadow animation in fullscreen * Reset overflow slide wrapper and fix blur for IE * Fix replay when exitFullscreenOnEnd is false and cleanup * Disable tap to pause * Disable highlight on overlay press on android * Use layout effect for launching into fullscreen * Minor style fix in block editor to align controls * Render slide count from the server * Show slide count when block is not selected in the block editor * Add srcset and sizes attributes dynamically for slides with images so the content fits the screen its viewed on * Auto crop sides of images if ratio is close to 9:16 * Save width and height as part of the media attributes * Fix missing closing tag * Auto crop videos as well * Try to fit media in screens close to 9:16 * Refine autocrop and default it to 20% * Add expand icon alternative to slide count and allow customization of the player from the block settings attribute * Server side crop as well * Default to the expand icon version * Zoom on embed on hover and display pagination from server * Remove replay button on end * Hide mute icon for images * Fix minor UI glitches * Try tweaking animation * Tweak embed animation * Fix and refine UI for story block on the block editor * Get width and height from media_details on upload * Fix next slide in block editor * Cleanup unused dependencies * Allow modifying the story settings from url when there's only one story on the page * Override button CSS shadow properties as used on P2s * Display story in fullscreen over WordPress admin bar * Add setting to autoplay story on load * Make background transparent instead of using opacity to fix backdrop filter support on safari * Videopress: fix video url if incorrect in the block attribute and display poster image on load if first slide is a videopress media * Make the story a link to the post itself until the JS is loaded * Fix adding new slides using drag n drop by setting the addToGallery param (even though it's not a gallery) * Replace button tags with a on the server side and allow empty stories * Return early if no media type for a slide



Addresses part of #16591:
With this change we stop rendering all the slides dynamically from the server. Instead we only render the first one and serialize the media into the markup so the client can retrieve it and load slides dynamically. Slides are rendered as the story is played, with a preload of the next slide.
It also applies the latest changes in design regarding stories:
This doesn't update buttons to use
@wordpress/elementnor fixes accessibility issues, those are tackled in this PR #16852Here is how it looks like:
Frontend:

Block Editor:

Changes proposed in this Pull Request:
In this PR we lazy load media while stories are being played. This way, we improve the initial page load speed.
We also define a list of alternative images for each slide using srcset and force the browser to load the right image for the current viewport.
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Load a page with a story in it. Notice in the network tab only the fist slide is loaded.
Disable JS and reload the page, notice the story looks almost identical as the version with JS
Proposed changelog entry for your changes: