Skip to content

Sharing & Likes: Move the React Settings > Sharing screen off TanStack Query - #53853

Merged
jeherve merged 6 commits into
trunkfrom
update/sharing-likes-drop-tanstack
Oct 21, 2026
Merged

jeherve merged 6 commits into
trunkfrom
update/sharing-likes-drop-tanstack

Conversation

@jeherve

@jeherve jeherve commented Oct 20, 2026

Copy link
Copy Markdown
Member

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/data store, the way Newsletter's settings screen works. Requests stay plain apiFetch calls, and snackbars still go through the notices store; there's no TanStack or core-data left.

  • data/store.ts holds status, settings and services, filled from JetpackScriptData so the first render still waits on no request. Resolvers handle the reads.
  • data/writes.ts holds every write. They all go through one queue, so requests reach the server one at a time, in the order you clicked.
  • The hooks keep their names and return shapes (useStatus, useSettings, useServices, useSaveSetting, useSaveServices, useCustomService, useFeatureAction), so the sections and the services manager are unchanged. useIsSaving() replaces useIsMutating() for the unsaved-changes warning.

What TanStack did for us is rebuilt in the store:

  • Saves are still optimistic. A refused save rolls back only its own value, and only if no later edit replaced it. A response landing while another save waits doesn't overwrite that save's value.
  • Each local change bumps a version, so a read already in flight is dropped instead of landing on top of an optimistic value. TanStack's cancelQueries() did that job.
  • A pending-write count drives the unsaved-changes warning.

Why

TanStack came in with the screen (#53297) and was bundled into the route, while @wordpress/data already 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 used retry: false and networkMode: 'always'.

I considered @wordpress/core-data entities 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-data also 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

  • After a write, status and settings are always read again. TanStack only refetched queries a component was showing, but both are always on screen, so the requests are the same as before.
  • After a feature action, the services list is either read again (when Sharing still configures) or left alone. There's no more "mark it stale for later" in between; nothing in the screen needed it.
  • Sharing & Likes: Replace "Open Site Editor" with template placement cards #53838 (template placement cards) still imports TanStack. Once this lands it needs the same treatment, plus a "last saved value" the store doesn't track yet, for the cards' "Preview and edit" link.

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:

<?php
add_filter( 'rsm_jetpack_ui_modernization_sharing_likes', '__return_true' );

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.

  • On load, only sharing-likes/services is requested; status and settings come from the page.
  • Change each setting (button style, sharing label, Disable CSS and JS, the Likes radio, placement, Twitter Site Tag) and reload. Everything sticks.
  • Throttle the network to "Slow 4G" and click two checkboxes in a row. Both change straight away, but the second settings request only starts once the first one, and the status read after it, have finished.
  • In DevTools, block requests matching 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.
  • Turn Comment Likes off, then on. The placement heading changes from "Where sharing buttons, Like buttons, and Comment Likes appear" to "Where sharing and Like buttons appear" and back.
  • In the services manager: add a service, create a custom one, edit it, move a button, remove one and use Undo, delete the custom service, then reload. Removing the last button asks first.
  • Still throttled, change a setting and close the tab while it saves. The browser asks before leaving.
  • Use "Switch to the Like block" and "Switch to the Sharing Buttons block". The sections change, and there's no services request afterwards (that route answers 409 once Sharing hands off).
  • Switch to a classic theme such as Twenty Twenty-One and turn off the Sharing and Likes modules. Use "Turn on sharing buttons" and "Turn on Like buttons"; the options come back.
  • The console shows nothing new. The addEventListener error from sharedaddy/sharing.js is already there on trunk :)

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).
@jeherve jeherve added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Sharing Post sharing, sharing buttons Docs [Status] Needs Review This PR is ready for review. [Tests] Includes Tests [Package] Sharing Likes labels Oct 20, 2026
@jeherve jeherve self-assigned this Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 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 update/sharing-likes-drop-tanstack branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/sharing-likes-drop-tanstack
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/sharing-likes-drop-tanstack

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

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!

@jp-launch-control

jp-launch-control Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 6 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/sharing-likes/src/settings-app/data/use-feature-action.ts 7/7 (100.00%) 0.00% 0 💚
projects/packages/sharing-likes/src/settings-app/data/use-save-setting.ts 1/1 (100.00%) 0.00% 0 💚
projects/packages/sharing-likes/src/settings-app/data/queries.ts 11/12 (91.67%) 7.05% -1 💚
projects/packages/sharing-likes/src/settings-app/data/use-save-services.ts 1/1 (100.00%) 2.86% -1 💚
projects/packages/sharing-likes/routes/settings/stage.tsx 0/4 (0.00%) 0.00% -2 💚

2 files are newly checked for coverage.

File Coverage
projects/packages/sharing-likes/src/settings-app/data/writes.ts 121/125 (96.80%) 💚
projects/packages/sharing-likes/src/settings-app/data/store.ts 42/42 (100.00%) 💚

Full summary · PHP report · JS report

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
jeherve merged commit 0cdec97 into trunk Oct 21, 2026
129 of 130 checks passed
@jeherve
jeherve deleted the update/sharing-likes-drop-tanstack branch October 21, 2026 12:37
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Oct 21, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Sharing Post sharing, sharing buttons [Package] Sharing Likes [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant