BUG: Fix block styles not loading on frontend (fixed #1375) #1422
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem this Pull Request solves
See #1375 for details.
The fix implemented here may or may not be the chosen route for long term fixes.
In #1286 I introduced the automatic dependency generation script and logic which in turn introduced the bug in #1375 because the frontend script for blocks (
/src/blocks/index-frontend.js
) doesn't list any dependencies on components, hence the@eventespresso/components
built module is not loaded on the frontend. That module is where the styles for the component the event attendees block uses (components/event-attendees/style.css
) are found. There are two temporary solutions:@eventespresso/components
as a dependency for the frontend css php side./src/blocks/index-frontend.js
(which would then get built to the/src/blocks/index-frontend.css
file).I chose the second option for the following reasons:
Going forward as you plan for more blocks (not for this pull - but for future pulls), I would suggest evaluating:
wp_enqueue
the block assets by what blocks are detected. There is apre_render_block
filter in wp core that you might be able to use to detect when blocks are being rendered for post content and use that to enqueue the script/style (print style inline or enqueue script for footer). The other option is to use theparse_blocks
function in core on an early hook (as soon as you know post_content) to detect if the post content has blocks (which is what you might want to use on a single post view).How has this been tested
Checklist
esc_html__()
, see https://codex.wordpress.org/I18n_for_WordPress_Developers)