Repository navigation
Sharing & Likes: Move the React Settings > Sharing screen off TanStack Query - #53853
Merged
Merged
Conversation
The screen now keeps status, settings and services in one @wordpress/data store, following Newsletter's settings screen: plain apiFetch calls, no TanStack Query and no core-data. wp-data already loads as a shared script, whereas TanStack was bundled into the route, and core-data would have pulled the block editor's scripts onto the page. What TanStack did for the screen is rebuilt in the store: - Every write goes through one queue per registry, so requests reach the server one at a time, in order, rereads included. - Saves stay optimistic. A refused save rolls back only its own value, and a response landing while another save of the same kind waits leaves that save's value alone. - Each local change bumps a version, so a read already in flight is dropped instead of landing on top of it. - A pending-write count drives the unsaved-changes warning. The hooks keep their names and return shapes, so sections and the services manager are unchanged. The route bundle loses about 35 KB minified (9 KB gzipped).
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
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 6 files. Only the first 5 are listed here.
2 files are newly checked for coverage.
|
Rereads went through @wordpress/data's resolver metadata, which cannot cancel a read already in flight. An earlier read finishing late could then mark a newer, failed read as done, leaving the services list on a spinner for good, and a reread took its version only once the resolver started, a tick after it was asked for, so it could land on top of an optimistic value made in between. Reads now record their own failures, versioned like their data, and reread takes its version when it is called. A services list that could not be loaded reads again when it next appears, as it did before. Also covers two guarantees no test held: the queue keeps going after a refused write, and the leave-page warning turns off once writes settle.
jeherve
added a commit
that referenced
this pull request
Oct 21, 2026
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.
jeherve
added a commit
that referenced
this pull request
Oct 21, 2026
…ards (#53838) * Sharing & Likes: Replace "Open Site Editor" with template placement cards 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. * Sharing & Likes: Describe the template placement cards in AGENTS.md 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. * Sharing & Likes: Test that refused saves of list settings roll back 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. * Sharing & Likes: Keep the placement hint announced, and trim the card 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`. * Sharing & Likes: Read the placement cards' state from the settings store 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. * Sharing & Likes: Make the placement card tests tell saving from loading 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. * Sharing & Likes: Say what the cards cannot change in a saved template 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. * Sharing & Likes: Correct the placement cards' notes and changelog entry 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. * Sharing & Likes: Say the placement choices don't apply to the blocks 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
The React Settings > Sharing screen (behind
rsm_jetpack_ui_modernization_sharing_likes) kept its data in TanStack Query. It now keeps it in one@wordpress/datastore, the way Newsletter's settings screen works. Requests stay plainapiFetchcalls, and snackbars still go through the notices store; there's no TanStack or core-data left.data/store.tsholds status, settings and services, filled fromJetpackScriptDataso the first render still waits on no request. Resolvers handle the reads.data/writes.tsholds every write. They all go through one queue, so requests reach the server one at a time, in the order you clicked.useStatus,useSettings,useServices,useSaveSetting,useSaveServices,useCustomService,useFeatureAction), so the sections and the services manager are unchanged.useIsSaving()replacesuseIsMutating()for the unsaved-changes warning.What TanStack did for us is rebuilt in the store:
cancelQueries()did that job.Why
TanStack came in with the screen (#53297) and was bundled into the route, while
@wordpress/dataalready loads on the page as a shared script. It also brought its own gotchas: queued writes waiting on a paused reread deadlocked unless every read usedretry: falseandnetworkMode: 'always'.I considered
@wordpress/core-dataentities first, and tried them on one setting. But they don't queue writes or roll back a refused edit, so we'd have rebuilt both anyway.wp-core-dataalso depends on the block editor's scripts (wp-block-editor,wp-blocks…), so importing it would load about 1.8 MB of JavaScript this page doesn't need today.The route bundle drops from 1,097,255 to 1,061,864 bytes (about 35 KB minified, 9 KB gzipped). Its script dependencies don't change.
What changes, and what doesn't
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
You need a connected Jetpack site with this branch, and an mu-plugin that turns the screen on:
Turn on the Sharing, Likes and Comment Likes modules, use a block theme such as Twenty Twenty-Five, then go to Settings > Sharing with your browser's network tab open.
sharing-likes/servicesis requested; status and settings come from the page.settingsrequest only starts once the first one, and thestatusread after it, have finished.sharing-likes/settings(Network › Block request URL), then change a setting. The control goes back to its previous value and a snackbar says the save failed. Unblock it before you go on.servicesrequest afterwards (that route answers 409 once Sharing hands off).addEventListenererror fromsharedaddy/sharing.jsis already there on trunk :)