Skip to content

fix: make sure we get block-supports styles for the overlay gates in time#4449

Open
laurelfulford wants to merge 6 commits intotrunkfrom
fix/block-theme-gate-overlay-styles
Open

fix: make sure we get block-supports styles for the overlay gates in time#4449
laurelfulford wants to merge 6 commits intotrunkfrom
fix/block-theme-gate-overlay-styles

Conversation

@laurelfulford
Copy link
Contributor

@laurelfulford laurelfulford commented Feb 3, 2026

All Submissions:

Changes proposed in this Pull Request:

Edited I originally thought this was a block theme issue but I can recreate it on a fresh site running the Classic Theme, too. I've updated the details testing steps accordingly!

Right now, the overlay content gate is getting inserted at wp_footer.

When a block theme is used Certain block styles are generated as needed by WordPress, and they're not automatically available like they are with the classic theme. By the time the inline gate is injected, it's "too late" for its blocks to be included in those inline styles. This means certain styles -- like block alignments and spacing -- don't work in the gates.

This PR renders the gate's content early so it can get all the styles that are needed, and adds them in their own inline styles separate from the WordPress ones.

I'm not sure if this is the best approach. The other solution I tried was rendering the overlay earlier. That also seemed to work, but it seems more dependent on how the theme is structured, and it would involve a bit of a rewrite of the overlay styles so they'd still work. It seemed a little messier, and possibly more likely to introduce issues, so just sticking to this for now. Open to feedback on the approach though!

Closes NPPD-1181

How to test the changes in this Pull Request:

  1. Set up a content gate (using Memberships or the new Newspack approach).
  2. In the Content gate, insert the Registration Card (compact) pattern (the second one in the list of Content Gate block patterns.
  3. Publish.
  4. In an incognito window, trigger the gate on a post - note the layout is a little messed up (the button and text should be on opposite sides, and the spacing is wrong between the two lines of text):
CleanShot 2026-02-02 at 16 20 31
  1. Apply this PR and run npm run build.
  2. Repeat step 4; confirm the gate looks better:
CleanShot 2026-02-02 at 16 22 13
  1. View source and find newspack-content-gate-block-supports (the styles injected for the overlay block) and core-block-supports-inline-css. Do a bit of spot checking (mostly making sure the former isn't huge) to confirm that the newspack-content-gate-block-supports styles aren't repeating a bunch of stuff from core-block-supports-inline-css.
  2. Switch to the Block theme (or classic theme if you're already testing with the block theme).
  3. Confirm that the overlay gate also looks good there.

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
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

This pull request fixes a styling issue with overlay content gates when using block themes. The core problem is that block-specific styles (alignments, spacing, etc.) were not being generated for the gate content because it was injected too late in the page rendering process via wp_footer.

Changes:

  • Extracted gate layout validation logic into a reusable private method get_overlay_gate_layout_id()
  • Added prepare_overlay_gate_styles() method that pre-renders gate content during wp_enqueue_scripts to trigger block style generation
  • Registered and enqueued gate-specific block support styles as inline CSS early in the page head

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

@laurelfulford laurelfulford marked this pull request as ready for review February 4, 2026 00:28
@laurelfulford laurelfulford requested a review from a team as a code owner February 4, 2026 00:28
@laurelfulford laurelfulford added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 4, 2026
@laurelfulford
Copy link
Contributor Author

I need to look at this again with fresh eyes (long day!) but I think I may be getting this issue with the Classic theme, too 😕

@laurelfulford
Copy link
Contributor Author

I can also see the issue on a JN site running the classic theme, so I've removed the block theme check and updated the testing steps.

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

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant