Repository navigation
Connection: Transfer ownership without leaving the site - #53359
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! 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. Backup 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. Boost 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. Search 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. Social 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. Protect 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. Videopress 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. Stats Data 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. |
Code Coverage SummaryCoverage changed in 6 files. Only the first 5 are listed here.
7 files are newly checked for coverage. Only the first 5 are listed here.
|
There was a problem hiding this comment.
🟡 Changes recommended
Optional-action handling, error accessibility, and documented navigation behavior remain inconsistent.
5 open findings
What changed in this PR
Adds an in-product connection ownership transfer flow, replacing redirects to WordPress.com.
Changes:
- Adds the candidate REST endpoint and JavaScript API methods.
- Adds and integrates the transfer workflow into connection dialogs.
- Adds tests, styling, and user-facing changelogs.
| File | Description |
|---|---|
projects/plugins/videopress/changelog/add-cnx-ownership-transfer |
Adds VideoPress release note. |
projects/plugins/stats/changelog/add-cnx-ownership-transfer |
Adds Stats release note. |
projects/plugins/social/changelog/add-cnx-ownership-transfer |
Adds Social release note. |
projects/plugins/search/changelog/add-cnx-ownership-transfer |
Adds Search release note. |
projects/plugins/protect/changelog/add-cnx-ownership-transfer |
Adds Protect release note. |
projects/plugins/jetpack/changelog/add-cnx-ownership-transfer |
Adds Jetpack release note. |
projects/plugins/boost/changelog/add-cnx-ownership-transfer |
Adds Boost release note. |
projects/plugins/backup/changelog/add-cnx-ownership-transfer |
Adds Backup release note. |
projects/packages/connection/tests/php/REST_Endpoints_Test.php |
Tests candidate filtering and authorization. |
projects/packages/connection/src/class-rest-connector.php |
Implements the candidate endpoint. |
projects/packages/connection/changelog/add-cnx-ownership-transfer |
Documents the endpoint. |
projects/js-packages/connection/index.jsx |
Exports the transfer component and type. |
projects/js-packages/connection/components/transfer-connection-ownership/use-ownership-transfer.ts |
Manages transfer state and requests. |
projects/js-packages/connection/components/transfer-connection-ownership/types.ts |
Defines candidate data. |
projects/js-packages/connection/components/transfer-connection-ownership/test/component.tsx |
Tests transfer behavior and errors. |
projects/js-packages/connection/components/transfer-connection-ownership/style.scss |
Styles the transfer workflow. |
projects/js-packages/connection/components/transfer-connection-ownership/index.tsx |
Composes transfer steps and actions. |
projects/js-packages/connection/components/transfer-connection-ownership/done-step.tsx |
Renders transfer confirmation. |
projects/js-packages/connection/components/transfer-connection-ownership/confirm-step.tsx |
Renders transfer review and warnings. |
projects/js-packages/connection/components/transfer-connection-ownership/candidate-list.tsx |
Renders candidate selection and empty states. |
projects/js-packages/connection/components/transfer-connection-ownership/candidate-identity.tsx |
Renders candidate identity badges. |
projects/js-packages/connection/components/owner-disconnect-dialog/test/component.tsx |
Tests handoff to the transfer flow. |
projects/js-packages/connection/components/owner-disconnect-dialog/index.tsx |
Replaces external transfer navigation. |
projects/js-packages/connection/components/manage-connection-dialog/test/component.tsx |
Tests integrated transfer navigation. |
projects/js-packages/connection/components/manage-connection-dialog/style.scss |
Sizes the embedded workflow. |
projects/js-packages/connection/components/manage-connection-dialog/index.tsx |
Embeds and coordinates ownership transfer. |
projects/js-packages/connection/changelog/add-cnx-ownership-transfer |
Documents the new UI flow. |
projects/js-packages/api/index.jsx |
Adds candidate-fetch and owner-update methods. |
projects/js-packages/api/changelog/add-cnx-ownership-transfer |
Documents the API methods. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ad5b9ab to
e5a0222
Compare
coder-karen
left a comment
There was a problem hiding this comment.
Thanks @fgiannar, this tests well!
I've got a couple of questions / suggestions after reviewing code:
If ownership is locked, shouldn't we prevent offering the option to transfer at all? Before getting to the stage where we click 'transfer ownership', that is.
On the done step, Done is the only exit, and with onOwnershipTransferred set, leaveTransfer calls it and returns without leaving the step or resetting isTransferOpen / newOwnerId. So the component passing the callback has to close the dialog itself, otherwise it looks like the user is stuck. Even then, the stale state sends the next open straight back to the chooser, where Back fires the callback again, so there is a 'done loop' that can't end.
Could the callback branch reset both before returning?
And the docblock could say what's expected of the consumer, e.g. that it should close the dialog or refresh its own state.
Not an issue right now as noone uses the component, but probably makes sense to clarify now before it gets used.
- Component usage:
You can useStackinstead of hand-written flex CSS. Five classes in style.scss just recreate it:-form,__transfer-ownership,__identity,__handover,__who(style.scss#L3-L15, L46-L50, L62-L78). For example:
<Stack direction="column" gap="lg" className="jp-connection__transfer-ownership-form">
<Stack direction="row" align="center" gap="md">
`checkStatus` rejects with an Error whose message is "<server text> (Status 400)" and hangs the REST body off `response`. The catch read `err.code`, which is never set on that Error, so every refusal fell through to the default branch and printed the raw server string — all four mapped messages were unreachable. The tests missed it because they rejected with the body alone, the shape the component assumed rather than the one it receives. They now reject the way `checkStatus` does, and cover each code. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
`align-self: stretch` beside `margin-inline: auto` does nothing: an auto cross-axis margin absorbs the free space first, so the step shrink-wrapped and the centred column was whatever its content happened to need. The done step made it obvious, being the shortest, but every view was sized by accident. Set the width explicitly instead. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
All three pointed at the top of the same page, leaving the reader to find the part that answers them. The two "how does someone connect" links now open the connection section, and the ownership link the one describing the connection owner. The anchor is an argument rather than a fragment in the slug: getRedirectUrl discards anything after a `#`. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
@wordpress/ui's scale starts at 13px and body-sm is 12px, so the step had been rendering as fine print inside a dialog whose own copy is 16px. Take the base from Jetpack's `--font-body` and keep the secondary pieces relative to it, rather than inheriting a scale built for denser surfaces. `--font-label` would have made this worse: base-styles jumps 12px to 16px with nothing in between, which is why three other projects each declare their own 14px token. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
… gaps The step reloaded the page itself, where every other post-action in this package — disconnect, unlink, protected-owner confirm and release — is handed to the consumer. Add `onOwnershipTransferred` for the same reason, keeping the reload as its default: the transfer changes what the current user may do, so a consumer that does nothing must not be left showing owner-only actions. Tests for what was untested: that leaving a completed transfer reports the new owner, that the owner-disconnect warning hands over to this dialog rather than opening a second flow, the candidates fetch failure, and the logged-out and not-the-owner cases on the endpoint. Leftovers: a `.check-users` rule with no renderer, an `isLoading` the hook returned and nobody read, and `ConnectionOwnerCandidate`, which the Connectors card will need and could not import. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The confirm step spliced the display name into the string handed to createInterpolateElement, so a name containing a `<` would have been parsed as markup rather than shown. Pass it as the element's child instead. The other four names in this step go straight into JSX, where React escapes them, so they stay as they are. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
…to do Both error messages arrived after an async failure as plain styled text, with focus still on the button that triggered them, so a screen reader user got no sign the transfer had been refused. Render them as error Notices, which announce themselves and match the warning, info and success notices the flow already uses. The success step also rendered Done unconditionally while the chooser hides its dismiss without a callback, so a consumer handling completion itself got a button that did nothing. Guard it the same way. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
Three places where the component built by hand what @wordpress/ui provides, and the hand-built version was missing the accessible half each time: * The confirm button swapped its label to "Transferring…" and set `disabled`. `Button` has `loading` and `loadingAnnouncement`, and derives `disabled` from `loading`, so the state is announced rather than only shown. * `CandidateIdentity` reached for `<strong>` and `<span>` where every sibling step uses `Text`. Dropping `Text`'s variants over their type scale never required dropping `Text`. * Five class rules re-declared what `Stack` does. Its `lg` and `md` gaps are the 16px and 12px those rules hardcoded, so the layout is unchanged; the classes stay for what is genuinely ours, like the load-bearing `flex-shrink: 0`. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The dialog tracked "which view" and "did it complete" separately, so the two could disagree. After a consumer callback neither was cleared: the user was left on a dead Done button, and the next open came back to the chooser still believing a transfer had happened, where Back re-fired the callback. Collapse them into one value, with the new owner living inside the state that means completed. Closing is a single write, so the pair cannot drift, and an id only exists where there is one to read. This is the two-sources-of-truth problem an earlier review judged unreachable. It was, until `onOwnershipTransferred` added a path where the page does not reload — which I added without rechecking that. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The owner and `isMaster` were seeded into the connection store once at page load and never written again — both reducers handled no action at all — so the only way a surface learned about a transfer was a full reload. That reload was the reason for a Done button, a consumer callback, a hidden navigation inside a shared component, and the stale-state problem behind all of them. Add `setConnectionOwner`, patched from the transfer rather than refetched: nothing else in the user connection data turns on ownership — the permissions it reports are plain capability checks — so a request would only confirm what the caller already knows. With the store current, the component sheds the chrome that existed to work around it. It now renders only what its steps need — Continue, Back, Transfer — and leaving is the surrounding surface's business: in the dialog, the footer returns to the actions, which already reflect the new owner. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
"Back" on the success step promised a step to return to that no longer exists, and on the confirm step it collided with the step's own Back — two controls, same word, different destinations. The footer is now purely the dialog's exit: Cancel, or Close once ownership has moved. Step navigation belongs to the step, which has the only Back. Closing also forgets the view, so reopening starts on the actions rather than on whatever was last on screen — the staleness that was previously masked by the footer never closing from inside the flow. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The README documents each exported component, and this one is exported for the Connectors card to reuse — so say what it renders, what it deliberately does not, and that it updates the store rather than expecting a reload. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The confirm step claimed the new owner's account would power site-level features. Those come from the site connection; the owner's account is about whose WordPress.com data this site's data is. Per jetpack.com/support/primary-user, the owner owns the data WordPress.com stores for the site and is the point of contact for support about it — so say that instead. The notice link now goes to that page, via the `jetpack-support-primary-user` slug the legacy owner notice already uses, rather than to an anchor in the general connection doc. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
* The transfer view no longer carries an owner id nothing reads, and the dialog can be dismissed with Escape or a click outside once ownership has moved, where there is nothing left to lose. * `useOwnershipTransfer` stops touching an unmounted step: closing mid-request could otherwise land a completed transfer after the view had been reset, so the next open started on the step. The store still learns the new owner. * The protected-owner flag comes from the store's selector rather than from script data, and the select compares candidates by value rather than against the string "null". * The candidates response is typed as `unknown` and narrowed, rather than annotated with a shape the API client never checks. * The README no longer claims every surface updates: a host passing its own copy down as props only reflects the change if that copy comes from the store. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The flag was seeded at page load and never written again, so after ownership moves it describes a site state that may no longer hold: the server may have released the anchor, or ownership may have moved to the anchored user. Only the server knows which, and the store already uses null for "cannot say". CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
When a site has exactly one connected administrator there is nothing to choose between, so choose it: the select opens on them and Continue is available straight away. The manage dialog's content padding was a flat 80px with no breakpoint, which on a phone left a couple of hundred pixels of content — enough to truncate the select's placeholder and wrap the heading a word at a time. Start at 2rem/1rem and keep the 80px from 600px up, matching the disconnect dialog. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
f7cdb59 to
516f2f0
Compare
Cancel stayed live during the request, and leaving did not cancel anything: the transfer still landed and still reached the store, so ownership moved with nobody told, and a refusal was never shown at all. The component knows it is busy and the dialog owns the exit, so the one reports and the other acts on it. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
The notice spliced the display name into the string handed to
createInterpolateElement, so a name containing a `<` would be parsed as
markup. Pass it as the element's child, as the line above it already does.
`<name />` was never extracted: the type drops any tag containing a space, so
where it was the only tag the conversion map widened to `{}` and checked
nothing. Both are `<name/>` now, and the map is enforced.
CONNECT-480
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
WordPress ships @wordpress/components to the page as `wp.components`, so it costs nothing to use. @wordpress/ui is not provided that way and is bundled into ours, and its select brings Base UI and the whole Floating UI positioning stack with it. Swapping the one control takes the shared jetpack-connection.js from 462KB to 251KB, and 104KB to 51KB gzipped — every page that loads the script was paying that, not just this step. The trade is a native `<select>`, which looks less like the @wordpress/ui controls around it and behaves better on mobile and with assistive tech. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
`onTransferred` was created in the test but never passed to the dialog, which has no such prop since the consumer callback was removed — so asserting it was never called proved nothing. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
Swapping to the transfer step unmounts the link that was clicked, so focus fell to the document body — a keyboard or screen reader user was left outside the dialog they were still in, with no announcement that the view had changed. Focus the heading instead, which is what the dialog is labelled by, so the new view announces itself. CONNECT-480 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYDknke15qyKNtrT2KMcyo
|
Many thanks for reviewing @LiamSarsfield !
Done via 3d51d08
This would be an edge case that can be handled in a follow-up PR, when we migrate the component in the Connectors screen.
Leftover from previous versions, I have updated the PR description now.
Fixed via 3d2ccbb
Fixed via 5182d44
Fixed via 577fe61
Yes, pls note that the existing link would redirect to the core users page without any filtering for connected users. We've added the corresponding link in the Connectors card ( via #53150) instead (central hub for managing Jetpack Connection) with actual filtering for connected users. |
|
Many thanks @coder-karen ! Great findings on the build sizes and I've made a note of this so going forward Replaced via 0a1dd20 |
coder-karen
left a comment
There was a problem hiding this comment.
This tests well for me, thanks!

Related to CONNECT-480
Proposed changes
Changing the connection owner currently means leaving the site for Calypso. This adds the in-product transfer flow and points both connection dialogs at it.
GET jetpack/v4/connection/owner/candidateslists the connected administratorsPOST /connection/ownerwould accept — filtered by the same administrator capabilityManager::update_connection_owner()requires, with the current owner left out, so the UI can't offer somebody the change would then refuse. Local user data only; resolving WordPress.com profiles would cost a request per user. Gated onjetpack_disconnect, the same capability as changing the owner.fetchConnectionOwnerCandidates()andsetConnectionOwner()injs-packages/api.<TransferConnectionOwnership>component carrying the whole flow — choose an administrator, confirm what moves with ownership, then a success step the surface dismisses.Three cases it handles rather than failing generically:
ownership_locked,new_owner_not_admin,new_owner_not_connected,new_owner_is_existing_owner. The list is built when the dialog opens, so a candidate can stop qualifying while it's on screen.Two smaller behaviour fixes that came out of testing:
isMasterfrom page load and had no way to update them — both reducers handled no action at all — so the only way a surface learned about a transfer was reloading. AsetConnectionOwneraction now records it, patched from the transfer rather than refetched: nothing else in the user connection data turns on ownership, so a request would only confirm what we already know. Surfaces reading connection state update in place.Separation of concerns
TransferConnectionOwnershiprenders no chrome of its own — no modal, no heading, no way out. It draws only what its steps need: Continue, Back between steps, and the transfer itself. Everything else belongs to the surface hosting it, which is what lets the same component serve the manage dialog now and the Connectors card next.TransferConnectionOwnershipManageConnectionDialogThe component having no Cancel, Close or Done falls out of that rather than being a separate decision: each is a way of leaving a container the component doesn't own. Its only prop beyond
apiRoot/apiNonceisonTransferred, for a host that needs to do something extra once ownership has moved — not to make it work.Where this departs from the mockups
--jp-pinkfor the incoming one. Avatars were tried and dropped: script data carries no avatar for the outgoing owner, so one badge could only ever be initials while the other fetched a Gravatar, which is a guaranteed mismatch. The endpoint no longer returns an avatar URL, so nothing is requested from Gravatar.Not included, per the issue's scope: the Connectors card itself (blocked on CONNECT-478), gating owner disconnect on transfer (CONNECT-486), and the legacy
Connection_Noticeform onusers.php.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. No new tracking events. The new endpoint returns local user data (ID, login, display name, email) that an administrator can already read from

users.php, and only to a user withjetpack_disconnect. Nothing is fetched from a third party — the badges are initials, not Gravatars.Testing instructions
Needs a site with at least two administrators who have both connected their WordPress.com accounts, logged in as the connection owner.
The transfer itself
users.php(the Connected to WordPress.com column) and that the manage dialog no longer offers you owner-only actions.One dialog, one exit, and no reload
Escape, clicking outside and a ✕ all do nothing — the manage dialog disables them by design.Update: Escape and click-outside now work once ownership has movedFrom the owner disconnect warning
No other connected administrators
Refusal messages
Protected owner,
wp eval 'var_export( Automattic\Jetpack\Connection\Protected_Owner::set( WPCOM_ID, LOCAL_ID ) );'Non-owner admin
Error states
Both need a snippet in a mu-plugin (
wp-content/mu-plugins/), removed afterwards.Ownership locked.
add_filter( 'jetpack_connection_ownership_transferable', '__return_false' );Transfer from the confirm step: you should get "Ownership of this connection is locked and cannot be transferred."
-- Note the filter is currently being deprecated, however you can still test with it atm.
WordPress.com refuses the change. Make the outbound call fail:
Transfer from the confirm step: you should get "Could not confirm new owner." and stay on the confirm step so you can retry. Then check
users.php— the owner must be unchanged.update_connection_owner()notifies WordPress.com first and only writesmaster_useron success, so a partial failure has to leave the old owner in place.