Bug: Bud's inline runtime is lost in Gutenberg editor when a block is pre-rendered #281
Open
5 tasks done
Labels
bug
Something isn't working
Terms
Description
Context
I'm using
log1x/acf-composer
to create ACF Gutenberg blocks.What's wrong?
When a block enqueues its own Bud bundle, the inline runtime is lost when loading the Gutenberg editor.
This is due to WP pre-rendering the blocks via internal calls to the WP REST API early in the page lifecycle:
Call stack
When the custom block is pre-rendered, the JS is enqueued, and the inline runtime is flagged as having been output.
Then the actual page renders, the inline runtime is not output because the Bundle class remembers inlining it when rendering the block earlier.
What have you tried? / Temporary workaround
For now I'm keeping track of when the REST API callbacks have finished, and using that in each bundle's conditional callback:
And the block conditionally enqueues using that function:
What insights have you gained?
The pre-rendering of blocks is essential for a good editing experience, so it can't be disabled.
Possible solutions
The might be a simpler way to detect that the bundle is being enqueued via an internal REST request, but the workaround above is the only way I've found.
Another workaround (which doesn't really solve the underlying problem) is to include all the block JS in a single editor bundle. This would prevent it from being enqueued during the pre-rendering step.
Steps To Reproduce
log1x/acf-composer
and create an example blockwp acorn acf:block TestBlock
resources/scripts/blocks/test-block.js
and add it to thebud.config.mjs
under a new bundle name:npm run build
Expected Behavior
The inline runtime should be included in the Gutenberg editor if the theme has enqueued an editor script.
Actual Behavior
The inline runtime is missing if a block with its own enqueued bundle was pre-rendered.
Relevant Log Output
No response
Versions
Acorn v3.1.0
The text was updated successfully, but these errors were encountered: