fix: make sure we get block-supports styles for the overlay gates in time#4449
fix: make sure we get block-supports styles for the overlay gates in time#4449laurelfulford wants to merge 7 commits intotrunkfrom
Conversation
There was a problem hiding this comment.
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 duringwp_enqueue_scriptsto 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.
|
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 😕 |
|
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. |
|
Throwing this one back in draft mode while I try another approach. |
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 usedCertain block styles are generated as needed by WordPress, and they're not automatically availablelike 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:
npm run build.newspack-content-gate-block-supports(the styles injected for the overlay block) andcore-block-supports-inline-css. Do a bit of spot checking (mostly making sure the former isn't huge) to confirm that thenewspack-content-gate-block-supportsstyles aren't repeating a bunch of stuff fromcore-block-supports-inline-css.Other information: