Skip to content

Upgrade nudge: fix collapsed banner outside the block editor - #50873

Merged
kraftbj merged 5 commits into
trunkfrom
file-upload-upsell-banner-fix
Aug 11, 2026
Merged

Upgrade nudge: fix collapsed banner outside the block editor#50873
kraftbj merged 5 commits into
trunkfrom
file-upload-upsell-banner-fix

Conversation

@kraftbj

@kraftbj kraftbj commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Jetpack_Gutenberg::get_render_callback_with_availability_check() prints an upgrade nudge above paid blocks on the frontend for admins. That nudge is pre-rendered at build time from extensions/shared/components/index.jsx into _inc/blocks/upgrade-nudge.html, and its stylesheet is _inc/blocks/components.css, built from the same entry.

The markup is the shared Nudge component, so it carries the same classes as the editor's paid-block banner. But the rules that give that banner its vertical breathing room live in extensions/extended-blocks/paid-blocks/editor.scss, which is editor-only and never loads on the frontend. The shared component's own stylesheet has no vertical margins and no flex-wrap, so on the frontend the banner collapses to the 28px height of its own button: the Upgrade button sits flush against the top and bottom edges, and the description runs underneath it instead of wrapping.

The Forms preview screen renders the form on the frontend for an admin, so a form with a File upload field hits this on every preview.

