Skip to content

fix(block-theme): load block styles when needed#4555

Merged
laurelfulford merged 2 commits intotrunkfrom
fix/enqueue-blocks-without-collections
Mar 19, 2026
Merged

fix(block-theme): load block styles when needed#4555
laurelfulford merged 2 commits intotrunkfrom
fix/enqueue-blocks-without-collections

Conversation

@laurelfulford
Copy link
Copy Markdown
Contributor

@laurelfulford laurelfulford commented Mar 10, 2026

All Submissions:

Changes proposed in this Pull Request:

This PR fixes a weird issue that seems to have started happening after I wiped my test site: blocks like the social links block from the Author Profile block aren't loading CSS on the front-end.

Looking at the code I think this makes sense -- it's checking to see if we're on a Collections page before loading. What I don't get is how it worked for me in the first place. I'm not sure if my test site was in a weird state before (like had a Collections block in the template), or is somehow in a weird state now. I did have a pretty mangled template, so it could be the former, but I wish I could get it back to check.

This PR adds a check for blocks in the content as well. I'm open to other approaches, too, if there's a better way - maybe removing the check entirely?

Also I'd be interested if this is working for anyone else? I'm so confused 😂

Closes NPPD-1348

How to test the changes in this Pull Request:

  1. On a page/post without a Collections block, add an Author Profile block.
  2. View on the front-end; note that the social links have bullets.
  3. Apply this PR.
  4. Confirm the styles now look right on the front-end.
  5. Smoke test things like Collections or other blocks in the Newspack Plugin block

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates frontend asset loading for Newspack blocks so dist/blocks.css is enqueued when a post/page actually contains Newspack block markup (fixing missing frontend styling like Social Links bullets when using Author Profile blocks).

Changes:

  • Refines Blocks::should_load_block_assets() to load styles on Collections archives/singles.
  • Adds a singular-page content check intended to detect whether any Newspack block is present before enqueuing blocks.css.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread includes/class-blocks.php Outdated
@laurelfulford laurelfulford marked this pull request as ready for review March 10, 2026 00:32
@laurelfulford laurelfulford requested a review from a team as a code owner March 10, 2026 00:32
@laurelfulford laurelfulford added the [Status] Needs Review The issue or pull request needs to be reviewed label Mar 10, 2026
Copy link
Copy Markdown
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for the should_load_block_assets() method follows (both in trunk and in your PR), but even when returning false (trunk), blocks.css was loading in the frontend for me.

I tried commenting out this bit, but nothing changed:

wp_enqueue_style(
'newspack-blocks-frontend',
Newspack::plugin_url() . '/dist/blocks.css',
[],
NEWSPACK_PLUGIN_VERSION
);
)

Then I learned it was this:

"style": "file:../../../dist/blocks.css"

WP will automatically enqueue assets declared in the block.json file if the page renders it. So it's possible that in your tests, you always had the My Account button block rendering and enqueueing the CSS.

@github-actions github-actions Bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Mar 18, 2026
@laurelfulford
Copy link
Copy Markdown
Contributor Author

Ohhhh thanks @miguelpeixe! That makes sense -- I have had that block active most of the time 🤦‍♀️

So glad I'm not completely losing it! 🎉

@laurelfulford laurelfulford merged commit ec4c70b into trunk Mar 19, 2026
11 checks passed
@laurelfulford laurelfulford deleted the fix/enqueue-blocks-without-collections branch March 19, 2026 14:37
@github-actions
Copy link
Copy Markdown

Hey @laurelfulford, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Mar 19, 2026
# [6.36.0-alpha.1](v6.35.1...v6.36.0-alpha.1) (2026-03-19)

### Bug Fixes

