Repository navigation
Sharing & Likes: Replace "Open Site Editor" with template placement cards - #53838
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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! |
Code Coverage SummaryCoverage changed in 1 file.
2 files are newly checked for coverage.
|
|
Putting this on hold for a bit: we're moving the Settings > Sharing data layer off TanStack Query first, so this PR can use the new layer rather than reading TanStack's pending saves. I'll rebase once that lands. |
…ards Fixes CM-976 On block themes with the legacy buttons off, the Sharing buttons and Like buttons sections only offered a link to the Site Editor, leaving owners to find the right template and the right spot in it. CM-972 and CM-975 can now place each block before or after the content of single posts and pages, so the sections offer that as two cards. Core cannot hook one block on both sides of the content, and the route refuses a list with both, so the cards are an either/or: each change sends the whole list, ticking one card replaces the other, and unticking the ticked one empties it. Saves go through useSaveSetting(), so a refused save rolls the cards back. "Preview and edit" only shows on a card the last save that went through has ticked, since the template has no block before then. The optimistic value is in the cache, so the saved one comes from the oldest pending save's previous value. "Switch to the … block" sets the new status before settings are read again, so the variant briefly lacks the placement key. The cards show disabled while a write or a settings read is in flight, and the old button only stays for a server that does not offer the key.
Part of CM-976 The React screen's section in AGENTS.md covered the services manager but not the cards that now replace the Site Editor link, nor when the link still shows.
The rollback only restores a setting while the store still holds the value that save wrote, compared by identity, so a later edit of the same setting is kept. Under TanStack Query the cache held a copy of every array, so no list setting ever rolled back: `show`, and the template placements. The settings store keeps the value it is given, so lists roll back again; this pins it with a list row next to the boolean one.
… tests `Fieldset.Root` holds one description id, and `Fieldset.Details` registers its own, so wherever the theme has a page template, screen readers lost "Pick one place: before or after the content." to the hidden "More details follow." The notes under the cards are now plain paragraphs, and the page template test asserts the fieldset's description. "Before the content" and "After the content" get translator context, since they read as fragments on their own. The tests drop rows and cases that no mutation of the component could fail on their own (the rollback is covered in `use-save-setting`), and the switch test now checks the fieldset by its legend and `aria-busy`.
Part of CM-976 The cards read two things from TanStack Query: whether settings were still being re-read after "Switch to the … block", and the value of the last save that went through, for the "Preview and edit" link. #53853 moved the screen to a @wordpress/data store, so both now come from its pending-write count. A feature action stays pending until settings are read again, so the cards show disabled until the new variant's key arrives, as before. While any write is pending, the stored settings may hold an optimistic value, so the preview link waits until nothing is saving. That hides an already-saved card's link for the length of another setting's save; in exchange the cards need no copy of the last saved settings.
9b8faca to
faeffea
Compare
Part of CM-976 The switch test only covers the moment when the key is missing and a write is pending at once, so a component that disabled the cards and marked the group busy during every placement save still passed. Users would see the cards flicker disabled on each click. The preview test now checks that the other card stays enabled while a save is pending. The click table now has a Likes row, so the Likes setting key is tested directly rather than only through the switch test. The comment above the preview test went: the component holds that rationale, and the test name already says it.
Part of CM-976 The note under the cards said saved templates "keep the blocks you left in them, whatever you pick here", which reads as if a pick still applies on top. It does not. Saving a template in the Site Editor records each hooked block type in the anchor's `ignoredHookedBlocks`, per type rather than per side. After that, a block the owner removed stays removed, and moving a placement to the other side adds nothing there. The card's own "Preview and edit" link is the shortest way into that state, so the note now says to move or remove those blocks in the Site Editor.
Part of CM-976 AGENTS.md said each save "sends the whole list", which describes the bug the tests guard against: the cards send one placement or none, and that is why ticking one card unticks the other. It also left out that the fallback waits while a write is pending, showing the cards disabled instead. The changelog entry read as if the live Settings > Sharing screen got the cards. They are only in its React version, behind `rsm_jetpack_ui_modernization_sharing_likes`, and the entry now says so, matching the package's earlier entries for that screen.
Part of CM-976 The "Where … appear" section stays on screen while another section offers its block, and the block cards cover posts and pages whatever that section says. Unticking Pages there reads as if it kept the blocks off pages too. The section now says blocks added to templates aren't affected, whenever a section offers its block.
Fixes CM-976
Proposed changes
On a block theme where the legacy buttons are off, the Sharing buttons and Like buttons sections of the React Settings > Sharing screen say "Add the … block to your theme's template." and offer an Open Site Editor button. Owners then have to find the right template, and the right spot in it, on their own.
This replaces that button with two cards per section, like the placements in Jetpack > Newsletter's Subscriptions section: one adds the section's block before the content of single posts and pages, the other after it. They save the placements #53732 added, through the same autosave as the screen's other settings.
Rationale
One side or the other. Core can't hook one block both before and after the post content (see #53413), and the route refuses a list with both sides.
CheckboxCardis a checkbox, so the section makes the two cards a choice: every save sends the block's whole list ([],['before_content']or['after_content']), and the copy says to pick one place. Radios would have no way to remove the block, which is why the cards stay checkboxes: unticking the ticked one is how it comes out.One card for posts and pages. That's how the placements have worked since #53413. The heading says so, and the page template link covers owners who want something different on pages.
The preview link waits for the save. Before that, the template doesn't have the block yet. Newsletter does the same with
isEnabledAndSaved. The settings store holds the optimistic value while a write is pending, so the link shows once nothing is saving. That also hides an already-saved card's link while another setting saves; in exchange, the store doesn't need a second copy of the settings.No flash of the old button. "Switch to the … block" updates the status before settings are read again, so for a moment the section is in
block_call_to_actionwithout the key. The store counts the action as a pending write until that read lands, and the cards show disabled meanwhile. The Open Site Editor button now only shows when the server doesn't offer the key at all.A refused save unticks the card again. The rollback only restores a setting while the store still holds the value that save wrote, compared by identity. Under TanStack Query the cache held a copy of every array, so list settings never rolled back. The store from #53853 keeps the array it's given, so they do again, and the rollback test now has a list row (
show) next to the boolean one.The "Pick one place" hint stays announced. A fieldset takes one description, and
Fieldset.Detailsregisters its own, so wherever the theme has a page template, screen readers heard "More details follow." instead of the hint. The notes under the cards are plain paragraphs.It doesn't touch the PHP screen, which keeps its Open Site Editor link until it retires (CM-945), or the Jetpack dashboard and My Jetpack links.
Left for follow-ups:
CheckboxCarditself, and would change Newsletter's cards too.statusto say which templates are saved.saveSetting(data/writes.ts) and predates this PR.The React screen is still behind
rsm_jetpack_ui_modernization_sharing_likes, so the changelog entry is in the package only.Related product discussion/links
CheckboxCardDoes this pull request change what data or activity we track or use?
No.
Testing instructions
On a connected Jetpack site running Twenty Twenty-Five, with the Sharing and Likes modules off and this in an mu-plugin:
wp jetpack module activate sharedaddy) and reload. The "Where sharing buttons appear" section shows up, and its description ends with "Blocks you add to your templates aren't affected." Untick Pages there: the legacy sharing buttons go away from pages, but the Like block stays.