Changes:

  • Add the missing spacing to extensions/shared/components/style.scss. That file already exists to carry editor styling to the frontend (it does the same for Gutenberg's Warning component), it is only imported by the pre-rendered components entry, and nothing else imports that entry — so the rules land exactly where the bug is and nowhere else. Logical properties, so it is RTL-correct.
  • Fix a dead selector in paid-blocks/editor.scss: Upgrade nudge: replace CSS class to avoid Gutenberg editor iframe warning #50260 renamed the nudge's editor-canvas class from wp-block to jetpack-nudge-canvas but left .jetpack-upgrade-plan-banner.wp-block[data-align] behind, so left- and right-aligned nudges lost their content-width cap. That selector currently matches nothing, so this has no blast radius either.

Notes for review:

  • This is a long-standing bug, not a recent regression. The shared stylesheet never carried the vertical margins. It got easy to hit because the Forms preview screen renders paid blocks on the frontend for admins.
  • I first fixed this in @automattic/jetpack-shared-extension-utils and backed it out. Five consumers already style .jetpack-upgrade-plan-banner__wrapper at the same specificity — ai-assistant and connect-banner set flex-wrap: nowrap, ai-post-excerpt sets flex-direction: column plus its own description margin, the logo generator sets its own padding — and equal-specificity ties resolve by source order, so editing the shared package would have shifted those banners depending on bundle ordering. See the second commit for the reasoning.
  • Follow-up worth doing separately: the banner rules in paid-blocks/editor.scss are now near-duplicates of the shared stylesheet, and .jetpack-upgrade-plan__hidden is emitted by the shared component but only declared in the editor stylesheet — so visible={false} and a missing checkout URL don't actually hide anything outside the editor. Both deserve a proper cleanup of the shared component rather than another scoped patch.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Screenshots

Before:
1-before-trunk

After:

2-after-pr50873

Testing instructions

Requires a self-hosted Jetpack site without a paid plan (the file upload field needs one), logged in as an admin.

  • Build and deploy the plugin: jetpack build plugins/jetpack --deps.
  • Create a form with the Jetpack Form block and add a File upload field.
  • Use the form's Preview button to open the frontend preview screen.
  • The "Upgrade your plan to use this premium block" banner should have even padding above and below, with the Upgrade button vertically centered and not touching the banner edges. The description should not run underneath the button.
  • Narrow the browser window. The description should wrap onto its own line above the button rather than being clipped.
  • Confirm nothing changed in the block editor: the banner above the file upload field should look exactly as it did before.
  • Confirm nothing changed on the AI assistant upgrade banner, the connect banner, or the AI logo generator nudge — those share the .jetpack-upgrade-plan-banner classes but are styled by different stylesheets and are deliberately untouched here.

The `.jetpack-upgrade-plan-banner` styles that give the banner its vertical
breathing room live only in the Jetpack plugin's editor-only stylesheet
(extensions/extended-blocks/paid-blocks/editor.scss). The shared `Nudge`
component ships its own stylesheet, and that copy has no vertical margins and
no flex-wrap.

Anywhere the shared stylesheet loads without the editor one -- most visibly the
pre-rendered frontend nudge in _inc/blocks/upgrade-nudge.html, which
Jetpack_Gutenberg::get_render_callback_with_availability_check() prints above
paid blocks for admins -- the banner collapses to the 28px height of its own
button, the Upgrade button sits flush against the top and bottom edges, and the
description runs under the button instead of wrapping. The Forms preview screen
renders the form on the frontend for an admin, so the file upload field hits
this path every time.

Move the spacing into the shared stylesheet so the banner stands on its own,
using logical properties so it works in RTL. The Jetpack editor stylesheet
already declares the same values at the same specificity, so the editor
rendering is unchanged.

Also:

- Define `.jetpack-upgrade-plan__hidden` in the shared stylesheet. The shared
  component emits that class for `visible={false}` and for a missing checkout
  URL, but only the editor stylesheet declared it, so neither actually hid
  anything outside the editor.
- Fix a dead selector in the editor stylesheet: #50260 renamed the nudge's
  editor-canvas class from `wp-block` to `jetpack-nudge-canvas` but left
  `.jetpack-upgrade-plan-banner.wp-block[data-align]` behind, so left- and
  right-aligned nudges lost their content-width cap.

Fixes FORMS-737
@kraftbj kraftbj self-assigned this Jul 28, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the file-upload-upsell-banner-fix branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack file-upload-upsell-banner-fix
bin/jetpack-downloader test jetpack-mu-wpcom-plugin file-upload-upsell-banner-fix

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [JS Package] Shared Extension Utils [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress RNA labels Jul 28, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 28, 2026
Putting the spacing in the shared jetpack-shared-extension-utils stylesheet
reached further than the bug does. Five other consumers already style
`.jetpack-upgrade-plan-banner__wrapper` at the same specificity -- the AI
assistant and connect banners set `flex-wrap: nowrap`, ai-post-excerpt sets
`flex-direction: column` plus its own description margin, and the logo
generator sets its own padding. Ties at equal specificity resolve by source
order, so the shared-package edit would have changed those banners depending on
bundle ordering.

The broken banner is the pre-rendered frontend one, and its stylesheet is
_inc/blocks/components.css, built solely from extensions/shared/components.
That entry's style.scss already exists to carry editor styling to the frontend
(it does the same for Gutenberg's Warning component), and nothing else imports
it, so the rules land exactly where the bug is and nowhere else.

Revert the shared package and its changelog; add the rules there instead.
@jp-launch-control

jp-launch-control Bot commented Jul 28, 2026

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@kraftbj
kraftbj marked this pull request as ready for review July 28, 2026 18:50
@kraftbj
kraftbj requested review from enejb and simison July 28, 2026 18:50
@kraftbj kraftbj added [Status] Needs Review This PR is ready for review. Reviewer Can Merge PR author indicates the reviewer is free to merge/deploy if they want to own the change. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Jul 28, 2026
@enejb

enejb commented Jul 28, 2026

Copy link
Copy Markdown
Member

This PR is staring to look better but I am still seeing the following on the peview page.

Screenshot 2026-07-28 at 3 15 08 PM

I am expecting to see the upload banner to be 100% of the width.

I am not sure why this is not the case.

@enejb

enejb commented Jul 28, 2026

Copy link
Copy Markdown
Member

Also I noticed that the HTML code that we generate seems a bit off.

See undefined__description banner-description class.

Screenshot 2026-07-28 at 3 20 30 PM

Enej raised two things on the PR.

The banner was still narrower than the field it warns about. The nudge is
printed as a sibling of the block, so inside a flex container it becomes a flex
item and shrinks to its content width. Contact_Form only adds the
`has-no-jetpack-form-layout` class when the block has no layout attribute
(class-contact-form.php), and grunion.scss only stretches children under that
class -- so a form saved from the editor, which does carry a layout attribute,
leaves the banner at content width.

Set `width: 100%` on the banner. Note this deliberately isn't `flex: 0 0 100%`:
a form saved with a layout attribute renders a *column* flex container with
`align-items: flex-start`, where flex-basis sizes the block axis and leaves the
width untouched. Measured on a real form, the flex-basis version stayed at
414px inside a 620px form while `width: 100%` gives the full 620px.

Also stop the shared Nudge emitting a literal `undefined__description` class.
The description built its class with a bare template literal while the title
already used a guarded `clsx` call; use the same guard so the prefixed class
only appears when a class name is actually passed. Consumers that pass one keep
their prefixed class.
@kraftbj

kraftbj commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Both fixed in caa602318e.

Width. Contact_Form only adds the has-no-jetpack-form-layout class when the block has no layout attribute (class-contact-form.php), and grunion.scss only stretches form children under that class. A form saved from the editor does carry a layout attribute, so it gets has-jetpack-form-layout and the nudge — which is printed as a sibling of the block — stayed at its content width as a flex item. That's why you saw it on the preview page and I didn't on my first test form.

Worth flagging why the fix is width: 100% and not flex: 0 0 100%: a form saved with a layout attribute renders a column flex container with align-items: flex-start, so flex-basis sizes the block axis and leaves the width untouched. I tried the flex version first and the banner stayed at 414px inside a 620px form even though the declaration applied cleanly.

undefined__description. Good catch. The description built its class with a bare template literal while the title already used a guarded clsx call. Both use the guard now, so consumers that do pass a class name keep their prefixed class.

Verified on a Jurassic Ninja site against the real built components.css, on a form saved with {"layout":{"type":"flex","orientation":"vertical"}}:

before after
banner width 414px in a 620px form 620px
wrapper height 28px 48px
description class undefined__description banner-description banner-description

No change on forms saved without a layout attribute (still full width), and the editor rendering is untouched since these rules only ship in the pre-rendered frontend stylesheet.

One note on CI: the WordPress.com Tests red mark is a reporting artifact, not a real failure. The TeamCity build passes with zero build problems and zero failing tests — the GitHub check has a 600 second budget and this build lands around 10m30s, so the reporter gives up a few seconds before TeamCity finishes. Re-running it now.

@enejb

enejb commented Aug 11, 2026

Copy link
Copy Markdown
Member

This banner is on the frontend of the site. In the editor it looks correct for me but not on when it in the preview mode or in when a admin is looking at it on the front end of the site.

@kraftbj

kraftbj commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Here's what I'm seeing in the editor + preview + logged-in front-end + logged-out front end.

1-editor 2-preview-mode 3-frontend-as-admin 4-frontend-logged-out

@enejb enejb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR fixes things for me! Nice work!

@kraftbj
kraftbj merged commit d1f75e2 into trunk Aug 11, 2026
112 checks passed
@kraftbj
kraftbj deleted the file-upload-upsell-banner-fix branch August 11, 2026 21:02
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[JS Package] Shared Extension Utils [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Reviewer Can Merge PR author indicates the reviewer is free to merge/deploy if they want to own the change. RNA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants