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

Block: Pattern Thumbnail: Fix loading and error state #655

Merged
merged 4 commits into from
Apr 4, 2024

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Apr 2, 2024

Fixes #652 — This updates the pattern preview block to use context for the initial block state (ex, attempts). Previously the state.attempts value was global, so each pattern on the page incremented it. By the time the last patterns on the page are rendered, the attempts value would already be >10, so it would only try the initial fetch and if the mshots image did not exist, it would error - no retries.

This updates the attempts to behave as expected, 10 attempts per pattern. This should cut down on the number of errors per page.

The error display has also been updated, in the case where there are issues. Happy to tweak this if there are any suggestions @StevenDufresne @WordPress/meta-design (screenshot below)

Screenshots

Screenshot 2024-04-02 at 5 01 34 PM

How to test the changes in this Pull Request:

  1. View the pattern archives
  2. The previews should load successfully
  3. If there are any errors, it should not show the broken <img> tag

To check that this is loading correctly from scratch, you could update $cache_key to something random, which will force mshots to re-take the screenshots, and take longer for loading.

To intentionally trigger an error state, update the $cache_key (render.php) and change MAX_ATTEMPTS (view.js) to 1 or 2.

Remember to rebuild if you make those changes.

@ryelle ryelle added the [Component] Theme The frontend of the pattern directory, pattern lists UI label Apr 2, 2024
@ryelle ryelle self-assigned this Apr 2, 2024
@ryelle ryelle changed the title Block: Pattern Preview: Fix loading errors and error state Block: Pattern Thumbnail: Fix loading and error state Apr 2, 2024
@jasmussen
Copy link

Is this the error state?

screenshot of supposed error state

If yes, then I wonder, what might cause that error state to happen? Is this if the thumbnail doesn't load properly? I forgot what error state we use for the Showcase thumbnails, but we should probably use the same here, and omit the duplicated link-text. If the error state for the Showcase is not appropriate, we should use a broken image icon, something like:

Screenshot 2024-04-03 at 08 58 26

SVG:

<svg width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M5 3a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h5l-.121-.121 1.379-1.379H5a.5.5 0 0 1-.5-.5v-2.436l4.096-2.987 2.996 1.941a.75.75 0 0 0 .93-.091L16 12.046l1.375 1.337 1.06-1.06-1.912-1.86a.75.75 0 0 0-1.046 0l-3.571 3.471-2.927-1.897a.75.75 0 0 0-.85.024L4.5 14.707V5a.5.5 0 0 1 .5-.5h14a.5.5 0 0 1 .5.5v6.258l1.5-1.5V5a2 2 0 0 0-2-2H5Zm16 11-1.5 1.5V19a.5.5 0 0 1-.5.5h-3.5L14 21h5a2 2 0 0 0 2-2v-5Z" fill="#1E1E1E"/></svg>

Shown at 24x24px.

@ryelle
Copy link
Contributor Author

ryelle commented Apr 3, 2024

If yes, then I wonder, what might cause that error state to happen? Is this if the thumbnail doesn't load properly?

Yes - though it's pretty rare since we retry fetching the image 10 times.

I forgot what error state we use for the Showcase thumbnails

I'm pretty sure the error state for Showcase is just the site title text (so like this, but without the icon). Since all the sites got custom screenshots (which would never show this), we never got back to requesting design for an error state.

I'll update the image, and see what i can do about the text— we need some text there for accessibility (since it's a link), but perhaps I can hide it better.

@ryelle
Copy link
Contributor Author

ryelle commented Apr 3, 2024

Updated the text & icon, it now looks like this if an image fails to load:

Screenshot 2024-04-03 at 2 31 43 PM

@jasmussen
Copy link

Nice!

@StevenDufresne
Copy link
Collaborator

I'm getting 403's from mShots making it hard to test but since they are from mShots it's probably a fair representation of this branch. The current sequence shows broken image > loader > image. It becomes more pronounced when I add throttling.

The code looks correct from a logic standpoint.

Screen Capture on 2024-04-04 at 09-18-36

@ryelle
Copy link
Contributor Author

ryelle commented Apr 4, 2024

I think you're getting the broken image before the Interactivity API kicks in, so I've tweaked the CSS a bit to hide the image by default. So now you should see the empty grey box -> loader -> image.

I'm going to merge this PR, we can iterate if there are edge cases once it's on production.

@ryelle ryelle merged commit 5ed7a68 into trunk Apr 4, 2024
3 checks passed
@ryelle ryelle deleted the fix/pattern-preview-errors branch April 4, 2024 19:28
@StevenDufresne
Copy link
Collaborator

I'm still getting this on production:

Screen Capture on 2024-04-15 at 13-43-08

ryelle added a commit that referenced this pull request Apr 15, 2024
…r users, hide image on error

This removes the flash of text before the loader kicks in. This text is only used to ensure the link has an accessible name while the image is loading or broken. Once loaded, the image's alt serves this function. If there is an error, the (broken) image should not be visible, and the span provides the accessible text.

See #655 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Theme The frontend of the pattern directory, pattern lists UI
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Block Theme: Broken image links.
3 participants