Skip to content

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

@andrewserong

Description

@andrewserong

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

Metadata

Metadata

Labels

[Block] CoverAffects the Cover Block - used to display content laid over a background image[Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Feature] Site EditorRelated to the overarching Site Editor (formerly "full site editing")[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions