Newsletter: gate placement "Preview and edit" link on saved-enabled state#49532
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 4 files.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
fc3134f to
85ff8e9
Compare
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Follow-up note: a pre-existing "phantom unsaved edit" issue (not fixed here)Flagging for later — out of scope for this PR. The Settings body caches the optimistic The |
10770ad to
1eace63
Compare
1eace63 to
41baabc
Compare
85ff8e9 to
5540206
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes an empty Site Editor preview edge case in the modernized Newsletter Settings UI by only rendering the per-placement “Preview and edit” link when the placement is enabled in the saved (persisted) baseline, not merely toggled on in the optimistic UI state.
Changes:
- Add a persisted “saved baseline” (
savedData) alongside the optimistic settings state and keep it updated after successful saves. - Gate each placement card’s “Preview and edit” link on
data[key] && savedData[key](while preserving existing Site Editor capability gating). - Add Jest coverage for the new gating behavior and a patch-level changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| projects/packages/newsletter/src/settings/sections/subscriptions-section.tsx | Gates placement-card preview links on enabled and saved state (using savedData). |
| projects/packages/newsletter/src/settings/newsletter-settings.tsx | Introduces and module-caches savedData baseline; advances it on successful saves; passes it into SubscriptionsSection. |
| projects/packages/newsletter/tests/subscriptions-section.test.tsx | Adds automated tests covering enabled/saved, enabled/unsaved, reverted-to-saved, and capability-ineligible cases. |
| projects/packages/newsletter/changelog/change-newsletter-preview-edit-gating | Documents the user-facing fix in the changelog. |
…tate The subscription placement "Preview and edit" link was gated only on site capability, so it appeared for placements that were disabled or toggled-but- unsaved — clicking it opened an empty Site Editor preview. Show the link only when the placement is enabled in its saved state (enabled in data and not in the pending changeset).
5540206 to
6144ec3
Compare
Part of #49485 - NL08
Proposed changes
savedData) rather than "untouched since save", which keeps the link reversible: toggle a saved-on placement off and back on and the link returns immediately, without a round-trip to the server. A freshly enabled-but-unsaved placement still stays linkless until the save lands. The existing site-capability gating (block theme / theme stylesheet / subscription-site-edit support) is preserved.datais updated optimistically while the key is tracked in a pending changeset that's cleared on save. The page previously kept no record of the last-persisted values, so the first version of this fix had to use "key is in the pending changeset" as a proxy for "unsaved". That proxy is touch-based, not value-based: toggling a saved-on placement off then on left the key marked dirty, so the link stayed hidden until an actual save — even though the saved state never changed. This version introducessavedData, a persisted baseline set on load and advanced on every successful save, and gates the link ondata[ key ] && savedData[ key ]. The baseline is module-cached (parallel to Newsletter: Stop the modernized Settings spinner from flashing on every visit #49530's optimistic cache) so it survives the tab unmount/remount without the link blinking off on return.This only touches the placement-card grid. The Navigation subgroup's "Preview and edit" links are intentionally out of scope here (they share the same "empty preview when unsaved" critique — a reasonable follow-up).
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Prerequisite: a site with the modernized Newsletter dashboard enabled (modernization filter on) and a block theme so the Site Editor links are eligible.
Automated coverage:
tests/subscriptions-section.test.tsxasserts the link shows for enabled-and-saved placements (including the reverted-to-saved case) and is hidden for disabled, enabled-but-unsaved, and capability-ineligible cases (jp test js packages/newsletter).