* **access-rules:** normalize rules to individual OR groups ([#4584](#4584)) ([40a7259](40a7259))
* apply max-width to add payment method iframe ([#4575](#4575)) ([de27bb5](de27bb5))
* **block-theme:** ensure content gate contents inserted in time for styles to be rendered ([#4539](#4539)) ([2be2f3b](2be2f3b))
* **block-theme:** load block styles when needed ([#4555](#4555)) ([ec4c70b](ec4c70b))
* **block-theme:** migrate newspack-theme modal checkout fixes ([#4557](#4557)) ([6eb5f48](6eb5f48))
* **content-gating:** allow for metering with paid access only ([#4571](#4571)) ([e2d8e01](e2d8e01))
* exclude Jetpack Swiper CSS from perfmatters unused CSS feature ([#4538](#4538)) ([0d64190](0d64190))
* guard against null, but enumerated, storage keys ([adcec53](adcec53))
* **integrations:** integrations settings registration ([#4573](#4573)) ([a4d90c2](a4d90c2))
* json_decode and notice style fixes ([#4531](#4531)) ([8fc6ada](8fc6ada))
* use correct is_enabled method ([#4564](#4564)) ([6396e41](6396e41)), closes [#4541](#4541)

### Features

* **alert-manager:** failure pattern detection ([#4527](#4527)) ([9a0bb3d](9a0bb3d))
* alerting system ([#4511](#4511)) ([1df65a0](1df65a0))
* **content-gate:** default block patterns ([#4540](#4540)) ([4852a9a](4852a9a))
* **content-gate:** display matching gates in post editor ([#4572](#4572)) ([eb275eb](eb275eb))
* **content-gating:** group subscriptions members in my account ([#4543](#4543)) ([202781a](202781a))
* **content-gating:** i3 designs for Metered Countdown + Content Gifting ([#4526](#4526)) ([ba5b4ee](ba5b4ee))
* **group-subscription:** invite email and acceptance flow ([#4546](#4546)) ([ac50a98](ac50a98))
* **integrations:** add integrations settings framework ([#4541](#4541)) ([735e640](735e640))
* **integrations:** refactor metadata for integration specific selection ([#4544](#4544)) ([eb747fc](eb747fc))
* new `getAll()` method to fetch all reader data from store at once ([fbe68db](fbe68db))
* new `getAll()` method to retrieve all items from the reader data store ([b7d6664](b7d6664))
* **reader-activation:** add integration health check system ([#4550](#4550)) ([4993f21](4993f21))
* **yoast:** add Bluesky contact method registration ([#4554](#4554)) ([aa143d7](aa143d7))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.36.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Mar 30, 2026
# [6.36.0](v6.35.2...v6.36.0) (2026-03-30)

### Bug Fixes

* **access-rules:** normalize rules to individual OR groups ([#4584](#4584)) ([40a7259](40a7259))
* apply max-width to add payment method iframe ([#4575](#4575)) ([de27bb5](de27bb5))
* **block-theme:** ensure content gate contents inserted in time for styles to be rendered ([#4539](#4539)) ([2be2f3b](2be2f3b))
* **block-theme:** load block styles when needed ([#4555](#4555)) ([ec4c70b](ec4c70b))
* **block-theme:** migrate newspack-theme modal checkout fixes ([#4557](#4557)) ([6eb5f48](6eb5f48))
* **content-gating:** allow for metering with paid access only ([#4571](#4571)) ([e2d8e01](e2d8e01))
* exclude Jetpack Swiper CSS from perfmatters unused CSS feature ([#4538](#4538)) ([0d64190](0d64190))
* guard against null, but enumerated, storage keys ([adcec53](adcec53))
* **integrations:** integrations settings registration ([#4573](#4573)) ([a4d90c2](a4d90c2))
* json_decode and notice style fixes ([#4531](#4531)) ([8fc6ada](8fc6ada))
* use correct is_enabled method ([#4564](#4564)) ([6396e41](6396e41)), closes [#4541](#4541)

### Features

* **alert-manager:** failure pattern detection ([#4527](#4527)) ([9a0bb3d](9a0bb3d))
* alerting system ([#4511](#4511)) ([1df65a0](1df65a0))
* **content-gate:** default block patterns ([#4540](#4540)) ([4852a9a](4852a9a))
* **content-gate:** display matching gates in post editor ([#4572](#4572)) ([eb275eb](eb275eb))
* **content-gating:** group subscriptions members in my account ([#4543](#4543)) ([202781a](202781a))
* **content-gating:** i3 designs for Metered Countdown + Content Gifting ([#4526](#4526)) ([ba5b4ee](ba5b4ee))
* **group-subscription:** invite email and acceptance flow ([#4546](#4546)) ([ac50a98](ac50a98))
* **integrations:** add integrations settings framework ([#4541](#4541)) ([735e640](735e640))
* **integrations:** refactor metadata for integration specific selection ([#4544](#4544)) ([eb747fc](eb747fc))
* new `getAll()` method to fetch all reader data from store at once ([fbe68db](fbe68db))
* new `getAll()` method to retrieve all items from the reader data store ([b7d6664](b7d6664))
* **reader-activation:** add integration health check system ([#4550](#4550)) ([4993f21](4993f21))
* **yoast:** add Bluesky contact method registration ([#4554](#4554)) ([aa143d7](aa143d7))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.36.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants