Skip to content

Fix: Prevent visual jitter when changing block styles#78327

Open
DarkMatter-999 wants to merge 1 commit into
WordPress:trunkfrom
DarkMatter-999:fix/style-jitter-on-variation-change
Open

Fix: Prevent visual jitter when changing block styles#78327
DarkMatter-999 wants to merge 1 commit into
WordPress:trunkfrom
DarkMatter-999:fix/style-jitter-on-variation-change

Conversation

@DarkMatter-999
Copy link
Copy Markdown
Contributor

What?

Closes #77830

This PR updates the BlockProps hook in the block editor to use useLayoutEffect instead of useEffect when setting wrapper properties.

Why?

When a block style variation (like "Rounded") is applied, there is currently a visual "jerk" or flash. This happens because useEffect runs after the browser has already painted the initial state.

In the case of the Image block (e.g., in Twenty Twenty-Four theme):

  1. The browser paints the default "Rounded" style (which defaults to a 9999px border-radius/circle).
  2. useEffect fires, adding the specific theme variation classes (e.g., is-style-rounded-[hash]).
  3. The browser paints again with the theme's specific border-radius (e.g., 20px), causing a visible snap from a circle to a rounded square.

How?

By switching to useLayoutEffect, the wrapper properties (including theme-specific variation classes) are applied synchronously after all DOM mutations but before the browser has a chance to paint. This ensures the very first frame the user sees already contains the correct, theme-defined CSS classes, eliminating the intermediate "fully rounded" state.

Testing Instructions

  1. Use a theme that defines a specific border-radius for the "Rounded" image variation (e.g., Twenty Twenty-Four).
  2. Open the Site Editor or Post Editor.
  3. Insert an Image block and select an image.
  4. In the Settings Sidebar, click on the Styles tab.
  5. Switch the style from "Default" to "Rounded".
  6. Observe: The image should transition to the theme's rounded setting immediately without flashing as a full circle first.

Screenshots or screencast

Before

block-style-jitter.mov

After

block-style-jitter-fix.mov

Use of AI Tools

I used Gemini 3 Flash to help draft PR description.

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label May 15, 2026
@DarkMatter-999 DarkMatter-999 marked this pull request as ready for review May 15, 2026 08:03
@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block editor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

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

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Block: Visual jerk/flash when changing style to "Rounded"

1 participant