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

Cover Block: flickering in site editor page view when used within a synced pattern #53211

Closed
andrewserong opened this issue Aug 1, 2023 · 5 comments · Fixed by #53256 or #53253
Closed
Assignees
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@andrewserong
Copy link
Contributor

andrewserong commented Aug 1, 2023

Description

While reviewing #53169 an issue with the Cover block was encountered, where sometimes it will repeatedly flicker when displayed within the site editor's view of an individual page, when the Cover block is contained within a synced pattern that forms part of the template.

The flickering appears to be to do with logic in useCoverIsDark within the Cover block. Specifically, the async state update in:

retrieveFastAverageColor()
.getColorAsync( url, {
// Previously the default color was white, but that changed
// in v6.0.0 so it has to be manually set now.
defaultColor: [ 255, 255, 255, 255 ],
// Errors that come up don't reject the promise, so error
// logging has to be silenced with this option.
silent: process.env.NODE_ENV === 'production',
crossOrigin: imgCrossOrigin,
} )
.then( ( color ) => setIsDark( color.isDark ) );

Kudos @aaronrobertshaw for finding the bug and the lines of code relevant for it!

Step-by-step reproduction instructions

  1. Create a synced pattern that contains a Cover block with a background image set
  2. In a theme like TT3, add a new template (e.g. my-template.html in the templates directory).
  3. Within my-template.html, add the synced block pattern. To get the markup to add to the template, you can add the synced pattern to a post or page, then view the code editor view and copy + paste to your my-template.html file
  4. Create a page and set its template to my-template.html.
  5. Open the site editor, and navigate to Pages > your newly created page. Click the preview of the page to switch to the edit mode, and notice that the Cover block flickers.

Example markup from my my-template.html file:

<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

<!-- wp:pattern {"slug":"core/query-standard-posts"} /-->

<!-- wp:post-content /-->

<!-- wp:post-featured-image /-->

<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

<!-- wp:block {"ref":65} /-->

Screenshots, screen recording, code snippet

2023-08-01.11.44.52.mp4

Environment info

  • GB trunk

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@andrewserong andrewserong added [Type] Bug An existing feature does not function as intended [Block] Cover Affects the Cover Block - used to display content laid over a background image [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels Aug 1, 2023
@andrewserong andrewserong moved this to 🐛 Punted to 6.3.1 in WordPress 6.3.x Editor Tasks Aug 1, 2023
@aaronrobertshaw
Copy link
Contributor

cc @ajlende given your insight in this area due to past updates 🙇

@carolinan
Copy link
Contributor

Did you mean this issue? #52313 or 53169 ?

@ajlende
Copy link
Contributor

ajlende commented Aug 1, 2023

Sorry, I don't have the time to look too deeply into this right now. But, from the video, could the setAttribute in the offending code be sending the component into an update loop somehow?

I wonder if it would be possible to remove the isDark attribute and compute its value on save instead?

@aaronrobertshaw
Copy link
Contributor

Did you mean this issue? #52313 or 53169 ?

#52313 might be related (different replication steps though). #53169 though is definitely unrelated.

@ajlende
Copy link
Contributor

ajlende commented Aug 4, 2023

Sorry it took me a while to get around to testing this. It seems in order to replicate the issue, the image you use must be less than 50% lightness as computed by FAC. On my computer I don't see the flickering, but I added logging to the FAC callback and see it triggering repeatedly.

I see there are already a couple fixes, but it seems my old unmerged PR #45076 that improves the heuristic also seems to fix it.

It looks like the main problem was that there were multiple useEffects that called setState for isDark putting the component into the update loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
No open projects
6 participants