gutenberg-style-engine-block-supports style block missing due to early invocation of gutenberg_page_attachments

Created on 21 May 2025, 3 months ago

Problem/Motivation

We're encountering an issue where the additional style block gutenberg-style-engine-block-supports is not consistently added to the page header after editing a page using the Gutenberg editor.

Problem:
In the gutenberg_page_attachments hook, the module conditionally injects CSS into the header based on the result of:
$stores = StyleEngine::get_stores();
However, in some cases, this returns an empty array, and the associated style block is missing from the rendered page.

Findings:
After debugging, we discovered:
• StyleEngine::get_stores() returns an empty array under certain conditions.
• The gutenberg_page_attachments hook is triggered before LayoutProcessor::processBlock() runs.
• This appears to be a timing issue: the style engine hasn't yet populated its internal stores when the hook is called.

Expected Behavior:
The gutenberg-style-engine-block-supports style block should be reliably present after editing and viewing a page that includes blocks using the style engine.

Steps to reproduce

Environment:
• Drupal core: 10.4.5
• Gutenberg module: 3.0.6

1. Edit a node using the Gutenberg editor.
2. Save and reload the page.
3. Inspect the page header — the gutenberg-style-engine-block-supports block is sometimes missing.
4. Clear caches (drush cr or via the UI).
5. Reload the same page — the style block is now correctly injected.

Proposed resolution

Consider deferring the injection of style blocks until after StyleEngine is fully initialized. This could involve:
• Attaching styles later in the rendering process.
• Or explicitly triggering StyleEngine::get_stores() initialization earlier.

Temporary Workaround:
The issue is resolved after rebuilding the Drupal cache, which likely triggers a full render pipeline and ensures StyleEngine is populated.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium uws@ugent.be

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024