Repository navigation
Connection: Tell the admin when a failed fresh connection has left the site disconnected - #55384
Conversation
…e site disconnected Starting a fresh connection from Safe Mode disconnects the site before it registers again. When registration fails, the endpoint now adds `disconnected: true` to the error's data, keeping its code, and the new Safe Mode screen shows its own message for it instead of the generic server error.
|
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! |
…thod name, for Phan
Code Coverage SummaryCoverage changed in 4 files.
|
bindlegirl
left a comment
There was a problem hiding this comment.
Tested and found one issue worth addressing. Also confirmed in code review:
- After the "disconnected" error, the screen still offers the Safe Mode choices (identity-crisis.tsx:170, L179).
Pressing Back, or picking the other answer on the same step, clears the error (use-identity-crisis-flow.ts:30-35). The new message disappears and the screen goes back to showing Safe Mode choices, although the site is no longer in Safe Mode.
Migrate then reports success and shows "Address update started" on a disconnected site.
Keep Safe Mode saves safe_mode_confirmed. After a reconnect, only the Jetpack plugin clears that setting. So on a site without the Jetpack plugin, the next real Safe Mode starts already confirmed and its notice is hidden.
The old screen has the same hole, but the new screen can now tell this case apart.
Fix: set isDisconnected = actions.error?.cause === 'disconnected', then disabled={ isBusy || isDisconnected } on ChoiceStep and canGoBack={ … && ! isDisconnected }. "Try again" keeps working.
- Minor issue: Testing step 2 is empty. It reads "Put the site in Safe Mode:" with nothing after the colon, and steps 5–7 depend on it. A code block probably got dropped.
| ); | ||
| case 'disconnected': | ||
| return __( | ||
| 'Your site couldn’t be registered with WordPress.com again, so it is now disconnected. Try again to connect it, or connect it later from My Jetpack.', |
There was a problem hiding this comment.
| 'Your site couldn’t be registered with WordPress.com again, so it is now disconnected. Try again to connect it, or connect it later from My Jetpack.', | |
| 'Your site couldn’t be registered with WordPress.com again, so it is now disconnected. Try again to connect it, or connect it later from Settings->Connectors->Jetpack Connection', |
Woo plugins don't have My Jetpack and Connectors card is the main connection hub so I think we should do it like this? I'm not sure if the format with -> is the best way though.
There was a problem hiding this comment.
Nice catch!
I took your wording suggestion, with › instead of -> to match how our other strings write menu paths ("Settings › General"): example "…or connect it later in Settings › Connectors, under Jetpack Connection."
…h connection disconnects the site Changing the answer or going back cleared the error and offered the Safe Mode choices again, though the site was no longer in Safe Mode. The message now points to Settings › Connectors, which every plugin has, instead of My Jetpack.
|
Thanks for the review @bindlegirl
Addressed in e3077e4. Once the error says the site is disconnected, the answers are disabled, and Back is hidden, so only "Try again" remains. Added a screen test for it.
Added an |
…on-tell-the-admin-when-a-failed-fresh # Conflicts: # projects/js-packages/connection/components/identity-crisis/identity-crisis.tsx # projects/js-packages/connection/components/identity-crisis/test/identity-crisis.test.tsx
bindlegirl
left a comment
There was a problem hiding this comment.
Retested. LGTM! Nice work 🚢
There was a problem hiding this comment.
Thanks for working on this!
The lock added in the commit e3077e4 introduced an issue: the lock drops if 'try again' fails for another reason.
isDisconnected comes from the latest error, but "site is disconnected" is lasting state. run() calls setError( null ) on each attempt, then sets the new cause:
- Start fresh fails: disconnected, options locked.
- Try again fails with offline, session, blocked, output or server.
isDisconnectedis false: Back and Safe Mode options return, on a disconnected site.
How to replicate: force an error as per the testing steps. Before clicking 'try again', set to offline mode in the browser network tab. Presumably rare case, but still possible.
Suggested fix: keep it in the hook, like isMigrated, and never clear it:
// use-identity-crisis-actions/index.ts
const [ isDisconnected, setIsDisconnected ] = useState( false );
// in catch:
const cause = getIdentityCrisisErrorCause( caught );
if ( cause === 'disconnected' ) {
setIsDisconnected( true );
}
Add isDisconnected: boolean to IdentityCrisisActions, and use actions.isDisconnected in the screen. Any host using the hook directly then gets it too. Extend the new test with a second, different rejection.
Additionally, closing the Connectors panel removes the lock.
"Close" unmounts the screen, dropping its state. The store still says Safe Mode, because its identityCrisis reducer never changes. Reopening shows the first question with no error. Migrate and Keep Safe Mode can then run on a disconnected site.
Suggested fix could be to hide the screen on Close instead of removing it.
Lastly, "Try again" can delete a connection made in the meantime - for example in testing assuming you have the safe model panels open in one tab and the connectors card in another.
Many thanks for the review @coder-karen. Since I had already merged, and this is safe by being behind a feature flag, I'm tackling this in a newer PR. Will point to this one once it is created. |
|
@coder-karen Opened #55402 to tackle the issues found in your review. Please take a look when you have some time :) |
…isconnected, and refuse a stale fresh connection (#55402) * Connection: Keep the Safe Mode screen on Try again once the site is disconnected, and refuse a stale fresh connection Follow-up to #55384's review. The screen now remembers a failed fresh connection that left the site disconnected across later failures, and in the connection store so a remounted screen (Connectors panel Close) remembers it too. The start-fresh endpoint refuses to disconnect a site that is connected and no longer in Safe Mode, so a screen left open in another tab can't undo a connection made since. * Connection: Mark the store from the Safe Mode actions hook, restore focus, and test the guard's Safe Mode case Review follow-ups: the hook marks the connection store as soon as the request fails, so closing the panel mid-request no longer loses it; focus moves to Try again when the view switches; the notice hides while retrying so a repeated failure is announced; the reducer skips a no-op update; the README lists isDisconnected; and a test checks a connected site in Safe Mode can still start fresh, with the Status cache cleared between tests. * Connection: Remove the Safe Mode filter the start-fresh test adds * Connection: Head the disconnected Safe Mode view accordingly and drop the host's actions there * Connection: Show a Reload view once Safe Mode was resolved elsewhere, instead of Try again * Connection: Note the Reload view and the screen's flag in the changelog
Fixes CONNECT-627
Proposed changes
Creating a fresh connection from Safe Mode disconnects the site first and registers it again second. If registration fails, the site is left disconnected, but the new Safe Mode screen showed the generic "Your site's server ran into a problem" message.
identity-crisis/start-fresh: whentry_registration()fails, the error keeps its code (cannot_save_secrets,site_inaccessible, …) and getsdisconnected: truein its data. Error data that isn't an array (empty, or the HTTP code) is not merged;WP_Error::add_data()keeps it in the response'sadditional_data. So for an error whose data was the HTTP code (e.g.site_inaccessible),datachanges from a number to an object; nothing in the monorepo reads it.start_fresh_missing_connection_urland an error from thejetpack_idc_authorization_urlfilter come after registration succeeded, and the nonce and permission checks run before the disconnect, so they keep today's message.getIdentityCrisisErrorCause()returns a newdisconnectedcause for it, andIdentityCrisisErrorNoticesays the site is now disconnected, and to try again or connect it later in Settings › Connectors.error_causeand the real reason aserror_code.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Use a connected Jetpack site running this branch.
start-freshresponse hascode: test_registration_failedanddata.disconnected: true.The site is now disconnected and no longer in Safe Mode.
jetpack_pre_registerline, connect the site again and put it back in Safe Mode (step 2). Run step 3 again: you land on WordPress.com's connect flow.