From 0ea24cc660dcad0ca77c7128e232af8fda710469 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Sat, 26 Sep 2026 20:47:27 -0400 Subject: [PATCH 01/15] My Jetpack: show the site itself while asking what it is for The prototype's identity stage, ported: the site's own homepage in a browser window in a receding stack, over a count of what is in it. The screenshot comes from WordPress.com's mshots service, the same one Calypso uses. It has no callback and no status, so it is polled: the same URL answers 200 with a placeholder while the page renders and 200 with the picture once it has. Both are 400 by 300, so the content type is the only thing that separates them and the pixels cannot be measured. Nothing waits on it. The panel draws either way and the picture arrives into it, or it does not. What the panel will not claim: - No window at all for a site that cannot be photographed. A frame around nothing promises a photograph that will never arrive, and the counts on their own are at least all true. - No count of zero. A zero is how an unmeasured field is spelled at least as often as it is a real count. - The backs of the stack are blank. The prototype writes the site's feed URLs on them because its scan really read those pages; we read nothing. - A numeral counts up only when it is large enough for the count to read as motion. Counting to 1 spends most of a second showing 0. The whole panel is hidden from the accessibility tree: the question is on the left, and the picture is of a site the reader is sitting inside. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../components/onboarding-screen/index.tsx | 8 +- .../onboarding-screen/wizard/lib.ts | 10 + .../wizard/site-portrait.tsx | 277 ++++++++++++++++++ .../wizard/styles.module.scss | 210 +++++++++++++ .../wizard/test/site-portrait.test.tsx | 244 +++++++++++++++ .../onboarding-screen/wizard/use-site-shot.ts | 112 +++++++ .../onboarding-screen/wizard/wizard.tsx | 27 +- .../add-my-jetpack-onboarding-site-portrait | 4 + projects/packages/my-jetpack/global.d.ts | 7 + .../my-jetpack/src/class-initializer.php | 63 ++++ .../add-my-jetpack-onboarding-site-portrait | 4 + 11 files changed, 957 insertions(+), 9 deletions(-) create mode 100644 projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx create mode 100644 projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx create mode 100644 projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts create mode 100644 projects/packages/my-jetpack/changelog/add-my-jetpack-onboarding-site-portrait create mode 100644 projects/plugins/jetpack/changelog/add-my-jetpack-onboarding-site-portrait diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/index.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/index.tsx index a3c928749de2..90c0acdd5700 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/index.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/index.tsx @@ -16,7 +16,13 @@ const OnboardingScreen: FC = () => { const wizard = getMyJetpackWindowInitialState( 'onboardingWizard' ); if ( wizard?.exitUrl ) { - return ; + return ( + + ); } return ( diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts index 4f29e0b1d92c..b1f01183dcb3 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts @@ -137,6 +137,16 @@ export type WizardStep = 0 | 1 | 2 | 3; // The WizardStep union has to be hand-written; the count is read off the steps. export const TOTAL_STEPS = wizardSteps().length; +/** What the page tells the wizard about the site it is running on. */ +export interface OnboardingSite { + url: string; + domain: string; + // Whether WordPress.com's screenshot service could reach it; decided in PHP, + // because a failure comes back as a picture of a failure rather than an error. + canPhotograph: boolean; + counts: { posts: number; pages: number; media: number; plugins: number }; +} + export interface WizardState { // The option chosen on each step, keyed by step index. choices: Partial< Record< WizardStep, string > >; diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx new file mode 100644 index 000000000000..e31c366f98bb --- /dev/null +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx @@ -0,0 +1,277 @@ +import { useReducedMotion } from '@wordpress/compose'; +import { createInterpolateElement } from '@wordpress/element'; +import { _n } from '@wordpress/i18n'; +import clsx from 'clsx'; +import { useEffect, useRef, useState } from 'react'; +import styles from './styles.module.scss'; +import { useSiteShot } from './use-site-shot'; +import type { OnboardingSite } from './lib'; +import type { ReactNode } from 'react'; + +// How long a numeral takes to reach its value, from the prototype. +const COUNT_MS = 900; + +/* + * Below this a count-up is not motion, it is a wrong number held on screen: a + * count to 1 spends most of its 900ms reading "0 posts published", which is + * the exact claim `statLines` filters zeros out to avoid making. + */ +const COUNT_FLOOR = 10; + +/* + * The three lights on a browser's title bar. The prototype's own values, which + * are the muted set rather than the saturated one, so they read as chrome and + * not as status. + */ +const LIGHTS = [ '#f09795', '#ece77d', '#91ce97' ]; + +/** + * The three lights, for the front window and for the backs behind it. + * + * @return The rendered lights. + */ +function Lights() { + return ( + <> + { LIGHTS.map( light => ( + + ) ) } + + ); +} + +/** + * What this site has, one line each. + * + * Whole sentences with the number inside them, marked up rather than split: a + * translator handed "posts published" on its own cannot tell what agrees with + * what, and several languages need the number to place the noun. + * + * A zero is left out. It is how an unmeasured field is spelled at least as + * often as it is a real count, and "0 posts published" on a site with posts is + * worse than saying nothing — which is what the prototype found on a site whose + * media endpoint answered 401. + * + * @param counts - What the page counted. + * @return One entry per count worth showing. + */ +function statLines( counts: OnboardingSite[ 'counts' ] ) { + const lines = [ + { + value: counts.posts, + /* translators: %d is how many posts the site has published. */ + text: _n( + '%d post published', + '%d posts published', + counts.posts, + 'jetpack-my-jetpack' + ), + }, + { + value: counts.pages, + /* translators: %d is how many pages the site has published. */ + text: _n( + '%d page published', + '%d pages published', + counts.pages, + 'jetpack-my-jetpack' + ), + }, + { + value: counts.media, + /* translators: %d is how many files are in the site's media library. */ + text: _n( + '%d file in your media library', + '%d files in your media library', + counts.media, + 'jetpack-my-jetpack' + ), + }, + { + value: counts.plugins, + /* translators: %d is how many plugins the site has installed. */ + text: _n( + '%d plugin installed', + '%d plugins installed', + counts.plugins, + 'jetpack-my-jetpack' + ), + }, + ]; + + return lines.filter( line => line.value > 0 ); +} + +/** + * The numeral, showing either what the site has or where the count is up to. + * + * `children` is the numeral as the translated string spells it, and it is what + * renders at rest. Every frame of a count-up is a number the site does not + * have, so the true one is the default and the count is the exception. + * + * @param props - The component props. + * @param props.at - Where the count is up to, or null when it is not running. + * @param props.children - The numeral as the translated string spells it. + * @return The rendered numeral. + */ +function StatNumeral( { at, children }: { at: number | null; children?: ReactNode } ) { + return ( + { at === null ? children : at } + ); +} + +/** + * One count, as a sentence, with the numeral counting up to it. + * + * The count waits for the row's own entrance delay, which it reads off the + * stylesheet rather than repeating here: written as a constant it would finish + * behind a row that had not faded in yet the first time the stagger changed. + * + * @param props - The component props. + * @param props.text - The translated sentence, with `%d` still in it. + * @param props.value - What to put in place of `%d`. + * @return The rendered row. + */ +function StatRow( { text, value }: { text: string; value: number } ) { + const row = useRef< HTMLParagraphElement >( null ); + const reduced = useReducedMotion(); + const [ at, setAt ] = useState< number | null >( null ); + + useEffect( () => { + if ( reduced || value < COUNT_FLOOR || ! row.current ) { + return; + } + + const delay = parseFloat( getComputedStyle( row.current ).animationDelay ) * 1000 || 0; + let frame = 0; + // Null rather than 0, which is a timestamp a fake clock really does hand out. + let began: number | null = null; + + const tick = ( now: number ) => { + began = began ?? now; + + const through = Math.min( 1, ( now - began ) / COUNT_MS ); + + // Back to the translated numeral at the end rather than to our own + // rendering of the same number, which would not be localized. + if ( through >= 1 ) { + setAt( null ); + return; + } + + setAt( Math.round( value * ( 1 - Math.pow( 1 - through, 3 ) ) ) ); + frame = requestAnimationFrame( tick ); + }; + + const start = setTimeout( () => { + setAt( 0 ); + frame = requestAnimationFrame( tick ); + }, delay ); + + return () => { + clearTimeout( start ); + cancelAnimationFrame( frame ); + }; + }, [ reduced, value ] ); + + return ( +

+ { createInterpolateElement( text.replace( '%d', String( value ) ), { + b: , + } ) } +

+ ); +} + +/** + * This site, as a browser window in a receding stack, over what is in it. + * + * The prototype's identity stage, and the one screen it shows this on: where we + * say what we read the site as and ask whether that is right. Ours asks the + * same question, so it is the same screen. + * + * The backs are blank rather than labelled. The prototype writes the site's + * feed URLs on them because its scan really read those pages; we read nothing, + * so a URL there would be a claim about a fetch that never happened. + * + * Hidden from the accessibility tree in full. Every fact in it is decorative + * here — the question being asked is on the left, the picture is of a site the + * user is sitting inside, and read aloud the counts are four numbers with no + * bearing on the answer. + * + * @param props - The component props. + * @param props.site - What the page told us about this site. + * @return The rendered portrait. + */ +export function SitePortrait( { site }: { site: OnboardingSite } ) { + const shot = useSiteShot( site.url, site.canPhotograph ); + const stats = statLines( site.counts ); + + return ( + + ); +} + +/** + * Whether there is anything true to put on the panel for this site. + * + * @param site - What the page told us, if anything. + * @return True when the portrait has either a picture coming or a count to show. + */ +export function hasPortrait( site: OnboardingSite | undefined ): site is OnboardingSite { + if ( ! site ) { + return false; + } + + return site.canPhotograph || Object.values( site.counts ).some( count => count > 0 ); +} diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index 96a85fdeb424..7a9f21e1f9eb 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -195,6 +195,41 @@ $mesh-mask: linear-gradient(to bottom, #000 0%, #000 62%, $mesh-mask-low 77%); * WPDS duration is --wpds-motion-duration-xl at 400ms, far too fast to read as * drawing, so the prototype's value is kept. */ + +/* + * The site portrait, from the prototype's card-stack.tsx and step-panel.tsx. + * Its numbers were solved from the Figma node rather than eyeballed, so they + * are copied rather than re-derived. + * + * The two backs are PROPORTIONAL, not fixed: the front card is fluid, and + * fixed backs stopped receding and started poking out of both sides once the + * panel narrowed. They are also shorter than the front, so they peek at the + * top and never below it, which is what makes it read as a stack going back + * rather than three cards fanned out. + */ +$portrait-width: 440px; +$portrait-back-far-width: 80.8%; +$portrait-back-far-rise: 23px; +$portrait-back-near-width: 89.7%; +$portrait-back-near-rise: 16px; +$portrait-bar-height: 30px; +$portrait-back-bar-height: 22px; +$portrait-light: 8.5px; +$portrait-back-light: 7px; +$portrait-stat-size-min: 30px; +$portrait-stat-size-max: 46px; + +/* + * Five layers, verbatim. A single flat shadow reads as a sticker, and the + * stack depends on these reading as three separate planes. + */ +$portrait-shadow: + 0 3.819px 3.819px rgba(15, 36, 117, 0.01), + 0 6.668px 6.668px rgba(15, 36, 117, 0.02), + 0 11.604px 11.604px rgba(15, 36, 117, 0.03), + 0 21.255px 21.255px rgba(15, 36, 117, 0.05), + 0 42px 42px rgba(15, 36, 117, 0.1); + $panel-art-width: 77%; $panel-art-draw-duration: 1.4s; @@ -1023,6 +1058,181 @@ $rail-row-min-height: 40px; } } +/* -------------------------------------------------------- site portrait */ + +.portrait { + display: flex; + position: relative; + z-index: 1; + flex-direction: column; + flex-grow: 1; + align-items: center; + justify-content: center; + gap: var(--wpds-dimension-gap-3xl); + min-block-size: 0; +} + +.portrait-stack { + position: relative; + inline-size: 100%; + max-inline-size: $portrait-width; +} + +// Render before the front card: these are its backdrop, and both are absolute +// so they take no space of their own. +.portrait-back { + display: block; + position: absolute; + + // Centred by margin, not by a transform: the entrance animates `transform`, + // and a translateY keyframe replaces a translateX here rather than adding to + // it — which threw both backs off to one side and out of the panel. + inset-inline: 0; + margin-inline: auto; + border-radius: var(--wpds-border-radius-xl); + background: rgba(252, 252, 252, 0.65); + backdrop-filter: blur(5px); + box-shadow: $portrait-shadow; + overflow: hidden; + animation: step-enter $appear-duration $house-easing both; + + @media (prefers-reduced-motion: reduce) { + animation-name: fade-in; + animation-duration: $appear-reduced-duration; + } +} + +.portrait-back--far { + top: -$portrait-back-far-rise; + inline-size: $portrait-back-far-width; + block-size: 150px; + animation-delay: $wave-base; +} + +.portrait-back--near { + top: -$portrait-back-near-rise; + inline-size: $portrait-back-near-width; + block-size: 200px; + background: rgba(252, 252, 252, 0.8); + animation-delay: $wave-base + $wave-step; +} + +.portrait-back__chrome { + display: flex; + align-items: center; + gap: var(--wpds-dimension-gap-xs); + block-size: $portrait-back-bar-height; + padding-inline: var(--wpds-dimension-padding-xs); + border-block-end: var(--wpds-border-width-xs) solid rgba(0, 0, 0, 0.05); + + .portrait-light { + inline-size: $portrait-back-light; + block-size: $portrait-back-light; + } +} + +.portrait-window { + position: relative; + border-radius: var(--wpds-border-radius-xl); + background: var(--jp-white); + box-shadow: $portrait-shadow; + overflow: hidden; + animation: step-enter $appear-duration $house-easing both; + animation-delay: $wave-base + 2 * $wave-step; + + @media (prefers-reduced-motion: reduce) { + animation-name: fade-in; + animation-duration: $appear-reduced-duration; + } +} + +.portrait-window__bar { + display: flex; + align-items: center; + gap: var(--wpds-dimension-gap-sm); + block-size: $portrait-bar-height; + padding-inline: var(--wpds-dimension-padding-xs) var(--wpds-dimension-padding-md); + border-block-end: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak); +} + +.portrait-light { + flex-shrink: 0; + inline-size: $portrait-light; + block-size: $portrait-light; + border-radius: 50%; +} + +.portrait-window__url { + min-inline-size: 0; + flex-grow: 1; + padding-block: 2px; + padding-inline: var(--wpds-dimension-padding-sm); + border-radius: 999px; + background: var(--wpds-color-background-surface-neutral-weak); + color: var(--wpds-color-foreground-content-neutral-weak); + font-size: var(--wpds-typography-font-size-sm); + line-height: var(--wpds-typography-line-height-xs); + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} + +/* + * Drawn whether a picture arrives or not, so the stack does not jump when one + * does. 16:10 is the prototype's crop; the service is asked for the same shape. + */ +.portrait-window__plate { + aspect-ratio: 16 / 10; + background: var(--wpds-color-background-surface-neutral-weak); +} + +.portrait-window__shot { + display: block; + inline-size: 100%; + block-size: 100%; + object-fit: cover; + object-position: top; + animation: fade-in var(--wpds-motion-duration-xl) var(--wpds-motion-easing-subtle) both; +} + +.portrait-stats { + display: grid; + inline-size: 100%; + max-inline-size: $portrait-width; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: var(--wpds-dimension-gap-xl) var(--wpds-dimension-gap-3xl); +} + +.portrait-stat { + margin: 0; + // The panel's own mint, dimmed, so the label sits under the numeral rather + // than beside it in a second green. + color: color-mix(in sRGB, var(--jp-green-mint) 70%, transparent); + font-size: var(--wpds-typography-font-size-md); + line-height: var(--wpds-typography-line-height-sm); + animation: step-enter $appear-duration $house-easing both; + animation-delay: $wave-base + 3 * $wave-step; + + @media (prefers-reduced-motion: reduce) { + animation-name: fade-in; + animation-duration: $appear-reduced-duration; + } +} + +/* + * The prototype sets this as a share of the viewport; the panel is the query + * container here, so the share is of the panel, and 7cqw is the same size at + * the width the two were compared at. + */ +.portrait-stat__value { + display: block; + color: var(--jp-green-mint); + font-size: clamp($portrait-stat-size-min, 7cqw, $portrait-stat-size-max); + font-variant-numeric: tabular-nums; + line-height: 1; + letter-spacing: -0.005em; +} + /* ----------------------------------------------------------- step body */ /* diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx new file mode 100644 index 000000000000..6a01310454aa --- /dev/null +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx @@ -0,0 +1,244 @@ +import { act, render, screen, waitFor } from '@testing-library/react'; +import { useReducedMotion } from '@wordpress/compose'; +import { SitePortrait, hasPortrait } from '../site-portrait'; +import type { OnboardingSite } from '../lib'; + +/* + * The hook caches one media query list per window, so a `matchMedia` stub put + * in place after the first render of the file never reaches it. + */ +jest.mock( '@wordpress/compose', () => ( { + ...jest.requireActual( '@wordpress/compose' ), + useReducedMotion: jest.fn( () => false ), +} ) ); + +const site = ( over: Partial< OnboardingSite > = {} ): OnboardingSite => ( { + url: 'https://example.com', + domain: 'example.com', + canPhotograph: true, + counts: { posts: 12, pages: 3, media: 40, plugins: 7 }, + ...over, +} ); + +const mockFetch = jest.fn(); + +beforeEach( () => { + mockFetch.mockReset(); + window.fetch = mockFetch as unknown as typeof window.fetch; +} ); + +const answers = ( type: string ) => + Promise.resolve( { headers: { get: () => type } } as unknown as Response ); + +describe( 'What the portrait is willing to show', () => { + it( 'says nothing at all for a site with no picture and no counts', () => { + expect( + hasPortrait( + site( { canPhotograph: false, counts: { posts: 0, pages: 0, media: 0, plugins: 0 } } ) + ) + ).toBe( false ); + } ); + + it( 'shows counts even when the site cannot be photographed', () => { + expect( hasPortrait( site( { canPhotograph: false } ) ) ).toBe( true ); + } ); + + it( 'shows the picture even for a site with nothing in it yet', () => { + expect( hasPortrait( site( { counts: { posts: 0, pages: 0, media: 0, plugins: 0 } } ) ) ).toBe( + true + ); + } ); + + /* + * A zero is how an unmeasured field is spelled at least as often as it is a + * real count. "0 posts published" on a site with posts is a claim; leaving the + * line out is not. + */ + it( 'leaves out a count of zero rather than reporting it', () => { + mockFetch.mockReturnValue( answers( 'image/gif' ) ); + + render( + + ); + + expect( screen.getByText( /posts published/ ) ).toBeInTheDocument(); + expect( screen.getByText( /plugins installed/ ) ).toBeInTheDocument(); + expect( screen.queryByText( /page published/ ) ).not.toBeInTheDocument(); + expect( screen.queryByText( /media library/ ) ).not.toBeInTheDocument(); + } ); + + // A frame around nothing promises a photograph that will never arrive. + it( 'draws no browser window for a site it cannot photograph', () => { + render( ); + + expect( screen.queryByText( 'example.com' ) ).not.toBeInTheDocument(); + expect( mockFetch ).not.toHaveBeenCalled(); + } ); +} ); + +describe( 'Waiting for the screenshot', () => { + // The picture carries an empty alt on purpose, so `presentation` is the only + // role it has, and the whole portrait is aria-hidden, so it must be asked for. + const picture = () => screen.queryByRole( 'presentation', { hidden: true } ); + + /* + * The service answers 200 with a placeholder while it renders and 200 with the + * picture once it has. The content type is the only thing between them: both + * are 400 by 300, so there is nothing in the pixels to measure. + */ + it( 'shows nothing while the service is still rendering', async () => { + mockFetch.mockReturnValue( answers( 'image/gif' ) ); + + render( ); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + expect( picture() ).toBeNull(); + } ); + + it( 'shows the picture once the type says it is one', async () => { + mockFetch.mockReturnValue( answers( 'image/jpeg' ) ); + + render( ); + + await waitFor( () => expect( picture() ).not.toBeNull() ); + expect( picture() ).toHaveAttribute( + 'src', + expect.stringContaining( 'mshots/v1/https%3A%2F%2Fexample.com' ) + ); + } ); + + // The URL is what the service keys its render on, so it must not vary. + it( 'polls the same address every time', async () => { + mockFetch.mockReturnValue( answers( 'image/gif' ) ); + + render( ); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + const asked = mockFetch.mock.calls.map( ( [ url ] ) => url ); + + expect( new Set( asked ).size ).toBe( 1 ); + } ); + + it( 'gives up quietly when the service never answers', async () => { + mockFetch.mockRejectedValue( new Error( 'offline' ) ); + + render( ); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + expect( picture() ).toBeNull(); + // The counts are still there: the picture is the part that can fail. + expect( screen.getByText( /posts published/ ) ).toBeInTheDocument(); + } ); +} ); + +describe( 'Counting the numeral up', () => { + /* + * The count runs on real animation frames after a real delay, so the test + * drives both: `frame` runs the pending callback at a chosen point on the + * clock, which is the only way to assert on a frame rather than on whichever + * one the machine happened to render first. + */ + let pending: FrameRequestCallback | null; + let clock: number; + // Restored one by one: `restoreAllMocks` also takes out the console spies the + // monorepo's Jest setup installs, and its own teardown then throws on them. + let spies: jest.SpyInstance[]; + + const frame = ( at: number ) => { + clock = at; + const run = pending; + pending = null; + act( () => run?.( clock ) ); + }; + + const begin = () => act( () => jest.runOnlyPendingTimers() ); + + const row = ( match: RegExp ) => screen.getByText( match, { selector: 'p' } ).textContent; + + beforeEach( () => { + pending = null; + clock = 0; + jest.useFakeTimers(); + mockFetch.mockReturnValue( answers( 'image/gif' ) ); + spies = [ + jest + .spyOn( window, 'requestAnimationFrame' ) + .mockImplementation( cb => ( ( pending = cb ), 1 ) ), + jest.spyOn( window, 'cancelAnimationFrame' ).mockImplementation( () => { + pending = null; + } ), + ]; + } ); + + afterEach( () => { + act( () => jest.runOnlyPendingTimers() ); + jest.useRealTimers(); + jest.mocked( useReducedMotion ).mockReturnValue( false ); + spies.forEach( spy => spy.mockRestore() ); + } ); + + const withPosts = ( posts: number ) => + render( + + ); + + it( 'shows the real number until the row it sits in starts moving', () => { + withPosts( 240 ); + + expect( pending ).toBeNull(); + expect( row( /posts published/ ) ).toBe( '240 posts published' ); + } ); + + it( 'counts from zero once the row starts moving', () => { + withPosts( 240 ); + begin(); + + expect( row( /posts published/ ) ).toBe( '0 posts published' ); + } ); + + it( 'is partway there partway through', () => { + withPosts( 240 ); + begin(); + frame( 0 ); + frame( 450 ); + + const shown = Number( row( /posts published/ )?.split( ' ' )[ 0 ] ); + + expect( shown ).toBeGreaterThan( 0 ); + expect( shown ).toBeLessThan( 240 ); + } ); + + // The last frame must be the translated string, not our own rendering of it. + it( 'lands on the real number and stops', () => { + withPosts( 240 ); + begin(); + frame( 0 ); + frame( 900 ); + + expect( row( /posts published/ ) ).toBe( '240 posts published' ); + expect( pending ).toBeNull(); + } ); + + /* + * Every frame of a count-up is a number the site does not have. At 1 it is + * almost all of them, held long enough to read as a fact rather than motion, + * and the fact it states is the zero `statLines` filters out. + */ + it( 'never counts a number too small to read as counting', () => { + withPosts( 1 ); + begin(); + + expect( pending ).toBeNull(); + expect( row( /post published/ ) ).toBe( '1 post published' ); + } ); + + it( 'does not count at all when motion is turned down', () => { + jest.mocked( useReducedMotion ).mockReturnValue( true ); + + withPosts( 240 ); + begin(); + + expect( pending ).toBeNull(); + expect( row( /posts published/ ) ).toBe( '240 posts published' ); + } ); +} ); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts new file mode 100644 index 000000000000..d2b98715681f --- /dev/null +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts @@ -0,0 +1,112 @@ +import { useEffect, useState } from 'react'; + +/* + * WordPress.com's screenshot service, the same one Calypso uses for importers + * and migration previews. `vpw`/`vph` are the viewport it renders at, `w`/`h` + * the image it returns, and `scale` 2 asks for retina. + */ +const MSHOTS = 'https://s0.wp.com/mshots/v1/'; +const VIEWPORT = 1600; +const WIDTH = 880; +const HEIGHT = 550; + +/* + * The first requests answer with a placeholder while the page is rendered, and + * a later one answers with the picture. Measured against the live service: the + * type flipped on the third poll at this interval. + */ +const RETRY_MS = 2500; +const MAX_TRIES = 10; + +/** + * The address of this site's homepage as WordPress.com would photograph it. + * + * @param url - The site's own URL. + * @return The screenshot URL. + */ +function shotUrl( url: string ): string { + const query = new URLSearchParams( { + vpw: String( VIEWPORT ), + vph: String( VIEWPORT ), + w: String( WIDTH ), + h: String( HEIGHT ), + scale: '2', + } ); + + return `${ MSHOTS }${ encodeURIComponent( url ) }?${ query }`; +} + +/** + * A photograph of this site's homepage, once there is one. + * + * Null until the service has a real picture, and null for good if it never + * does. Nothing waits on this: the panel draws either way and the picture + * arrives into it, or does not. + * + * The polling is the awkward part and it is not ours. There is no callback and + * no status: the same URL answers 200 with `image/gif` while the page is being + * rendered and 200 with `image/jpeg` once it has been, so the content type is + * the only thing that separates them. Calypso's own helper does the same. + * + * It is read with `fetch` rather than by loading the image and measuring it. + * Measured against the live service, the placeholder and the screenshot are + * both 400 by 300, so there is nothing in the pixels to tell them apart. + * + * The URL never varies between polls. It is what the service keys its render + * on, so a cache-buster would start a new render every time and never finish + * one. + * + * @param url - The site's own URL, or undefined to ask for nothing. + * @param allowed - Whether this site can be photographed at all; see the PHP. + * @return The screenshot URL once it is a screenshot, or null. + */ +export function useSiteShot( url: string | undefined, allowed: boolean ): string | null { + const [ ready, setReady ] = useState< string | null >( null ); + + useEffect( () => { + if ( ! url || ! allowed ) { + return; + } + + const src = shotUrl( url ); + let tries = 0; + let timer: ReturnType< typeof setTimeout >; + let live = true; + + const ask = async () => { + let done = false; + + try { + const response = await window.fetch( src, { mode: 'cors' } ); + done = ( response.headers.get( 'content-type' ) ?? '' ).includes( 'jpeg' ); + } catch { + // A network refusal is the same as not ready yet: try again, and stop + // when the tries run out. The panel keeps its artwork either way. + } + + if ( ! live ) { + return; + } + + if ( done ) { + setReady( src ); + return; + } + + tries += 1; + + if ( tries < MAX_TRIES ) { + timer = setTimeout( ask, RETRY_MS ); + } + }; + + ask(); + + return () => { + live = false; + clearTimeout( timer ); + }; + }, [ url, allowed ] ); + + return ready; +} diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx index 68f369da5b47..369c24ba8999 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx @@ -28,6 +28,7 @@ import { } from './lib'; import { PanelArt } from './panel-art'; import { PANEL_LINES } from './panel-type'; +import { hasPortrait, SitePortrait } from './site-portrait'; import { ChoiceStep } from './steps/choice-step'; import { FeaturesStep } from './steps/features-step'; import { FinishStep } from './steps/finish-step'; @@ -36,7 +37,7 @@ import styles from './styles.module.scss'; import { useJustConnected } from './use-just-connected'; import { readSavedRun, useSavedRun } from './use-saved-run'; import { useApplySetupModules, useSetupModules } from './use-setup-modules'; -import type { SettleOutcome, WizardState, WizardStep } from './lib'; +import type { OnboardingSite, SettleOutcome, WizardState, WizardStep } from './lib'; import type { SetupModuleResult } from './use-setup-modules'; import type { MouseEvent } from 'react'; @@ -92,6 +93,8 @@ type WizardProps = { exitUrl: string; // Where the rail's control lands: out of Jetpack entirely, back to wp-admin. dashboardUrl: string; + // What the page knows about this site, for the panel's portrait. + site?: OnboardingSite; }; /** @@ -106,9 +109,10 @@ type WizardProps = { * @param props - The component props. * @param props.exitUrl - The My Jetpack URL the footer's skip leads to. * @param props.dashboardUrl - The wp-admin URL the rail's control leads to. + * @param props.site - What the page knows about this site. * @return The rendered wizard. */ -export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { +export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { const steps = wizardSteps(); // Connecting leaves wp-admin for WordPress.com and comes back to a fresh page, @@ -286,6 +290,7 @@ export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { const showConnected = justConnected && arrivedOn.current === step; const isFeatures = meta.kind === 'features'; const isFinish = meta.kind === 'finish'; + const showPortrait = meta.kind === 'question' && hasPortrait( site ); /* * Continue is in the same place on every step, so the second half of a double @@ -585,13 +590,19 @@ export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { /> { /* - * Drawn in on every step, and keyed so it draws again on each one: - * the animation is CSS, so replaying it means a fresh element. The - * prototype keeps this to its start screen because its other panels - * carry a stage the art would compete with. Ours carry the art, so - * there is nothing for it to compete with. + * The site takes the panel on the one step that asks about it, as + * the prototype does: that screen says what we read the site as and + * asks whether it is right, so the site is the subject of it. + * + * Everywhere else the art is the subject. It is drawn in on each of + * those steps and keyed so the draw replays: the animation is CSS, + * so a repeat means a fresh element. */ } - + { showPortrait ? ( + + ) : ( + + ) } { /* Keyed by step so each line rises again when the copy is swapped. */ }

{ /* diff --git a/projects/packages/my-jetpack/changelog/add-my-jetpack-onboarding-site-portrait b/projects/packages/my-jetpack/changelog/add-my-jetpack-onboarding-site-portrait new file mode 100644 index 000000000000..07aae04d8ed5 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/add-my-jetpack-onboarding-site-portrait @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Onboarding: show the site's own homepage and what is on it while asking what the site is for. diff --git a/projects/packages/my-jetpack/global.d.ts b/projects/packages/my-jetpack/global.d.ts index cba4a236ca50..8c08fb79d2b9 100644 --- a/projects/packages/my-jetpack/global.d.ts +++ b/projects/packages/my-jetpack/global.d.ts @@ -468,6 +468,13 @@ type OnboardingWizardState = { exitUrl: string; // Where leaving Jetpack altogether lands: wp-admin's own dashboard. dashboardUrl: string; + // What the panel can show about this site, and whether it may photograph it. + site: { + url: string; + domain: string; + canPhotograph: boolean; + counts: { posts: number; pages: number; media: number; plugins: number }; + }; }; type MainFeaturePluginStatus = 'not-installed' | 'inactive' | 'active'; diff --git a/projects/packages/my-jetpack/src/class-initializer.php b/projects/packages/my-jetpack/src/class-initializer.php index 6c65ac850974..87ee6985a1e9 100644 --- a/projects/packages/my-jetpack/src/class-initializer.php +++ b/projects/packages/my-jetpack/src/class-initializer.php @@ -612,9 +612,72 @@ public static function get_onboarding_wizard_state() { 'exitUrl' => admin_url( 'admin.php?page=my-jetpack' ), // Where leaving Jetpack altogether lands: wp-admin's own dashboard. 'dashboardUrl' => admin_url(), + 'site' => self::get_onboarding_site_portrait(), ); } + /** + * What the wizard's panel can show about this site, and whether it may. + * + * Carried on the page rather than fetched: these are four cached core counts + * and two option reads, and a request for them would arrive after the panel + * had already decided what to draw. + * + * @internal Not part of the package's public API. + * + * @return array{url: string, domain: string, canPhotograph: bool, counts: array} + */ + public static function get_onboarding_site_portrait() { + $home = home_url(); + + $counts = array( + 'posts' => (int) wp_count_posts( 'post' )->publish, + 'pages' => (int) wp_count_posts( 'page' )->publish, + 'media' => array_sum( (array) wp_count_attachments() ), + // What is installed, not what is running: the number people recognise + // from the Plugins screen. + 'plugins' => count( Plugins_Installer::get_plugins() ), + ); + + return array( + 'url' => $home, + 'domain' => wp_parse_url( $home, PHP_URL_HOST ), + 'canPhotograph' => self::can_photograph_site(), + 'counts' => $counts, + ); + } + + /** + * Whether WordPress.com's screenshot service could reach this site. + * + * Asked before the request rather than judged after it, because a failure does + * not come back as one: an unreachable site returns HTTP 200 and a JPEG of a + * red 403 card, and a domain that does not resolve returns a JPEG of a yellow + * 404. Neither the status nor the content type can tell those from a homepage, + * so the only safe guard is to know the answer in advance. + * + * A connected site is reachable almost by definition: the connection itself is + * WordPress.com fetching this host. A private or coming-soon site answers with + * its splash rather than its homepage, and a local one answers nobody. + * + * @internal Not part of the package's public API. + * + * @return bool + */ + private static function can_photograph_site() { + $status = new Status(); + + if ( $status->is_offline_mode() || $status->is_local_site() ) { + return false; + } + + if ( ! (int) get_option( 'blog_public' ) ) { + return false; + } + + return ( new Connection_Manager() )->is_connected(); + } + /** * Get the slug and label that replace the Products tab, for links to it. * diff --git a/projects/plugins/jetpack/changelog/add-my-jetpack-onboarding-site-portrait b/projects/plugins/jetpack/changelog/add-my-jetpack-onboarding-site-portrait new file mode 100644 index 000000000000..ad0fe4888b57 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-my-jetpack-onboarding-site-portrait @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +My Jetpack: show the site's own homepage and what is on it during setup. From 7fe255e59f813a833145058de5e31b8774cf0a59 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Sun, 27 Sep 2026 07:54:24 -0400 Subject: [PATCH 02/15] My Jetpack: stop the screenshot poll adding its own wait to the render Measured against the live service on pages it had not seen: 5.0, 5.4 and 6.5 seconds to a picture. The poll ran on a flat 2.5s interval, so a picture ready at 5.4s was not noticed until 7.5s and up to 2.5s of the wait was ours rather than the service's. The polls are 1s apart while the render is plausibly finishing and 2.5s apart afterwards, when they are only there for the slow case, with a 25s deadline. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../onboarding-screen/wizard/use-site-shot.ts | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts index d2b98715681f..9d9b1924eb60 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts @@ -11,12 +11,16 @@ const WIDTH = 880; const HEIGHT = 550; /* - * The first requests answer with a placeholder while the page is rendered, and - * a later one answers with the picture. Measured against the live service: the - * type flipped on the third poll at this interval. + * Measured against the live service on pages it had not seen: 5.0, 5.4 and 6.5 + * seconds to a picture. A single interval wide enough to cover a slow render + * adds its own wait to every fast one, so the polls are close together while + * the render is plausibly finishing and further apart afterwards, when they are + * only there for the slow case. */ -const RETRY_MS = 2500; -const MAX_TRIES = 10; +const RETRY_MS = 1000; +const SLOW_RETRY_MS = 2500; +const SLOW_AFTER_MS = 10000; +const GIVE_UP_MS = 25000; /** * The address of this site's homepage as WordPress.com would photograph it. @@ -69,7 +73,7 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string } const src = shotUrl( url ); - let tries = 0; + const began = Date.now(); let timer: ReturnType< typeof setTimeout >; let live = true; @@ -80,8 +84,8 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string const response = await window.fetch( src, { mode: 'cors' } ); done = ( response.headers.get( 'content-type' ) ?? '' ).includes( 'jpeg' ); } catch { - // A network refusal is the same as not ready yet: try again, and stop - // when the tries run out. The panel keeps its artwork either way. + // A network refusal is the same as not ready yet: ask again, and stop + // at the deadline. The panel keeps its artwork either way. } if ( ! live ) { @@ -93,10 +97,10 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string return; } - tries += 1; + const waited = Date.now() - began; - if ( tries < MAX_TRIES ) { - timer = setTimeout( ask, RETRY_MS ); + if ( waited < GIVE_UP_MS ) { + timer = setTimeout( ask, waited < SLOW_AFTER_MS ? RETRY_MS : SLOW_RETRY_MS ); } }; From 7cd54b486cf181cfac42c649eb6153168d594042 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Sun, 27 Sep 2026 08:13:06 -0400 Subject: [PATCH 03/15] My Jetpack: ask for the screenshot while the user is away connecting The request went out when the panel mounted, which is the question step, which is where a connected user opens. The service takes around five seconds on a page it has not seen, so the wait landed entirely on the one screen that shows the picture. It is asked for at the wizard instead. The connect step sends the user to WordPress.com and back through a fresh page load, so on an unconnected site the render happens while they are away and the picture is waiting when they return. That meant dropping the connection requirement from the PHP guard. Connecting does not change whether the world can reach this host, it only proves it, and the proof arrives too late to be useful. The local, offline-mode and blog_public checks are what actually answer the question and they stay. Losing the proof exposes a hole that was already there: a host the service cannot reach is answered with a WordPress.com error card, as HTTP 200 and image/jpeg exactly like a homepage, and we would hang it in the frame and call it their site. Measured against the live service, every unreachable host gets back byte for byte the same card, so the two cards are now recognised by size and thrown away. The size comes from the body, because the service sends content-length on the placeholder and not on the picture. Verified against the live service: an unreachable host stops after two polls and shows counts only, a real page appears in about seven seconds from page load. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/site-portrait.tsx | 5 +- .../wizard/test/site-portrait.test.tsx | 83 +++---------- .../wizard/test/use-site-shot.test.ts | 113 ++++++++++++++++++ .../onboarding-screen/wizard/use-site-shot.ts | 32 ++++- .../onboarding-screen/wizard/wizard.tsx | 12 +- .../my-jetpack/src/class-initializer.php | 26 ++-- 6 files changed, 184 insertions(+), 87 deletions(-) create mode 100644 projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx index e31c366f98bb..6a227dd70a23 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx @@ -4,7 +4,6 @@ import { _n } from '@wordpress/i18n'; import clsx from 'clsx'; import { useEffect, useRef, useState } from 'react'; import styles from './styles.module.scss'; -import { useSiteShot } from './use-site-shot'; import type { OnboardingSite } from './lib'; import type { ReactNode } from 'react'; @@ -205,10 +204,10 @@ function StatRow( { text, value }: { text: string; value: number } ) { * * @param props - The component props. * @param props.site - What the page told us about this site. + * @param props.shot - The homepage screenshot, once the service has one. * @return The rendered portrait. */ -export function SitePortrait( { site }: { site: OnboardingSite } ) { - const shot = useSiteShot( site.url, site.canPhotograph ); +export function SitePortrait( { site, shot }: { site: OnboardingSite; shot: string | null } ) { const stats = statLines( site.counts ); return ( diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx index 6a01310454aa..a9ea9892d273 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx @@ -1,4 +1,4 @@ -import { act, render, screen, waitFor } from '@testing-library/react'; +import { act, render, screen } from '@testing-library/react'; import { useReducedMotion } from '@wordpress/compose'; import { SitePortrait, hasPortrait } from '../site-portrait'; import type { OnboardingSite } from '../lib'; @@ -20,15 +20,8 @@ const site = ( over: Partial< OnboardingSite > = {} ): OnboardingSite => ( { ...over, } ); -const mockFetch = jest.fn(); - -beforeEach( () => { - mockFetch.mockReset(); - window.fetch = mockFetch as unknown as typeof window.fetch; -} ); - -const answers = ( type: string ) => - Promise.resolve( { headers: { get: () => type } } as unknown as Response ); +const show = ( over: Partial< OnboardingSite > = {}, shot: string | null = null ) => + render( ); describe( 'What the portrait is willing to show', () => { it( 'says nothing at all for a site with no picture and no counts', () => { @@ -55,11 +48,7 @@ describe( 'What the portrait is willing to show', () => { * line out is not. */ it( 'leaves out a count of zero rather than reporting it', () => { - mockFetch.mockReturnValue( answers( 'image/gif' ) ); - - render( - - ); + show( { counts: { posts: 4, pages: 0, media: 0, plugins: 2 } } ); expect( screen.getByText( /posts published/ ) ).toBeInTheDocument(); expect( screen.getByText( /plugins installed/ ) ).toBeInTheDocument(); @@ -69,65 +58,26 @@ describe( 'What the portrait is willing to show', () => { // A frame around nothing promises a photograph that will never arrive. it( 'draws no browser window for a site it cannot photograph', () => { - render( ); + show( { canPhotograph: false } ); expect( screen.queryByText( 'example.com' ) ).not.toBeInTheDocument(); - expect( mockFetch ).not.toHaveBeenCalled(); - } ); -} ); - -describe( 'Waiting for the screenshot', () => { - // The picture carries an empty alt on purpose, so `presentation` is the only - // role it has, and the whole portrait is aria-hidden, so it must be asked for. - const picture = () => screen.queryByRole( 'presentation', { hidden: true } ); - - /* - * The service answers 200 with a placeholder while it renders and 200 with the - * picture once it has. The content type is the only thing between them: both - * are 400 by 300, so there is nothing in the pixels to measure. - */ - it( 'shows nothing while the service is still rendering', async () => { - mockFetch.mockReturnValue( answers( 'image/gif' ) ); - - render( ); - - await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); - expect( picture() ).toBeNull(); } ); - it( 'shows the picture once the type says it is one', async () => { - mockFetch.mockReturnValue( answers( 'image/jpeg' ) ); - - render( ); + it( 'hangs the picture in the window once there is one', () => { + show( {}, 'https://s0.wp.com/mshots/v1/x' ); - await waitFor( () => expect( picture() ).not.toBeNull() ); - expect( picture() ).toHaveAttribute( + expect( screen.getByRole( 'presentation', { hidden: true } ) ).toHaveAttribute( 'src', - expect.stringContaining( 'mshots/v1/https%3A%2F%2Fexample.com' ) + 'https://s0.wp.com/mshots/v1/x' ); } ); - // The URL is what the service keys its render on, so it must not vary. - it( 'polls the same address every time', async () => { - mockFetch.mockReturnValue( answers( 'image/gif' ) ); + // The plate is drawn either way, so the stack does not jump when one arrives. + it( 'draws the window before the picture arrives', () => { + show(); - render( ); - - await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); - const asked = mockFetch.mock.calls.map( ( [ url ] ) => url ); - - expect( new Set( asked ).size ).toBe( 1 ); - } ); - - it( 'gives up quietly when the service never answers', async () => { - mockFetch.mockRejectedValue( new Error( 'offline' ) ); - - render( ); - - await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); - expect( picture() ).toBeNull(); - // The counts are still there: the picture is the part that can fail. - expect( screen.getByText( /posts published/ ) ).toBeInTheDocument(); + expect( screen.getByText( 'example.com' ) ).toBeInTheDocument(); + expect( screen.queryByRole( 'presentation', { hidden: true } ) ).not.toBeInTheDocument(); } ); } ); @@ -159,7 +109,6 @@ describe( 'Counting the numeral up', () => { pending = null; clock = 0; jest.useFakeTimers(); - mockFetch.mockReturnValue( answers( 'image/gif' ) ); spies = [ jest .spyOn( window, 'requestAnimationFrame' ) @@ -178,9 +127,7 @@ describe( 'Counting the numeral up', () => { } ); const withPosts = ( posts: number ) => - render( - - ); + show( { counts: { posts, pages: 0, media: 0, plugins: 0 } } ); it( 'shows the real number until the row it sits in starts moving', () => { withPosts( 240 ); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts new file mode 100644 index 000000000000..da152564f1bf --- /dev/null +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts @@ -0,0 +1,113 @@ +import { renderHook, waitFor } from '@testing-library/react'; +import { useSiteShot } from '../use-site-shot'; + +const URL = 'https://example.com'; + +const mockFetch = jest.fn(); + +beforeEach( () => { + mockFetch.mockReset(); + window.fetch = mockFetch as unknown as typeof window.fetch; +} ); + +const answers = ( type: string, size = 95774 ) => + Promise.resolve( { + headers: { get: () => type }, + blob: () => Promise.resolve( { size } ), + } as unknown as Response ); + +const ask = () => renderHook( () => useSiteShot( URL, true ) ); + +describe( 'Waiting for the screenshot', () => { + /* + * The service answers 200 with a placeholder while it renders and 200 with the + * picture once it has. The content type is the only thing between them: both + * are 400 by 300, so there is nothing in the pixels to measure. + */ + it( 'has nothing while the service is still rendering', async () => { + mockFetch.mockReturnValue( answers( 'image/gif' ) ); + + const { result } = ask(); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + expect( result.current ).toBeNull(); + } ); + + it( 'has the picture once the type says it is one', async () => { + mockFetch.mockReturnValue( answers( 'image/jpeg', 95774 ) ); + + const { result } = ask(); + + await waitFor( () => expect( result.current ).not.toBeNull() ); + expect( result.current ).toContain( 'mshots/v1/https%3A%2F%2Fexample.com' ); + } ); + + // The URL is what the service keys its render on, so it must not vary. + it( 'asks the same address every time', async () => { + mockFetch.mockReturnValue( answers( 'image/gif' ) ); + + ask(); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + const asked = mockFetch.mock.calls.map( ( [ url ] ) => url ); + + expect( new Set( asked ).size ).toBe( 1 ); + } ); + + it( 'asks for nothing at all for a site that cannot be photographed', async () => { + renderHook( () => useSiteShot( URL, false ) ); + + await Promise.resolve(); + + expect( mockFetch ).not.toHaveBeenCalled(); + } ); + + it( 'gives up quietly when the service never answers', async () => { + mockFetch.mockRejectedValue( new Error( 'offline' ) ); + + const { result } = ask(); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + expect( result.current ).toBeNull(); + } ); +} ); + +/* + * A host the service cannot reach is answered with a fixed WordPress.com error + * card, as HTTP 200 and `image/jpeg` exactly like a homepage. Showing one would + * tell the user this is what their site looks like. + */ +describe( 'Refusing an error card', () => { + it.each( [ + [ 'the unreachable-host card', 17886 ], + [ 'the local-address card', 18852 ], + ] )( 'never shows %s', async ( _label, bytes ) => { + mockFetch.mockReturnValue( answers( 'image/jpeg', bytes ) ); + + const { result } = ask(); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + expect( result.current ).toBeNull(); + } ); + + // It is the service's final answer, so asking again only gets it back. + it( 'stops asking once a card comes back', async () => { + mockFetch.mockReturnValue( answers( 'image/jpeg', 17886 ) ); + + ask(); + + await waitFor( () => expect( mockFetch ).toHaveBeenCalledTimes( 1 ) ); + await new Promise( resolve => setTimeout( resolve, 1400 ) ); + + expect( mockFetch ).toHaveBeenCalledTimes( 1 ); + } ); + + // A card is recognised by its size, so a picture that is any other size is one. + it( 'shows a picture one byte off a card', async () => { + mockFetch.mockReturnValue( answers( 'image/jpeg', 17887 ) ); + + const { result } = ask(); + + await waitFor( () => expect( result.current ).not.toBeNull() ); + } ); +} ); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts index 9d9b1924eb60..52e7e8ed9942 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts @@ -22,6 +22,18 @@ const SLOW_RETRY_MS = 2500; const SLOW_AFTER_MS = 10000; const GIVE_UP_MS = 25000; +/* + * A host the service cannot reach gets a WordPress.com error card, answered as + * HTTP 200 and `image/jpeg` exactly like a homepage. The cards are fixed images + * and these are their sizes at the dimensions above: measured, every unreachable + * host returning byte for byte the same card as every other. + * + * Second line, not first: `can_photograph_site()` in the PHP already turns away + * the sites we can know about in advance. If WordPress.com ever redraws a card + * this stops matching, and we are back to where we were before it was added. + */ +const ERROR_CARD_BYTES = [ 17886, 18852 ]; + /** * The address of this site's homepage as WordPress.com would photograph it. * @@ -54,7 +66,9 @@ function shotUrl( url: string ): string { * * It is read with `fetch` rather than by loading the image and measuring it. * Measured against the live service, the placeholder and the screenshot are - * both 400 by 300, so there is nothing in the pixels to tell them apart. + * both 400 by 300, so there is nothing in the pixels to tell them apart. The + * same read is what lets an error card be recognised and thrown away; see + * `ERROR_CARD_BYTES`. * * The URL never varies between polls. It is what the service keys its render * on, so a cache-buster would start a new render every time and never finish @@ -79,10 +93,18 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string const ask = async () => { let done = false; + let refused = false; try { const response = await window.fetch( src, { mode: 'cors' } ); - done = ( response.headers.get( 'content-type' ) ?? '' ).includes( 'jpeg' ); + + if ( ( response.headers.get( 'content-type' ) ?? '' ).includes( 'jpeg' ) ) { + // The body rather than `content-length`, which the service sends on + // the placeholder and not on the picture. Read once, on the poll that + // answers with one, and the browser serves the `img` from its cache. + refused = ERROR_CARD_BYTES.includes( ( await response.blob() ).size ); + done = ! refused; + } } catch { // A network refusal is the same as not ready yet: ask again, and stop // at the deadline. The panel keeps its artwork either way. @@ -92,6 +114,12 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string return; } + // An error card is the service's final answer, so asking again only gets + // the same card back. + if ( refused ) { + return; + } + if ( done ) { setReady( src ); return; diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx index 369c24ba8999..437d91b71abf 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx @@ -37,6 +37,7 @@ import styles from './styles.module.scss'; import { useJustConnected } from './use-just-connected'; import { readSavedRun, useSavedRun } from './use-saved-run'; import { useApplySetupModules, useSetupModules } from './use-setup-modules'; +import { useSiteShot } from './use-site-shot'; import type { OnboardingSite, SettleOutcome, WizardState, WizardStep } from './lib'; import type { SetupModuleResult } from './use-setup-modules'; import type { MouseEvent } from 'react'; @@ -179,6 +180,15 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { const justConnected = useJustConnected(); const arrivedOn = useRef< WizardStep | null >( null ); + /* + * Asked for here rather than inside the panel, which is two steps away and + * mounts too late. The service takes five seconds or so on a page it has not + * seen, and the connect step sends the user to WordPress.com and back through + * a fresh page load — so the request goes out now, and the render happens + * while they are away. + */ + const shot = useSiteShot( site?.url, Boolean( site?.canPhotograph ) ); + const titleId = useId(); const panelRef = useRef< HTMLElement >( null ); const hasChangedStep = useRef( false ); @@ -599,7 +609,7 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { * so a repeat means a fresh element. */ } { showPortrait ? ( - + ) : ( ) } diff --git a/projects/packages/my-jetpack/src/class-initializer.php b/projects/packages/my-jetpack/src/class-initializer.php index 87ee6985a1e9..416ea6569e5b 100644 --- a/projects/packages/my-jetpack/src/class-initializer.php +++ b/projects/packages/my-jetpack/src/class-initializer.php @@ -650,15 +650,19 @@ public static function get_onboarding_site_portrait() { /** * Whether WordPress.com's screenshot service could reach this site. * - * Asked before the request rather than judged after it, because a failure does - * not come back as one: an unreachable site returns HTTP 200 and a JPEG of a - * red 403 card, and a domain that does not resolve returns a JPEG of a yellow - * 404. Neither the status nor the content type can tell those from a homepage, - * so the only safe guard is to know the answer in advance. + * Asked before the request because a failure does not come back as one: an + * unreachable host answers HTTP 200 with a JPEG of a WordPress.com error card, + * which no status or content type can tell from a homepage. The front end + * recognises those cards by size and throws them away, but that is the second + * line and not the first. * - * A connected site is reachable almost by definition: the connection itself is - * WordPress.com fetching this host. A private or coming-soon site answers with - * its splash rather than its homepage, and a local one answers nobody. + * A private or coming-soon site answers with its splash rather than its + * homepage, and a local one answers nobody. + * + * Deliberately does NOT require a connection. Connecting does not change + * whether the world can reach this host, it only proves it, and the proof + * arrives too late: the wizard asks for the picture while the user is away at + * WordPress.com, so that it is waiting for them when they come back. * * @internal Not part of the package's public API. * @@ -671,11 +675,7 @@ private static function can_photograph_site() { return false; } - if ( ! (int) get_option( 'blog_public' ) ) { - return false; - } - - return ( new Connection_Manager() )->is_connected(); + return (bool) (int) get_option( 'blog_public' ); } /** From 113ed221a7625e9513f01aab7945b28d4a0244ca Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Sun, 27 Sep 2026 09:50:38 -0400 Subject: [PATCH 04/15] My Jetpack: fix what three red teams found in the site portrait Never photograph a private or coming-soon site. blog_public is not a boolean: 0 asks search engines away, and -1 and below, which More Privacy Options adds on multisite, mean private. Every one of them cast to true, so a private site was sent to the screenshot service and its splash hung in a frame captioned with its own domain. Leave trashed uploads out of the media count. wp_count_attachments returns per-mime-type counts plus a trash total, and summing the lot reported someone's emptied uploads back to them as their library. Add a filter, for hosts serving sites that are public but unreachable from outside. Nothing but the local and offline checks stood between an intranet hostname and a third party. Only count any of it during the takeover. The whole portrait was computed and printed into every My Jetpack page load, and counting attachments groups by a column no index covers. Ask for the picture from the admin head as well, so the render starts at head-parse time rather than when the bundle boots, and so the picture is already downloaded on the way back from connecting. Both sides now assert the whole URL, because a drift between them would warm a render nothing reads. In the poll: reset the picture when the address changes, so a shot of the previous site cannot survive; stop on a refusal, which was read as a slow render and polled for the full twenty-five seconds; abort the request in flight; and read readiness from the redirect rather than the content type, which also drops the placeholder download from every poll. The error-card byte sizes now sit in one object with the dimensions they were measured at. They are a function of those dimensions and nothing said so, so widening the panel would have put a WordPress.com error card on screen as someone's homepage. Numerals are filled in by sprintf next to the plural they belong to. A plain replace left a positional placeholder on screen with no number in it, which is a legal and common way for a translator to write a lone number. Turning motion down part way through a count no longer strands the numeral on whatever it had reached. Eight mutations of the poll, four of the PHP and three of the component were each confirmed to fail a test before being restored. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/site-portrait.tsx | 83 +++--- .../wizard/styles.module.scss | 4 +- .../wizard/test/site-portrait.test.tsx | 90 ++++++- .../wizard/test/use-site-shot.test.ts | 159 ++++++++--- .../onboarding-screen/wizard/use-site-shot.ts | 147 +++++----- ...ix-my-jetpack-onboarding-portrait-red-team | 4 + .../my-jetpack/src/class-initializer.php | 122 +++++++-- .../php/Onboarding_Site_Portrait_Test.php | 250 ++++++++++++++++++ ...ix-my-jetpack-onboarding-portrait-red-team | 4 + 9 files changed, 710 insertions(+), 153 deletions(-) create mode 100644 projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team create mode 100644 projects/packages/my-jetpack/tests/php/Onboarding_Site_Portrait_Test.php create mode 100644 projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx index 6a227dd70a23..24ddaa0b0a48 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx @@ -1,9 +1,9 @@ -import { useReducedMotion } from '@wordpress/compose'; import { createInterpolateElement } from '@wordpress/element'; -import { _n } from '@wordpress/i18n'; +import { _n, sprintf } from '@wordpress/i18n'; import clsx from 'clsx'; import { useEffect, useRef, useState } from 'react'; import styles from './styles.module.scss'; +import { useReducedMotion } from './use-reduced-motion'; import type { OnboardingSite } from './lib'; import type { ReactNode } from 'react'; @@ -62,42 +62,54 @@ function statLines( counts: OnboardingSite[ 'counts' ] ) { const lines = [ { value: counts.posts, - /* translators: %d is how many posts the site has published. */ - text: _n( - '%d post published', - '%d posts published', - counts.posts, - 'jetpack-my-jetpack' + text: sprintf( + /* translators: %d is how many posts the site has published. */ + _n( + '%d post published', + '%d posts published', + counts.posts, + 'jetpack-my-jetpack' + ), + counts.posts ), }, { value: counts.pages, - /* translators: %d is how many pages the site has published. */ - text: _n( - '%d page published', - '%d pages published', - counts.pages, - 'jetpack-my-jetpack' + text: sprintf( + /* translators: %d is how many pages the site has published. */ + _n( + '%d page published', + '%d pages published', + counts.pages, + 'jetpack-my-jetpack' + ), + counts.pages ), }, { value: counts.media, - /* translators: %d is how many files are in the site's media library. */ - text: _n( - '%d file in your media library', - '%d files in your media library', - counts.media, - 'jetpack-my-jetpack' + text: sprintf( + /* translators: %d is how many files are in the site's media library. */ + _n( + '%d file in your media library', + '%d files in your media library', + counts.media, + 'jetpack-my-jetpack' + ), + counts.media ), }, { value: counts.plugins, - /* translators: %d is how many plugins the site has installed. */ - text: _n( - '%d plugin installed', - '%d plugins installed', - counts.plugins, - 'jetpack-my-jetpack' + text: sprintf( + /* translators: %d is how many plugins the site has installed. */ + _n( + '%d plugin installed', + '%d plugins installed', + counts.plugins, + 'jetpack-my-jetpack' + ), + counts.plugins ), }, ]; @@ -126,13 +138,13 @@ function StatNumeral( { at, children }: { at: number | null; children?: ReactNod /** * One count, as a sentence, with the numeral counting up to it. * - * The count waits for the row's own entrance delay, which it reads off the + * The count waits for the rows' entrance delay, which it reads off the * stylesheet rather than repeating here: written as a constant it would finish - * behind a row that had not faded in yet the first time the stagger changed. + * behind rows that had not faded in yet the first time the delay changed. * * @param props - The component props. - * @param props.text - The translated sentence, with `%d` still in it. - * @param props.value - What to put in place of `%d`. + * @param props.text - The translated sentence with the number already in it. + * @param props.value - The number, which the count-up needs on its own. * @return The rendered row. */ function StatRow( { text, value }: { text: string; value: number } ) { @@ -142,6 +154,9 @@ function StatRow( { text, value }: { text: string; value: number } ) { useEffect( () => { if ( reduced || value < COUNT_FLOOR || ! row.current ) { + // Back to the real number. Turning motion down part way through a count + // otherwise strands the numeral on whatever it had reached. + setAt( null ); return; } @@ -155,8 +170,8 @@ function StatRow( { text, value }: { text: string; value: number } ) { const through = Math.min( 1, ( now - began ) / COUNT_MS ); - // Back to the translated numeral at the end rather than to our own - // rendering of the same number, which would not be localized. + // Back to the numeral the translation produced, rather than leaving our + // own rendering of it on screen. if ( through >= 1 ) { setAt( null ); return; @@ -179,9 +194,7 @@ function StatRow( { text, value }: { text: string; value: number } ) { return (

- { createInterpolateElement( text.replace( '%d', String( value ) ), { - b: , - } ) } + { createInterpolateElement( text, { b: } ) }

); } diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index 7a9f21e1f9eb..df2e5be163dd 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -1103,14 +1103,14 @@ $rail-row-min-height: 40px; } .portrait-back--far { - top: -$portrait-back-far-rise; + inset-block-start: -$portrait-back-far-rise; inline-size: $portrait-back-far-width; block-size: 150px; animation-delay: $wave-base; } .portrait-back--near { - top: -$portrait-back-near-rise; + inset-block-start: -$portrait-back-near-rise; inline-size: $portrait-back-near-width; block-size: 200px; background: rgba(252, 252, 252, 0.8); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx index a9ea9892d273..f1c0ad97e7cd 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx @@ -1,15 +1,17 @@ import { act, render, screen } from '@testing-library/react'; -import { useReducedMotion } from '@wordpress/compose'; +import { _n } from '@wordpress/i18n'; import { SitePortrait, hasPortrait } from '../site-portrait'; +import { useReducedMotion } from '../use-reduced-motion'; import type { OnboardingSite } from '../lib'; -/* - * The hook caches one media query list per window, so a `matchMedia` stub put - * in place after the first render of the file never reaches it. - */ -jest.mock( '@wordpress/compose', () => ( { - ...jest.requireActual( '@wordpress/compose' ), - useReducedMotion: jest.fn( () => false ), +// Mocked rather than driven through `matchMedia`, so a test can turn it on part +// way through a count. +jest.mock( '../use-reduced-motion', () => ( { useReducedMotion: jest.fn( () => false ) } ) ); + +// The module's exports are frozen, so a translation can only be swapped here. +jest.mock( '@wordpress/i18n', () => ( { + ...jest.requireActual( '@wordpress/i18n' ), + _n: jest.fn( jest.requireActual( '@wordpress/i18n' )._n ), } ) ); const site = ( over: Partial< OnboardingSite > = {} ): OnboardingSite => ( { @@ -23,6 +25,8 @@ const site = ( over: Partial< OnboardingSite > = {} ): OnboardingSite => ( { const show = ( over: Partial< OnboardingSite > = {}, shot: string | null = null ) => render( ); +const posts = ( n: number ) => ( { posts: n, pages: 0, media: 0, plugins: 0 } ); + describe( 'What the portrait is willing to show', () => { it( 'says nothing at all for a site with no picture and no counts', () => { expect( @@ -63,6 +67,19 @@ describe( 'What the portrait is willing to show', () => { expect( screen.queryByText( 'example.com' ) ).not.toBeInTheDocument(); } ); + /* + * Every fact in it is decorative: the question is on the left, the picture is + * of a site the reader is sitting inside, and read aloud the counts are four + * numbers with no bearing on the answer. + */ + it( 'is hidden from assistive technology in full', () => { + show( {}, 'https://s0.wp.com/mshots/v1/x' ); + + // Present in the page, absent from the accessibility tree. + expect( screen.getByRole( 'presentation', { hidden: true } ) ).toBeInTheDocument(); + expect( screen.queryByRole( 'presentation' ) ).not.toBeInTheDocument(); + } ); + it( 'hangs the picture in the window once there is one', () => { show( {}, 'https://s0.wp.com/mshots/v1/x' ); @@ -126,8 +143,7 @@ describe( 'Counting the numeral up', () => { spies.forEach( spy => spy.mockRestore() ); } ); - const withPosts = ( posts: number ) => - show( { counts: { posts, pages: 0, media: 0, plugins: 0 } } ); + const withPosts = ( n: number ) => show( { counts: posts( n ) } ); it( 'shows the real number until the row it sits in starts moving', () => { withPosts( 240 ); @@ -188,4 +204,58 @@ describe( 'Counting the numeral up', () => { expect( pending ).toBeNull(); expect( row( /posts published/ ) ).toBe( '240 posts published' ); } ); + + /* + * Turning motion down part way through used to strand the numeral on whatever + * it had reached, and nothing moved it again. + */ + it( 'puts the real number back when motion is turned down mid-count', () => { + const { rerender } = withPosts( 240 ); + begin(); + frame( 0 ); + frame( 300 ); + + expect( row( /posts published/ ) ).not.toBe( '240 posts published' ); + + jest.mocked( useReducedMotion ).mockReturnValue( true ); + rerender( ); + + expect( row( /posts published/ ) ).toBe( '240 posts published' ); + } ); + + /* + * jsdom reports no delay, so the stylesheet is stubbed: without this the whole + * mechanic could be replaced by a zero and every test would still pass. + */ + it( 'waits for the delay the stylesheet gives the row', () => { + jest + .spyOn( window, 'getComputedStyle' ) + .mockReturnValue( { animationDelay: '0.34s' } as unknown as CSSStyleDeclaration ); + + withPosts( 240 ); + + act( () => jest.advanceTimersByTime( 339 ) ); + expect( pending ).toBeNull(); + + act( () => jest.advanceTimersByTime( 1 ) ); + expect( pending ).not.toBeNull(); + } ); +} ); + +/* + * `%1$d` is a legal and common way for a translator to write a lone `%d`, and a + * plain string replace leaves it on screen with no number in it at all. + */ +describe( 'Numbers a translator may have moved', () => { + it( 'fills in a positional placeholder', () => { + jest + .mocked( _n ) + .mockReturnValue( '%1$d posts published' as unknown as ReturnType< typeof _n > ); + + show( { counts: posts( 240 ) } ); + + expect( screen.getByText( /posts published/, { selector: 'p' } ) ).toHaveTextContent( + '240 posts published' + ); + } ); } ); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts index da152564f1bf..9b4e5e349343 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/use-site-shot.test.ts @@ -2,6 +2,8 @@ import { renderHook, waitFor } from '@testing-library/react'; import { useSiteShot } from '../use-site-shot'; const URL = 'https://example.com'; +const CARD = 17886; +const PICTURE = 95774; const mockFetch = jest.fn(); @@ -10,54 +12,87 @@ beforeEach( () => { window.fetch = mockFetch as unknown as typeof window.fetch; } ); -const answers = ( type: string, size = 95774 ) => +/* + * Shaped like what the service really sends, because the difference is the whole + * subject: a render in progress is a 307 the request is told not to follow, and + * anything else is an answer. + */ +const rendering = () => + Promise.resolve( { type: 'opaqueredirect', status: 0, ok: false } as Response ); + +const answers = ( size: number, status = 200 ) => Promise.resolve( { - headers: { get: () => type }, - blob: () => Promise.resolve( { size } ), + type: 'cors', + status, + ok: status >= 200 && status < 300, + blob: () => Promise.resolve( new Blob( [ new Uint8Array( size ) ] ) ), } as unknown as Response ); -const ask = () => renderHook( () => useSiteShot( URL, true ) ); +const ask = ( url: string | undefined = URL, allowed = true ) => + renderHook( + ( props: { url?: string; allowed: boolean } ) => useSiteShot( props.url, props.allowed ), + { + initialProps: { url, allowed }, + } + ); + +// Lets the poll's promise chain run without leaning on a timer. +const settle = () => + waitFor( () => expect( mockFetch ).toHaveBeenCalled() ).then( + () => new Promise( r => setTimeout( r, 0 ) ) + ); describe( 'Waiting for the screenshot', () => { - /* - * The service answers 200 with a placeholder while it renders and 200 with the - * picture once it has. The content type is the only thing between them: both - * are 400 by 300, so there is nothing in the pixels to measure. - */ it( 'has nothing while the service is still rendering', async () => { - mockFetch.mockReturnValue( answers( 'image/gif' ) ); + mockFetch.mockReturnValue( rendering() ); const { result } = ask(); - await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + await settle(); expect( result.current ).toBeNull(); } ); - it( 'has the picture once the type says it is one', async () => { - mockFetch.mockReturnValue( answers( 'image/jpeg', 95774 ) ); + it( 'has the picture once the service answers with one', async () => { + mockFetch.mockReturnValue( answers( PICTURE ) ); const { result } = ask(); await waitFor( () => expect( result.current ).not.toBeNull() ); - expect( result.current ).toContain( 'mshots/v1/https%3A%2F%2Fexample.com' ); + /* + * The whole address, and the same one again in the PHP test, because the + * head preload has to ask for exactly this picture. A drift on either side + * warms a render nothing then reads and nothing else would notice. + */ + expect( result.current ).toBe( + 'https://s0.wp.com/mshots/v1/https%3A%2F%2Fexample.com?vpw=1600&vph=1600&w=880&h=550&scale=2' + ); + } ); + + it( 'keeps asking until one arrives', async () => { + mockFetch.mockReturnValueOnce( rendering() ).mockReturnValue( answers( PICTURE ) ); + + const { result } = ask(); + + await waitFor( () => expect( result.current ).not.toBeNull(), { timeout: 4000 } ); + expect( mockFetch.mock.calls.length ).toBeGreaterThan( 1 ); } ); // The URL is what the service keys its render on, so it must not vary. it( 'asks the same address every time', async () => { - mockFetch.mockReturnValue( answers( 'image/gif' ) ); + mockFetch.mockReturnValue( rendering() ); ask(); - await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + await waitFor( () => expect( mockFetch ).toHaveBeenCalledTimes( 2 ), { timeout: 4000 } ); const asked = mockFetch.mock.calls.map( ( [ url ] ) => url ); expect( new Set( asked ).size ).toBe( 1 ); } ); it( 'asks for nothing at all for a site that cannot be photographed', async () => { - renderHook( () => useSiteShot( URL, false ) ); + ask( URL, false ); - await Promise.resolve(); + await new Promise( resolve => setTimeout( resolve, 0 ) ); expect( mockFetch ).not.toHaveBeenCalled(); } ); @@ -67,47 +102,109 @@ describe( 'Waiting for the screenshot', () => { const { result } = ask(); + await settle(); + expect( result.current ).toBeNull(); + } ); + + it( 'stops asking when it is taken off the page', async () => { + mockFetch.mockReturnValue( rendering() ); + + const { unmount } = ask(); + + await settle(); + unmount(); + const asked = mockFetch.mock.calls.length; + await new Promise( resolve => setTimeout( resolve, 1400 ) ); + + expect( mockFetch ).toHaveBeenCalledTimes( asked ); + } ); + + /* + * Aborting the request is not enough on its own: an abort lands in the same + * catch as a flaky network, which is a reason to ask again. + */ + it( 'does not start again when it is taken off the page mid-request', async () => { + let answer: ( response: Response ) => void = () => {}; + mockFetch.mockReturnValue( new Promise< Response >( resolve => ( answer = resolve ) ) ); + + const { unmount } = ask(); + await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + unmount(); + answer( await rendering() ); + await new Promise( resolve => setTimeout( resolve, 1400 ) ); + + expect( mockFetch ).toHaveBeenCalledTimes( 1 ); + } ); + + // A picture of the previous site is worse than no picture. + it( 'drops the picture when the address changes', async () => { + mockFetch.mockReturnValue( answers( PICTURE ) ); + + const { result, rerender } = ask(); + + await waitFor( () => expect( result.current ).not.toBeNull() ); + + mockFetch.mockReturnValue( rendering() ); + rerender( { url: 'https://elsewhere.example', allowed: true } ); + expect( result.current ).toBeNull(); + await settle(); } ); } ); /* * A host the service cannot reach is answered with a fixed WordPress.com error - * card, as HTTP 200 and `image/jpeg` exactly like a homepage. Showing one would - * tell the user this is what their site looks like. + * card, as HTTP 200 and a real JPEG at the full size, exactly like a homepage. + * Showing one would tell the reader this is what their site looks like. */ -describe( 'Refusing an error card', () => { +describe( 'Refusing an answer that is not a homepage', () => { it.each( [ [ 'the unreachable-host card', 17886 ], [ 'the local-address card', 18852 ], ] )( 'never shows %s', async ( _label, bytes ) => { - mockFetch.mockReturnValue( answers( 'image/jpeg', bytes ) ); + mockFetch.mockReturnValue( answers( bytes ) ); const { result } = ask(); - await waitFor( () => expect( mockFetch ).toHaveBeenCalled() ); + await settle(); expect( result.current ).toBeNull(); } ); - // It is the service's final answer, so asking again only gets it back. - it( 'stops asking once a card comes back', async () => { - mockFetch.mockReturnValue( answers( 'image/jpeg', 17886 ) ); + // A card is recognised by its size, so a picture of any other size is one. + it( 'shows a picture one byte off a card', async () => { + mockFetch.mockReturnValue( answers( CARD + 1 ) ); + + const { result } = ask(); + + await waitFor( () => expect( result.current ).not.toBeNull() ); + } ); + + it.each( [ + { label: 'a card', bytes: CARD, status: 200 }, + { label: 'a refusal', bytes: PICTURE, status: 403 }, + ] )( 'stops asking once $label comes back', async ( { bytes, status } ) => { + mockFetch.mockReturnValue( answers( bytes, status ) ); ask(); - await waitFor( () => expect( mockFetch ).toHaveBeenCalledTimes( 1 ) ); + await settle(); await new Promise( resolve => setTimeout( resolve, 1400 ) ); expect( mockFetch ).toHaveBeenCalledTimes( 1 ); } ); - // A card is recognised by its size, so a picture that is any other size is one. - it( 'shows a picture one byte off a card', async () => { - mockFetch.mockReturnValue( answers( 'image/jpeg', 17887 ) ); + /* + * The edge answers 403 for a while during an outage. Treated as a slow render + * that is sixteen requests per wizard with a guaranteed empty result. + */ + it( 'does not poll out the clock against a refusal', async () => { + mockFetch.mockReturnValue( answers( PICTURE, 500 ) ); const { result } = ask(); - await waitFor( () => expect( result.current ).not.toBeNull() ); + await settle(); + expect( result.current ).toBeNull(); + expect( mockFetch ).toHaveBeenCalledTimes( 1 ); } ); } ); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts index 52e7e8ed9942..47eb68c035f8 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-site-shot.ts @@ -2,38 +2,44 @@ import { useEffect, useState } from 'react'; /* * WordPress.com's screenshot service, the same one Calypso uses for importers - * and migration previews. `vpw`/`vph` are the viewport it renders at, `w`/`h` - * the image it returns, and `scale` 2 asks for retina. + * and migration previews. `vpw`/`vph` are the viewport it renders the page at, + * `w`/`h` the image it hands back, and `scale` the device pixel ratio it renders + * at — the returned image is `w` by `h` either way. */ const MSHOTS = 'https://s0.wp.com/mshots/v1/'; const VIEWPORT = 1600; -const WIDTH = 880; -const HEIGHT = 550; + +/* + * The picture we ask for, and the two error cards as encoded AT THAT SIZE. + * + * One object because the byte counts are a function of the dimensions above them + * and nothing else would say so. Measured against the live service, the same + * unreachable host answers with 7156 bytes at 440 by 275 and 27013 at 1760 by + * 1100. Change a dimension without re-measuring and the cards stop being + * recognised, which puts a WordPress.com error card on screen inside a browser + * frame captioned with the reader's own domain. + * + * They cannot be re-measured from a terminal: the edge answers a plain HTTP + * client 403 for any render it does not already hold. It takes a real browser. + */ +const SHOT = { + width: 880, + height: 550, + errorCardBytes: [ 17886, 18852 ] as readonly number[], +} as const; /* * Measured against the live service on pages it had not seen: 5.0, 5.4 and 6.5 * seconds to a picture. A single interval wide enough to cover a slow render - * adds its own wait to every fast one, so the polls are close together while - * the render is plausibly finishing and further apart afterwards, when they are - * only there for the slow case. + * adds its own wait to every fast one, so the polls are close together while the + * render is plausibly finishing and further apart afterwards, when they are only + * there for the slow case. */ const RETRY_MS = 1000; const SLOW_RETRY_MS = 2500; const SLOW_AFTER_MS = 10000; const GIVE_UP_MS = 25000; -/* - * A host the service cannot reach gets a WordPress.com error card, answered as - * HTTP 200 and `image/jpeg` exactly like a homepage. The cards are fixed images - * and these are their sizes at the dimensions above: measured, every unreachable - * host returning byte for byte the same card as every other. - * - * Second line, not first: `can_photograph_site()` in the PHP already turns away - * the sites we can know about in advance. If WordPress.com ever redraws a card - * this stops matching, and we are back to where we were before it was added. - */ -const ERROR_CARD_BYTES = [ 17886, 18852 ]; - /** * The address of this site's homepage as WordPress.com would photograph it. * @@ -44,35 +50,72 @@ function shotUrl( url: string ): string { const query = new URLSearchParams( { vpw: String( VIEWPORT ), vph: String( VIEWPORT ), - w: String( WIDTH ), - h: String( HEIGHT ), + w: String( SHOT.width ), + h: String( SHOT.height ), scale: '2', } ); return `${ MSHOTS }${ encodeURIComponent( url ) }?${ query }`; } +/** What one poll learned: the picture, keep asking, or stop asking. */ +type Answer = 'ready' | 'wait' | 'stop'; + +/** + * Ask once. + * + * @param src - The screenshot URL. + * @param signal - Aborts the request when the caller goes away. + * @return What the service said. + */ +async function askOnce( src: string, signal: AbortSignal ): Promise< Answer > { + try { + /* + * `manual`, so a poll during the render costs a redirect rather than the + * placeholder behind it. While the page is being rendered the service + * answers 307 to a placeholder at its own address, which arrives here as an + * opaque redirect; once rendered it answers the picture directly. + */ + const response = await window.fetch( src, { mode: 'cors', redirect: 'manual', signal } ); + + if ( response.type === 'opaqueredirect' ) { + return 'wait'; + } + + // A refusal is an answer, not a slow render, and asking again only gets it + // back. Calypso's own helper stops on a 4xx too. + if ( ! response.ok ) { + return 'stop'; + } + + return SHOT.errorCardBytes.includes( ( await response.blob() ).size ) ? 'stop' : 'ready'; + } catch { + // A network refusal is the same as not ready yet. The panel keeps its + // artwork either way. + return 'wait'; + } +} + /** * A photograph of this site's homepage, once there is one. * - * Null until the service has a real picture, and null for good if it never - * does. Nothing waits on this: the panel draws either way and the picture - * arrives into it, or does not. + * Null until the service has a real picture, and null for good if it never does. + * Nothing waits on this: the panel draws either way and the picture arrives into + * it, or it does not. * * The polling is the awkward part and it is not ours. There is no callback and - * no status: the same URL answers 200 with `image/gif` while the page is being - * rendered and 200 with `image/jpeg` once it has been, so the content type is - * the only thing that separates them. Calypso's own helper does the same. + * no status: the same URL answers a redirect to a placeholder while the page is + * being rendered and the picture once it has been. * - * It is read with `fetch` rather than by loading the image and measuring it. - * Measured against the live service, the placeholder and the screenshot are - * both 400 by 300, so there is nothing in the pixels to tell them apart. The - * same read is what lets an error card be recognised and thrown away; see - * `ERROR_CARD_BYTES`. + * It is read with `fetch` rather than by loading the image, because a host the + * service cannot reach is answered with an error card — HTTP 200 and a real + * JPEG at the full requested size, indistinguishable from a homepage by + * anything but its contents. See `SHOT`. * - * The URL never varies between polls. It is what the service keys its render - * on, so a cache-buster would start a new render every time and never finish - * one. + * The URL never varies between polls. It is what the service keys its render on, + * so a cache-buster would start a new render every time and never finish one. + * Re-asking the same address is not served from cache because the redirect it + * answers with carries `no-store`. * * @param url - The site's own URL, or undefined to ask for nothing. * @param allowed - Whether this site can be photographed at all; see the PHP. @@ -82,45 +125,28 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string const [ ready, setReady ] = useState< string | null >( null ); useEffect( () => { + // Whatever is held belongs to the previous address, and a stale picture of + // a different site is worse than none. + setReady( null ); + if ( ! url || ! allowed ) { return; } const src = shotUrl( url ); const began = Date.now(); + const stopping = new AbortController(); let timer: ReturnType< typeof setTimeout >; let live = true; const ask = async () => { - let done = false; - let refused = false; - - try { - const response = await window.fetch( src, { mode: 'cors' } ); - - if ( ( response.headers.get( 'content-type' ) ?? '' ).includes( 'jpeg' ) ) { - // The body rather than `content-length`, which the service sends on - // the placeholder and not on the picture. Read once, on the poll that - // answers with one, and the browser serves the `img` from its cache. - refused = ERROR_CARD_BYTES.includes( ( await response.blob() ).size ); - done = ! refused; - } - } catch { - // A network refusal is the same as not ready yet: ask again, and stop - // at the deadline. The panel keeps its artwork either way. - } - - if ( ! live ) { - return; - } + const answer = await askOnce( src, stopping.signal ); - // An error card is the service's final answer, so asking again only gets - // the same card back. - if ( refused ) { + if ( ! live || answer === 'stop' ) { return; } - if ( done ) { + if ( answer === 'ready' ) { setReady( src ); return; } @@ -136,6 +162,7 @@ export function useSiteShot( url: string | undefined, allowed: boolean ): string return () => { live = false; + stopping.abort(); clearTimeout( timer ); }; }, [ url, allowed ] ); diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team new file mode 100644 index 000000000000..ba978f9df67b --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: never photograph a private or coming-soon site, and leave trashed uploads out of the media count. diff --git a/projects/packages/my-jetpack/src/class-initializer.php b/projects/packages/my-jetpack/src/class-initializer.php index 416ea6569e5b..a17fd2cc51a9 100644 --- a/projects/packages/my-jetpack/src/class-initializer.php +++ b/projects/packages/my-jetpack/src/class-initializer.php @@ -170,6 +170,8 @@ public static function init() { */ add_action( 'admin_init', array( __CLASS__, 'maybe_redirect_to_onboarding' ) ); + add_action( 'admin_head', array( __CLASS__, 'preload_onboarding_site_shot' ) ); + // Nothing else gets to talk over the takeover. See both methods for why it // takes two hooks rather than one. add_action( 'in_admin_header', array( __CLASS__, 'silence_onboarding_notices' ), PHP_INT_MAX ); @@ -612,16 +614,17 @@ public static function get_onboarding_wizard_state() { 'exitUrl' => admin_url( 'admin.php?page=my-jetpack' ), // Where leaving Jetpack altogether lands: wp-admin's own dashboard. 'dashboardUrl' => admin_url(), - 'site' => self::get_onboarding_site_portrait(), + // Only when the wizard is the page. Counting attachments groups by a + // column no index covers, and on the ordinary dashboard nothing reads it. + 'site' => self::is_onboarding_takeover() ? self::get_onboarding_site_portrait() : null, ); } /** * What the wizard's panel can show about this site, and whether it may. * - * Carried on the page rather than fetched: these are four cached core counts - * and two option reads, and a request for them would arrive after the panel - * had already decided what to draw. + * Carried on the page rather than fetched: a request for them would arrive + * after the panel had already decided what to draw. * * @internal Not part of the package's public API. * @@ -630,10 +633,15 @@ public static function get_onboarding_wizard_state() { public static function get_onboarding_site_portrait() { $home = home_url(); + // Keyed by mime type, plus a `trash` total that is not in the library. Left + // in, it reports the emptied uploads back to the person who emptied them. + $attachments = (array) wp_count_attachments(); + unset( $attachments['trash'] ); + $counts = array( 'posts' => (int) wp_count_posts( 'post' )->publish, 'pages' => (int) wp_count_posts( 'page' )->publish, - 'media' => array_sum( (array) wp_count_attachments() ), + 'media' => array_sum( $attachments ), // What is installed, not what is running: the number people recognise // from the Plugins screen. 'plugins' => count( Plugins_Installer::get_plugins() ), @@ -641,23 +649,93 @@ public static function get_onboarding_site_portrait() { return array( 'url' => $home, - 'domain' => wp_parse_url( $home, PHP_URL_HOST ), + 'domain' => (string) wp_parse_url( $home, PHP_URL_HOST ), 'canPhotograph' => self::can_photograph_site(), 'counts' => $counts, ); } /** - * Whether WordPress.com's screenshot service could reach this site. + * Ask WordPress.com to start photographing this site before the page's own + * JavaScript can. + * + * The service takes about five seconds on a page it has not seen, and does not + * begin until something asks. Measured on a real admin page, the wizard's + * bundle does not make that first request until roughly two seconds in; a link + * in the head makes it at head-parse time instead. + * + * It also takes the picture off the critical path on the way back. The connect + * step sends the user to WordPress.com and returns them through a fresh page + * load, by which time the render is finished, so this fetch is the download and + * the wizard's own request is served from the cache. + * + * A link rather than a server-side request: WordPress's `blocking => false` is + * not asynchronous, it still waits for the round trip, and its timeout floor is + * a whole second. That second would be paid by exactly the hosts that cannot + * reach WordPress.com anyway. + * + * @since $$next-version$$ + * + * @return void + */ + public static function preload_onboarding_site_shot() { + if ( ! self::is_my_jetpack_admin_request() || ! self::is_onboarding_takeover() ) { + return; + } + + $site = self::get_onboarding_site_portrait(); + + if ( ! $site['canPhotograph'] ) { + return; + } + + printf( + '' . "\n", + esc_url( self::onboarding_site_shot_url( $site['url'] ) ) + ); + } + + /** + * This site's homepage as WordPress.com's screenshot service would photograph it. + * + * Must match what the wizard asks for exactly, or the preload warms a render + * nothing then reads. The JavaScript twin is `shotUrl` in `use-site-shot.ts`, + * where the dimensions are also what the error-card sizes are measured at. + * + * @internal Not part of the package's public API. + * + * @param string $url The site's own URL. + * @return string + */ + private static function onboarding_site_shot_url( $url ) { + return 'https://s0.wp.com/mshots/v1/' . rawurlencode( $url ) . '?' . http_build_query( + array( + 'vpw' => 1600, + 'vph' => 1600, + 'w' => 880, + 'h' => 550, + 'scale' => 2, + ) + ); + } + + /** + * Whether WordPress.com's screenshot service could reach this site, and + * whether what it would find is the site's homepage. * * Asked before the request because a failure does not come back as one: an * unreachable host answers HTTP 200 with a JPEG of a WordPress.com error card, * which no status or content type can tell from a homepage. The front end - * recognises those cards by size and throws them away, but that is the second - * line and not the first. + * recognises those cards and throws them away, but that is the second line and + * not the first. + * + * Private, coming-soon and unlaunched sites all answer with a splash rather + * than a homepage. A local one answers nobody. * - * A private or coming-soon site answers with its splash rather than its - * homepage, and a local one answers nobody. + * `blog_public` is compared to 1 rather than cast, because the option is not a + * boolean: `0` asks search engines to stay away and `-1` and below, which + * "More Privacy Options" adds on multisite, mean private. Every one of those + * casts to true. Nothing but 1 is an invitation to come and look. * * Deliberately does NOT require a connection. Connecting does not change * whether the world can reach this host, it only proves it, and the proof @@ -671,11 +749,25 @@ public static function get_onboarding_site_portrait() { private static function can_photograph_site() { $status = new Status(); - if ( $status->is_offline_mode() || $status->is_local_site() ) { - return false; - } + $can = ! $status->is_offline_mode() + && ! $status->is_local_site() + && ! $status->is_private_site() + && ! $status->is_coming_soon() + && 1 === (int) get_option( 'blog_public' ); - return (bool) (int) get_option( 'blog_public' ); + /** + * Whether this site's homepage may be sent to WordPress.com's screenshot + * service for the setup wizard's panel. + * + * Only the site's own address is sent, and only while the wizard is on + * screen. Hosts serving sites that are public but unreachable from outside, + * such as an intranet, can turn it off here. + * + * @since $$next-version$$ + * + * @param bool $can Whether the screenshot may be requested. + */ + return (bool) apply_filters( 'jetpack_my_jetpack_can_photograph_site', $can ); } /** diff --git a/projects/packages/my-jetpack/tests/php/Onboarding_Site_Portrait_Test.php b/projects/packages/my-jetpack/tests/php/Onboarding_Site_Portrait_Test.php new file mode 100644 index 000000000000..91ddad92cd59 --- /dev/null +++ b/projects/packages/my-jetpack/tests/php/Onboarding_Site_Portrait_Test.php @@ -0,0 +1,250 @@ + + */ + public static function provide_blog_public() { + return array( + 'public' => array( '1', true ), + 'public as an integer' => array( 1, true ), + 'discouraging search' => array( '0', false ), + 'unset' => array( '', false ), + 'private' => array( '-1', false ), + 'more privacy options' => array( '-2', false ), + 'more privacy options too' => array( '-3', false ), + ); + } + + /** + * @param mixed $blog_public What the option holds. + * @param bool $expected Whether the site may be photographed. + * @dataProvider provide_blog_public + */ + #[DataProvider( 'provide_blog_public' )] + public function test_only_a_public_site_is_photographed( $blog_public, $expected ) { + update_option( 'blog_public', $blog_public ); + + $this->assertSame( $expected, $this->can_photograph() ); + } + + public function test_offline_mode_is_never_photographed() { + remove_filter( 'jetpack_offline_mode', '__return_false' ); + add_filter( 'jetpack_offline_mode', '__return_true' ); + StatusCache::clear(); + + $this->assertFalse( $this->can_photograph() ); + + remove_filter( 'jetpack_offline_mode', '__return_true' ); + } + + /** + * A coming-soon site answers with its splash rather than its homepage, however + * public the option says it is. + */ + public function test_a_coming_soon_site_is_not_photographed() { + add_filter( 'jetpack_is_coming_soon', '__return_true' ); + StatusCache::clear(); + + $this->assertFalse( $this->can_photograph() ); + + remove_filter( 'jetpack_is_coming_soon', '__return_true' ); + } + + /** + * For hosts serving sites that are public but unreachable from outside. + */ + public function test_a_host_can_turn_it_off() { + add_filter( 'jetpack_my_jetpack_can_photograph_site', '__return_false' ); + + $this->assertFalse( $this->can_photograph() ); + } + + public function test_the_filter_cannot_photograph_a_private_site() { + update_option( 'blog_public', '-1' ); + add_filter( 'jetpack_my_jetpack_can_photograph_site', '__return_true' ); + + $this->assertTrue( $this->can_photograph(), 'the filter has the last word, both ways' ); + } + + /** + * `wp_count_attachments()` returns per-mime-type counts plus a `trash` total + * that is not in the library. Left in, it reports the emptied uploads back to + * the person who emptied them. + */ + /** + * `wp_count_attachments()` returns per-mime-type counts plus a `trash` total + * that is not in the library. Left in, it reports the emptied uploads back to + * the person who emptied them. + * + * Driven through the filter because WorDBless has no queryable posts table: + * an insert here returns an id and `wp_count_posts()` still answers zero. + */ + public function test_the_media_count_leaves_out_the_trash() { + add_filter( + 'wp_count_attachments', + function () { + return (object) array( + 'image/png' => 3, + 'application/pdf' => 2, + 'trash' => 40, + ); + } + ); + + $portrait = Initializer::get_onboarding_site_portrait(); + + $this->assertSame( 5, $portrait['counts']['media'] ); + } + + public function test_the_media_count_survives_a_library_with_no_trash_key() { + add_filter( + 'wp_count_attachments', + function () { + return (object) array( 'image/png' => 4 ); + } + ); + + $portrait = Initializer::get_onboarding_site_portrait(); + + $this->assertSame( 4, $portrait['counts']['media'] ); + } + + public function test_it_counts_published_posts_and_pages_only() { + add_filter( + 'wp_count_posts', + function ( $counts, $type ) { + return (object) array( + 'publish' => 'post' === $type ? 12 : 3, + 'draft' => 99, + 'trash' => 7, + ); + }, + 10, + 2 + ); + + $portrait = Initializer::get_onboarding_site_portrait(); + + $this->assertSame( 12, $portrait['counts']['posts'] ); + $this->assertSame( 3, $portrait['counts']['pages'] ); + } + + /** + * The head link exists to start the render before the wizard's own JavaScript + * can, so it has to ask for the same picture. Asserted as a whole string, and + * again in `use-site-shot.test.ts`, because a drift on either side warms a + * render nothing then reads and nothing else would notice. + */ + public function test_the_preload_asks_for_exactly_what_the_wizard_asks_for() { + $_GET['page'] = 'my-jetpack'; + $_GET['step'] = 'onboarding'; + add_filter( 'home_url', array( $this, 'return_example_url' ) ); + + ob_start(); + Initializer::preload_onboarding_site_shot(); + $printed = ob_get_clean(); + + $this->assertStringContainsString( + 'https://s0.wp.com/mshots/v1/https%3A%2F%2Fexample.com?vpw=1600&vph=1600&w=880&h=550&scale=2', + $printed + ); + $this->assertStringContainsString( 'rel="preload"', $printed ); + $this->assertStringContainsString( 'as="image"', $printed ); + } + + public function test_nothing_is_preloaded_for_a_site_that_cannot_be_photographed() { + $_GET['page'] = 'my-jetpack'; + $_GET['step'] = 'onboarding'; + update_option( 'blog_public', '0' ); + + ob_start(); + Initializer::preload_onboarding_site_shot(); + + $this->assertSame( '', ob_get_clean() ); + } + + /** + * Every other admin page would be warming a render nothing is going to read. + */ + public function test_nothing_is_preloaded_outside_the_wizard() { + $_GET['page'] = 'my-jetpack'; + unset( $_GET['step'] ); + + ob_start(); + Initializer::preload_onboarding_site_shot(); + + $this->assertSame( '', ob_get_clean() ); + } + + /** + * @return string + */ + public function return_example_url() { + return 'https://example.com'; + } + + public function test_the_domain_is_a_string_even_for_a_broken_home_url() { + add_filter( 'home_url', '__return_empty_string' ); + + $portrait = Initializer::get_onboarding_site_portrait(); + + $this->assertIsString( $portrait['domain'] ); + + remove_filter( 'home_url', '__return_empty_string' ); + } +} diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team new file mode 100644 index 000000000000..e81a6743cc19 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-portrait-red-team @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: never photograph a private or coming-soon site during setup, and leave trashed uploads out of the media count. From 3fb6dddfe189e902f14ba31354fecfef5cfb456a Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Sun, 27 Sep 2026 12:14:48 -0400 Subject: [PATCH 05/15] My Jetpack: stop the onboarding layout coming apart on a tall window The sheet and the brand panel are both capped at 944px and centred, for the reason written on the panel: the two stop being the same object on a tall window. The rail was never given the same treatment, so it alone stretched to the full window and the step list climbed away from the card it belongs to. On a 1264px window they were 160px apart, which reads as two layouts that have come unstuck. The rail's ground belongs to the shell, so capping it moves the steps and leaves the dark full bleed. The panel also gave up its artwork for a site it cannot photograph and showed three numbers centred in a column six hundred pixels tall. The picture is the portrait; the counts were its caption in the prototype and do not carry a panel on their own. Without a picture the panel keeps the artwork every other step shows. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../onboarding-screen/wizard/site-portrait.tsx | 15 ++++++++------- .../onboarding-screen/wizard/styles.module.scss | 15 +++++++++++++++ .../wizard/test/site-portrait.test.tsx | 17 +++++++++-------- .../fix-my-jetpack-onboarding-tall-window | 4 ++++ .../fix-my-jetpack-onboarding-tall-window | 4 ++++ 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-tall-window create mode 100644 projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-tall-window diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx index 24ddaa0b0a48..19e21f1fee08 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx @@ -275,15 +275,16 @@ export function SitePortrait( { site, shot }: { site: OnboardingSite; shot: stri } /** - * Whether there is anything true to put on the panel for this site. + * Whether this site has a portrait to put on the panel. + * + * The picture is the portrait. The counts came with it in the prototype and read + * as a caption under it; on their own they are three numbers centred in a column + * six hundred pixels tall, which is what a site that cannot be photographed was + * getting. The panel falls back to its artwork instead. * * @param site - What the page told us, if anything. - * @return True when the portrait has either a picture coming or a count to show. + * @return True when there is a picture coming. */ export function hasPortrait( site: OnboardingSite | undefined ): site is OnboardingSite { - if ( ! site ) { - return false; - } - - return site.canPhotograph || Object.values( site.counts ).some( count => count > 0 ); + return Boolean( site?.canPhotograph ); } diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index df2e5be163dd..fb7358eb0502 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -483,6 +483,21 @@ $rail-row-min-height: 40px; min-inline-size: 0; padding-block: var(--wpds-dimension-padding-lg); + /* + * Sized and centred with the sheet, for the reason already written on the + * brand panel: the three are one object. The sheet and the panel were capped + * and this was not, so on a window taller than the cap the steps climbed away + * from the card they belong to — 160px apart on a 1264px window, which reads + * as two layouts that have come apart. + * + * The ground is the shell's, not the rail's, so this moves the steps and + * leaves the dark full-bleed behind them. + */ + @media (min-width: $rail-breakpoint) { + align-self: center; + block-size: min(100%, #{$sheet-max-height}); + } + /* * Collapsed it is a header bar, and a header bar wants a header's gaps. It * kept the column's, so the mark, the title and the count sat 16 apart in a diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx index f1c0ad97e7cd..bd2d31346a5d 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/site-portrait.test.tsx @@ -28,16 +28,17 @@ const show = ( over: Partial< OnboardingSite > = {}, shot: string | null = null const posts = ( n: number ) => ( { posts: n, pages: 0, media: 0, plugins: 0 } ); describe( 'What the portrait is willing to show', () => { - it( 'says nothing at all for a site with no picture and no counts', () => { - expect( - hasPortrait( - site( { canPhotograph: false, counts: { posts: 0, pages: 0, media: 0, plugins: 0 } } ) - ) - ).toBe( false ); + it( 'says nothing at all when the page told us nothing', () => { + expect( hasPortrait( undefined ) ).toBe( false ); } ); - it( 'shows counts even when the site cannot be photographed', () => { - expect( hasPortrait( site( { canPhotograph: false } ) ) ).toBe( true ); + /* + * The picture is the portrait. On their own the counts are three numbers + * centred in a column six hundred pixels tall, so the panel takes its artwork + * back instead. + */ + it( 'yields the panel entirely when the site cannot be photographed', () => { + expect( hasPortrait( site( { canPhotograph: false } ) ) ).toBe( false ); } ); it( 'shows the picture even for a site with nothing in it yet', () => { diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-tall-window b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-tall-window new file mode 100644 index 000000000000..f14f454a8b5f --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-tall-window @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: keep the step list level with the card on a tall window, and keep the panel's artwork on a site that cannot be photographed. diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-tall-window b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-tall-window new file mode 100644 index 000000000000..46e82152352c --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-tall-window @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: fix the setup wizard's layout coming apart on a tall window. From 89e0e8e0412e1ddce71a656cdfc23cd8d6af9116 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Mon, 28 Sep 2026 19:34:29 -0400 Subject: [PATCH 06/15] My Jetpack: let the artwork carry the onboarding panel The display copy is gone. It was set in a face we cannot ship, outlined to SVG at build time so no font file ever went out, and outlines cannot be translated. Weighed against re-setting it: there is no wide Inter, the variable axes are opsz and weight with no width; WordPress core bundles no text font at all, only Dashicons and TinyMCE's icons; every font in this monorepo is an icon font; and loading one from Google's CDN would send a self-hosted owner's address to Google from the first screen they see. A subset would have cost 20 to 30KB against the 3.3KB the outlines gzip to. So the words went instead of the typeface, and the panel is artwork. Two things were holding the mesh gradient down and both only existed to protect that copy. The mask dimmed the lower third so the words had somewhere quiet to sit, and the periods were 17 to 29 seconds, which behind a 64px blur could not be seen moving at all. The mask is deleted, the periods are 7 to 17 and still primes so the four never re-align, and the drift is wider. The artwork takes 92% of the panel rather than 77%. The feature step sets on one line at the column's 470px: the heading loses everything but what it is for, and the four site-type lines end "Turn off any you don't need" rather than a sentence that wrapped whatever was in front of it. The site-type question says what the answer actually does, which is order the features, not choose them. The way out of the takeover carries its words. It was a mark with a tooltip, and a tooltip is the one affordance a touch user never gets, on the screen that has taken over their admin. It is padded now so the hover is a shape rather than a box clamped to the text, and pulled back by the same amount so the mark still lines up with the title under it. The finish screen's wash reaches the page. It was clipped twice over: the discs were a fixed multiple of a 64px badge, so they stopped at 768px on a 1600px window, and the screen itself was sitting inside the 470px reading column that clips them. The reach is a share of the window now, and the finish screen is out of the column. One commit because the stylesheet carries nearly all of it and splitting the hunks would have been more risk than the history is worth. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../onboarding-screen/wizard/lib.ts | 26 +- .../onboarding-screen/wizard/panel-type.ts | 69 ------ .../wizard/styles.module.scss | 229 +++++++----------- .../wizard/test/smoke.test.tsx | 68 +----- .../onboarding-screen/wizard/wizard.tsx | 82 ++----- ...pdate-my-jetpack-onboarding-panel-and-copy | 4 + .../my-jetpack/tools/generate-panel-type.py | 125 ---------- ...pdate-my-jetpack-onboarding-panel-and-copy | 4 + 8 files changed, 124 insertions(+), 483 deletions(-) delete mode 100644 projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-type.ts create mode 100644 projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy delete mode 100644 projects/packages/my-jetpack/tools/generate-panel-type.py create mode 100644 projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts index b1f01183dcb3..0530fc701ce2 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts @@ -183,8 +183,14 @@ export function wizardSteps(): WizardStepMeta[] { * This one is true either way, so it needs no second question about which. */ title: __( "What's this site for?", 'jetpack-my-jetpack' ), + /* + * Says what the answer does and no more. It only orders the features — + * all six are offered and all six start on whatever is picked — so + * anything about recommending a different set would be a promise the + * next step does not keep. + */ description: __( - 'Pick the closest fit. It shapes what we suggest next.', + 'Pick the closest fit. We’ll put the most useful features first.', 'jetpack-my-jetpack' ), /* @@ -232,10 +238,10 @@ export function wizardSteps(): WizardStepMeta[] { id: 'features', kind: 'features', label: __( 'What you need', 'jetpack-my-jetpack' ), - title: __( "Here's what we recommend for your site", 'jetpack-my-jetpack' ), + title: __( 'What we recommend', 'jetpack-my-jetpack' ), // Replaced by featuresDescription() once the site type is known; this is // what someone who skipped the question or typed their own answer reads. - description: __( 'Turn off anything you would rather not have.', 'jetpack-my-jetpack' ), + description: __( 'Turn off any you don’t need.', 'jetpack-my-jetpack' ), // The rows are the modules Jetpack reports, not a fixed list written here. options: [], }, @@ -354,24 +360,24 @@ export function siteTypeAnswer( state: WizardState ): string | undefined { * still start on, so "these matter most" is about what is at the top of the * list, and nothing here says anything was left out. * + * Each one is short enough to set on one line at the column's 470px. The + * longest, the business line, uses all of it, so a translation will wrap. + * * @return The line for each site type that has one, translated at call time. */ function featuresDescriptions(): Record< string, string > { return { - blog: __( - 'For a blog, these matter most. Turn off anything you would rather not have.', - 'jetpack-my-jetpack' - ), + blog: __( 'For a blog, these matter most. Turn off any you don’t need.', 'jetpack-my-jetpack' ), store: __( - 'For a store, these matter most. Turn off anything you would rather not have.', + 'For a store, these matter most. Turn off any you don’t need.', 'jetpack-my-jetpack' ), portfolio: __( - 'For a portfolio, these matter most. Turn off anything you would rather not have.', + 'For a portfolio, these matter most. Turn off any you don’t need.', 'jetpack-my-jetpack' ), business: __( - 'For a business site, these matter most. Turn off anything you would rather not have.', + 'For a business site, these matter most. Turn off any you don’t need.', 'jetpack-my-jetpack' ), }; diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-type.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-type.ts deleted file mode 100644 index e817f8f3e126..000000000000 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-type.ts +++ /dev/null @@ -1,69 +0,0 @@ -/** - * GENERATED FILE — do not edit by hand. - * - * The onboarding panel's display copy, outlined from Söhne Breit. Regenerate with - * `tools/generate-panel-type.py` after changing a line; that script holds the copy. - * - * These lines are brand copy and read the same in every locale by design, so they - * carry no `__()` call. Each entry keeps its text for the accessible name. - */ - -export type PanelLine = { - // The words, for the accessible name and the visually hidden copy. - text: string; - // SVG path data for the whole line, already shaped and kerned. - path: string; - // Width as a multiple of the line box, so one font-size scales the line. - ratio: number; -}; - -export const PANEL_LINES: Record< number, PanelLine[] > = { - '0': [ - { - text: 'Grow your audience.', - path: '', - ratio: 7.9208, - }, - { - text: 'Speed up your site.', - path: '', - ratio: 7.4646, - }, - { - text: 'Keep it secure.', - path: '', - ratio: 5.7489, - }, - ], - '1': [ - { - text: 'Set up in minutes.', - path: '', - ratio: 6.9849, - }, - { - text: 'We do the rest.', - path: '', - ratio: 5.9646, - }, - ], - '2': [ - { - text: 'The essentials,', - path: '', - ratio: 5.8333, - }, - { - text: 'switched on.', - path: '', - ratio: 4.8771, - }, - ], - '3': [ - { - text: 'Ready when you are.', - path: '', - ratio: 8.0558, - }, - ], -}; diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index fb7358eb0502..23d840a0e5ee 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -79,58 +79,24 @@ $row-glyph-gap: 14px; $row-min-height: 56px; /* - * The panel's display copy. The prototype sizes it off the viewport, at - * `clamp(26px,2.3vw,40px)` (components/onboarding/brand-panel.tsx:72), and the - * same rule reads much smaller here: its panel is 44% of a screen with no - * rail, ours is $panel-width of a grid that carries one. - * - * So the size is a share of the panel instead. .brand-panel__inner is the - * query container, and 1cqw is 1% of its content box, which $panel-copy-inset - * below makes exactly the copy block's own width. A line renders at `ratio` - * times the font size, and the widest ratio across the four steps is 7.9208, - * "Grow your audience." in panel-type.ts, so landing that line on 72% of the - * block is 72 / 7.9208, or 9.09cqw. At a 1440px viewport the block is 451.2px, - * the size is 41.0px, and that line is 324.8px wide: 72.0% of the block. - * - * 72% and not the 80% this started at, which put the widest line 8px from the - * inset and read as touching it. The prototype's own widest line is 38% of its - * panel; 72% is the compromise, because the size was raised deliberately. - * - * The clamp only guards the ends. 26px is the prototype's own floor, below a - * window the panel is hidden at anyway; 72px is reached at 792px of block, - * which is where $panel-copy-max-width stops it too. - * - * The line height is a unitless ratio rather than a token because the size it - * multiplies is fluid. - */ -$panel-copy-size-min: 26px; -$panel-copy-size-fluid: 9.09cqw; -$panel-copy-size-max: 72px; -$panel-copy-line-height: 1.16; - -/* - * The copy's inset from the panel's edge, from the prototype's `inset-x-10` on + * The panel's inset from its own edge, from the prototype's `inset-x-10` on * components/onboarding/brand-panel.tsx — Tailwind's 10, so 2.5rem. No WPDS - * padding token is 40px. It replaces the inner's inline padding rather than - * nesting inside it, so the container-query box and the copy block are one - * width and the 72% above is measured against the block itself. + * padding token is 40px. */ -$panel-copy-inset: 40px; +$panel-inset: 40px; /* * The panel's foot is deeper than its head, from the prototype's `pb-14` on - * brand-panel.tsx — Tailwind's 14, so 56px. It is what stops the display line - * reading as if it has slipped off the panel. The padding scale stops at 32 + * brand-panel.tsx — Tailwind's 14, so 56px. The padding scale stops at 32 * (--wpds-dimension-padding-3xl), so there is no step above it. */ -$panel-copy-bottom-inset: 56px; +$panel-bottom-inset: 56px; /* * The measure's ceiling, so a very wide panel cannot sprawl the line. It is * the width at which the clamp caps out — 72px / 9.09% — so the two limits * land together and the widest line stays at 72% past it. */ -$panel-copy-max-width: 792px; /* * The three stops of the shared gradient artwork, read off the linearGradient @@ -150,20 +116,25 @@ $brand-gradient-blue: #2e38fa; * field, and a blur radius has no scale at all. * * The periods are primes, so the four never visibly re-align: the shortest - * cycle they share is 17 x 19 x 23 x 29 seconds, about 48 hours. They were - * 37/47/59, which showed roughly one pass before anyone had read the screen. + * cycle they share is 7 x 11 x 13 x 17 seconds, about four and a half hours. + * + * They were 17/19/23/29, a half-minute field, and behind a 64px blur that + * could not be seen moving at all. A field nobody can tell is moving is a + * still image that costs four animations. */ -$mesh-period-1: 17s; -$mesh-period-2: 19s; -$mesh-period-3: 23s; -$mesh-period-4: 29s; +$mesh-period-1: 7s; +$mesh-period-2: 11s; +$mesh-period-3: 13s; +$mesh-period-4: 17s; /* * Blur is what makes four circles read as one field, so it is large next to - * the blobs. The opacities are set by the mint copy's contrast, measured on - * the composited background at the worst alignment of all four cycles rather - * than at one frame: 7.87:1 on a 680px panel, 8.00:1 on a 900px one, against - * a 7:1 floor. The mask below is what buys the headroom to be this bright. + * the blobs. + * + * The opacities used to be pinned by the contrast of the display copy that sat + * over them. That copy is gone, so the only thing above the field now is the + * artwork's hairline, and these are free to be read as a gradient rather than + * as a tint. */ $mesh-blur: 64px; $mesh-opacity-bright: 0.34; @@ -172,20 +143,10 @@ $mesh-opacity-blue: 0.58; $mesh-opacity-deep: 0.62; /* - * A stencil rather than a colour, and the reason the blobs can be this bright: - * the field is opaque over the top 62% and drops to $mesh-mask-floor by 77%, - * which is where the display copy starts on the shortest panel the breakpoint - * allows. A floor rather than nothing, so the lower third still moves. What - * the fade uncovers is the same ground the mesh paints, so it has no edge. - * - * It is a mask and not a per-blob drift limit because blur() is a fixed radius: - * a percentage travel limit that clears the copy at 900px fails at 680px, where - * the same 64px of soft edge covers half as much again of the panel. The mask - * is in percentages of the panel, so it is the only one of the two that scales. + * The field used to be held down over its lower third by a mask, so the display + * copy had something quiet to sit on. Nothing sits on it now, so the mask is + * gone and the whole panel carries the gradient. */ -$mesh-mask-floor: 0.56; -$mesh-mask-low: rgba(0, 0, 0, $mesh-mask-floor); -$mesh-mask: linear-gradient(to bottom, #000 0%, #000 62%, $mesh-mask-low 77%); /* * The panel artwork. Its width is the prototype's own proportion: 560px of art @@ -230,7 +191,7 @@ $portrait-shadow: 0 21.255px 21.255px rgba(15, 36, 117, 0.05), 0 42px 42px rgba(15, 36, 117, 0.1); -$panel-art-width: 77%; +$panel-art-width: 92%; $panel-art-draw-duration: 1.4s; /* @@ -258,8 +219,6 @@ $appear-reduced-duration: 0.4s; * The panel copy's own entrance, from the prototype's `.panel-line`: same 0.5s * but on the house curve and a 14px rise, one line 0.08s behind the last. */ -$panel-line-rise: 14px; -$panel-line-step: 0.08s; /* * The question column's measure. The surface-width scale steps 400, 560, 720, @@ -319,15 +278,22 @@ $wave-base: 0.1s; $wave-step: 0.08s; /* - * The finish screen's badge and the discs washing out from behind it. Scales, - * durations and delays are the prototype's, measured. The reference it came - * from used 28, 34 and 30, which on a full-width sheet is the whole window - * turning green rather than a bloom. + * The finish screen's badge and the discs washing out from behind it. Durations + * and delays are the prototype's, measured. + * + * How far each disc reaches is a share of the window's longest side, not a + * multiple of the badge. A multiple cannot track a screen: the prototype's own + * 28 is 1792px, which clears a 1600px window and stops two thirds of the way + * across a 2560px one, and the 12 it was cut to stopped at 768px — half of an + * ordinary window, so the wave read as a circle rather than a wash. + * + * These are the prototype's three at the width they were drawn against, written + * so they clear any width. `.finish` clips, so reaching past the edge is free. */ $finish-badge-size: 64px; -$finish-wash-1: 12; -$finish-wash-2: 15; -$finish-wash-3: 13; +$finish-wash-reach-1: 1.12; +$finish-wash-reach-2: 1.36; +$finish-wash-reach-3: 1.2; $finish-wash-duration-1: 1.4s; $finish-wash-duration-2: 1.8s; $finish-wash-duration-3: 1.6s; @@ -519,15 +485,22 @@ $rail-row-min-height: 40px; } /* - * The icon-only exit control, sized the way @wordpress/ui's own icon buttons - * are: square, at the compact height. + * The way out of the takeover. + * + * Padded, so the hover surface is a shape around the control rather than a box + * clamped to the words, and pulled back by the same amount so the mark still + * lines up with the rail title under it. Without the offset the padding would + * push the mark to the right of everything below it. + * + * The rail head's own gap is 4px, which is a gap between a title and its + * subtitle, not between a control and the heading it sits above. */ .exit { - --wp-ui-button-aspect-ratio: 1; - --wp-ui-button-min-width: unset; - --wp-ui-button-padding-inline: 0; + --wp-ui-button-padding-inline: var(--wpds-dimension-padding-md); align-self: flex-start; + margin-inline-start: calc(-1 * var(--wpds-dimension-padding-md)); + margin-block-end: var(--wpds-dimension-gap-md); } /* @@ -723,11 +696,10 @@ $rail-row-min-height: 40px; // the panel rather than the viewport. Its inline size comes from the grid, // never from its contents, which is what inline-size containment requires. container-type: inline-size; - padding-block: var(--wpds-dimension-padding-3xl) $panel-copy-bottom-inset; + padding-block: var(--wpds-dimension-padding-3xl) $panel-bottom-inset; // The prototype's own inset, and the width the display copy is measured - // against; see $panel-copy-inset. - padding-inline: $panel-copy-inset; + padding-inline: $panel-inset; // The frame's radius, not one step below it: the panel sits beside the frame // at the same scale, and two radii read as two unrelated surfaces. @@ -747,7 +719,6 @@ $rail-row-min-height: 40px; isolation: isolate; background: var(--jp-green-90); - mask-image: $mesh-mask; pointer-events: none; } @@ -901,59 +872,7 @@ $rail-row-min-height: 40px; * The lines are outlines sized in em, so this font-size is what scales them: * a share of the panel's own width, which no token can express. */ -.brand-panel__copy { - position: relative; - z-index: 3; - margin: 0; - max-inline-size: $panel-copy-max-width; - color: var(--jp-green-mint); - font-size: clamp($panel-copy-size-min, $panel-copy-size-fluid, $panel-copy-size-max); - line-height: $panel-copy-line-height; -} - -.brand-panel__line { - display: block; - opacity: 0; - animation-name: panel-line; - animation-duration: $appear-duration; - animation-timing-function: $house-easing; - animation-fill-mode: forwards; - // Sibling-counted rather than nth-child: the visually hidden copy shares the - // parent and would otherwise take the first line's place in the stagger. - & + & { - animation-delay: $panel-line-step; - } - - // The start screen's copy runs to three lines, so the stagger has to keep - // climbing; one selector per line, because a sibling combinator cannot - // count. The multiplier is the line's position, not a duration of its own. - & + & + & { - animation-delay: 2 * $panel-line-step; - } - - @media (prefers-reduced-motion: reduce) { - animation-name: fade-in; - } - - // Block, or the inline SVG sits on a baseline and leaves a descender gap. - svg { - display: block; - } -} - -@keyframes panel-line { - - from { - opacity: 0; - transform: translateY($panel-line-rise); - } - - to { - opacity: 1; - transform: translateY(0); - } -} @keyframes option-cascade { @@ -1004,11 +923,11 @@ $rail-row-min-height: 40px; } 33% { - transform: translate3d(22%, 19%, 0); + transform: translate3d(35%, 30%, 0); } 66% { - transform: translate3d(-18%, 9%, 0); + transform: translate3d(-29%, 14%, 0); } to { @@ -1023,11 +942,11 @@ $rail-row-min-height: 40px; } 33% { - transform: translate3d(-20%, -12%, 0); + transform: translate3d(-32%, -19%, 0); } 66% { - transform: translate3d(13%, -21%, 0); + transform: translate3d(21%, -34%, 0); } to { @@ -1042,11 +961,11 @@ $rail-row-min-height: 40px; } 33% { - transform: translate3d(26%, -14%, 0); + transform: translate3d(42%, -22%, 0); } 66% { - transform: translate3d(10%, 16%, 0); + transform: translate3d(16%, 26%, 0); } to { @@ -1061,11 +980,11 @@ $rail-row-min-height: 40px; } 33% { - transform: translate3d(-24%, 11%, 0); + transform: translate3d(-38%, 18%, 0); } 66% { - transform: translate3d(16%, -17%, 0); + transform: translate3d(26%, -27%, 0); } to { @@ -1425,11 +1344,14 @@ $rail-row-min-height: 40px; transition: none; } - // The prototype's own 16, not the glyph's natural 24: beside a 15px label a - // 24px tick is the biggest thing in the row. + /* + * The step above the prototype's own 16, which was too quiet to read as the + * answer to the question. Not the glyph's natural 24, which beside a 15px + * label is the biggest thing in the row. + */ svg { - inline-size: var(--wpds-dimension-size-2xs); - block-size: var(--wpds-dimension-size-2xs); + inline-size: var(--wpds-dimension-size-xs); + block-size: var(--wpds-dimension-size-xs); fill: currentColor; } @@ -1587,6 +1509,17 @@ $rail-row-min-height: 40px; display: none; } + /* + * The finish screen replaces the sheet rather than sitting in it, so it does + * not take the reading column every other step is measured in. `.finish` is + * what clips the wash discs, and inside a 470px column it clipped them to a + * 470px band down the middle of the page. The reading measure is kept by + * `.finish-column` inside it, where it belongs. + */ + .panel-content { + max-inline-size: none; + } + .canvas { grid-column: 1 / -1; @@ -1746,7 +1679,7 @@ $rail-row-min-height: 40px; animation: finish-wash $finish-wash-duration-1 ease-out both; animation-delay: $wave-base + 0.1s; filter: blur(6px); - --finish-wash-scale: #{$finish-wash-1}; + --finish-wash-scale: calc(#{$finish-wash-reach-1} * 100vmax / #{$finish-badge-size}); // The alpha rides on the colour, as the prototype has it. It cannot sit on // `opacity`, because that is the property the keyframe drives to 0. @@ -1758,7 +1691,7 @@ $rail-row-min-height: 40px; animation-delay: $wave-base + 0.2s; background: color-mix(in sRGB, var(--jp-green-50) 15%, transparent); filter: blur(8px); - --finish-wash-scale: #{$finish-wash-2}; + --finish-wash-scale: calc(#{$finish-wash-reach-2} * 100vmax / #{$finish-badge-size}); } .finish-wash--3 { @@ -1766,7 +1699,7 @@ $rail-row-min-height: 40px; animation-delay: $wave-base + 0.4s; background: color-mix(in sRGB, var(--jp-white) 30%, transparent); filter: blur(6px); - --finish-wash-scale: #{$finish-wash-3}; + --finish-wash-scale: calc(#{$finish-wash-reach-3} * 100vmax / #{$finish-badge-size}); } .finish-title { diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx index ddf70bb08d4d..1bffdad807ab 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx @@ -3,7 +3,6 @@ import userEvent from '@testing-library/user-event'; import { bell, chartBar, border, drafts, published } from '@wordpress/icons'; import { Children, isValidElement } from 'react'; import { startBenefits } from '../lib'; -import { PANEL_LINES } from '../panel-type'; import { Wizard } from '../wizard'; import type { UserEvent } from '@testing-library/user-event'; import type { ReactElement, ReactNode } from 'react'; @@ -195,14 +194,6 @@ const railGlyph = ( name: string ) => // eslint-disable-next-line testing-library/no-node-access GLYPH_BY_PATH[ railStep( name ).querySelector( 'svg path' )?.getAttribute( 'd' ) ?? '' ]; -// The panel's lines are outlined SVG, so the words live in one visually hidden -// block per step, read as a sentence rather than as fragments. -const PANEL_COPY = Object.values( PANEL_LINES ).map( lines => - lines.map( line => line.text ).join( ' ' ) -); - -const panelCopy = ( step: number ) => screen.getByText( PANEL_COPY[ step ] ); - // A question step needs a choice before Continue is live; the feature step starts // with every row answered. The start step is not advanced this way: it leaves // wp-admin entirely. @@ -578,7 +569,7 @@ describe( 'Wizard shell', () => { const { user } = setupWizard( { isUserConnected: true } ); await advance( user, 1 ); - expect( heading() ).toHaveTextContent( "Here's what we recommend for your site" ); + expect( heading() ).toHaveTextContent( 'What we recommend' ); await user.click( railStep( 'Your site' ) ); expect( heading() ).toHaveTextContent( "What's this site for?" ); @@ -599,7 +590,6 @@ describe( 'Wizard shell', () => { await advance( user, 2 ); expect( screen.queryByRole( 'navigation' ) ).not.toBeInTheDocument(); - expect( screen.queryByText( PANEL_COPY[ 3 ] ) ).not.toBeInTheDocument(); } ); /* @@ -666,54 +656,6 @@ describe( 'Wizard shell', () => { exitUrl ); } ); - - it( 'gives every step its own panel copy, and shows only the current one', async () => { - const { user } = setupWizard( { isUserConnected: true } ); - - expect( panelCopy( 1 ) ).toBeInTheDocument(); - expect( screen.queryByText( PANEL_COPY[ 0 ] ) ).not.toBeInTheDocument(); - - // Stops at the feature step: the finish step has no panel to carry copy. - for ( const step of [ 2 ] ) { - await advance( user, 1 ); - expect( panelCopy( step ) ).toBeInTheDocument(); - expect( screen.queryByText( PANEL_COPY[ step - 1 ] ) ).not.toBeInTheDocument(); - } - } ); - - it( 'draws the lines as outlines, flipped out of y-up font coordinates', () => { - setupWizard(); - - // eslint-disable-next-line testing-library/no-node-access - const svgs = Array.from( panelCopy( 0 ).parentElement?.querySelectorAll( 'svg' ) ?? [] ); - - // One per line, and hidden: the words are carried by the copy above - // instead. Counted off the data, because the start screen's copy is - // three lines where every other step's is two. - expect( svgs ).toHaveLength( PANEL_LINES[ 0 ].length ); - expect( svgs.every( svg => svg.getAttribute( 'aria-hidden' ) === 'true' ) ).toBe( true ); - - // The box is the font's, and the flip is what keeps the glyphs right way up. - expect( svgs[ 0 ] ).toHaveAttribute( - 'viewBox', - expect.stringMatching( /^0 -1037 [\d.]+ 1326$/ ) - ); - expect( - // eslint-disable-next-line testing-library/no-node-access - svgs.map( svg => svg.querySelector( 'g' )?.getAttribute( 'transform' ) ) - ).toEqual( PANEL_LINES[ 0 ].map( () => 'scale(1, -1)' ) ); - } ); - - it( 'joins the three start-screen lines into one hidden sentence', () => { - setupWizard(); - - // The start screen's copy runs to three lines where every other step's - // runs to two, and the three are read as one sentence, not as fragments. - expect( PANEL_LINES[ 0 ] ).toHaveLength( 3 ); - expect( panelCopy( 0 ) ).toHaveTextContent( - 'Grow your audience. Speed up your site. Keep it secure.' - ); - } ); } ); describe( 'The site-type question', () => { @@ -840,7 +782,7 @@ describe( 'Clicking Continue twice', () => { await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); await user.dblClick( screen.getByRole( 'button', { name: 'Continue' } ) ); - expect( heading() ).toHaveTextContent( "Here's what we recommend for your site" ); + expect( heading() ).toHaveTextContent( 'What we recommend' ); expect( mockApply ).not.toHaveBeenCalled(); } ); @@ -869,7 +811,7 @@ describe( 'Coming back to a run in progress', () => { unmount(); setupWizard( { isUserConnected: true } ); - expect( heading() ).toHaveTextContent( "Here's what we recommend for your site" ); + expect( heading() ).toHaveTextContent( 'What we recommend' ); expect( screen.getByText( /For a store, these matter most/ ) ).toBeInTheDocument(); } ); @@ -991,9 +933,7 @@ describe( 'The feature step', () => { await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); expect( screen.queryByText( /matter most/ ) ).not.toBeInTheDocument(); - expect( - screen.getByText( 'Turn off anything you would rather not have.' ) - ).toBeInTheDocument(); + expect( screen.getByText( 'Turn off any you don’t need.' ) ).toBeInTheDocument(); } ); it( 'lists the modules with Jetpack’s own names, every one switched on', async () => { diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx index 437d91b71abf..d9c4a4af0387 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx @@ -10,7 +10,7 @@ import { import { __, sprintf } from '@wordpress/i18n'; import { border, chevronLeft, chevronRight, drafts, published, wordpress } from '@wordpress/icons'; import { ThemeProvider } from '@wordpress/theme'; -import { Button, Icon, LinkButton, Stack, Text, Tooltip, VisuallyHidden } from '@wordpress/ui'; +import { Button, Icon, LinkButton, Stack, Text } from '@wordpress/ui'; import clsx from 'clsx'; import { useCallback, useEffect, useId, useRef, useState, useMemo } from 'react'; import { Slide01Gradient } from '../../testimonials/slide-01-gradient'; @@ -27,7 +27,6 @@ import { wizardSteps, } from './lib'; import { PanelArt } from './panel-art'; -import { PANEL_LINES } from './panel-type'; import { hasPortrait, SitePortrait } from './site-portrait'; import { ChoiceStep } from './steps/choice-step'; import { FeaturesStep } from './steps/features-step'; @@ -59,14 +58,6 @@ const SHELL_BACKGROUND = '#1e1e1e'; */ const CONTENT_BACKGROUND = '#fcfcfc'; -/* - * Söhne Breit's own metrics, in font units: the hhea ascent, and the line box - * the generator measured every ratio against. Font coordinates are y-up, so the - * box starts at -ascent and the glyphs are flipped back with scale(1, -1). - */ -const TYPE_ASCENT = 1037; -const TYPE_BOX = 1326; - /** * WordPress's own post-status icons: done = published (the ring with a tick), * current = drafts (the half-filled ring), upcoming = border (the dashed ring). @@ -326,7 +317,6 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { [ isFeatures, handleApplyAndContinue, handleNext ] ); - const panelLines = PANEL_LINES[ step ]; const state: WizardState = useMemo( () => ( { choices, freeText: siteTypeDetail } ), [ choices, siteTypeDetail ] @@ -395,35 +385,21 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) {
{ /* - * Icon plus tooltip, as the Site Editor's own back control does it: - * the aria-label is what a screen reader reads, and the popup is the - * only thing a mouse user gets, since the mark alone says nothing. - * Rendered AS the link rather than around it, or the trigger would - * wrap one control in another. + * The words are on the control rather than in a tooltip. The mark + * alone says nothing, and a tooltip is the one affordance a touch + * user never gets — on the screen that takes over their admin, the + * way back has to be readable without hovering it. */ } - - - - - } - /> - { /* - * Beside the mark, not under it: the rail title sits directly - * below and a popup on that side lands on top of the words. - */ } - }> - { __( 'Back to WordPress', 'jetpack-my-jetpack' ) } - - + + + { __( 'Back to WordPress', 'jetpack-my-jetpack' ) } + { wizardTitle } @@ -613,34 +589,6 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { ) : ( ) } - { /* Keyed by step so each line rises again when the copy is swapped. */ } -

- { /* - * The lines are drawn as outlines, so the words themselves are - * carried here — one sentence per step, not one per line. - */ } - }> - { panelLines.map( line => line.text ).join( ' ' ) } - - - { panelLines.map( line => ( - - - - ) ) } -

diff --git a/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy b/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy new file mode 100644 index 000000000000..27e1d3000225 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Onboarding: let the artwork carry the panel, shorten the setup copy, and name the way back to WordPress. diff --git a/projects/packages/my-jetpack/tools/generate-panel-type.py b/projects/packages/my-jetpack/tools/generate-panel-type.py deleted file mode 100644 index 09208736ab3e..000000000000 --- a/projects/packages/my-jetpack/tools/generate-panel-type.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python3 -"""Generate the onboarding panel's display copy as outlined SVG paths. - -The panel's display lines are set in Söhne Breit. The font file is not part of -this repository, so a fixed set of brand lines is outlined here instead and only -the resulting paths ship. - -The lines are brand copy, not interface copy: they read the same in every locale by -design, exactly like a logo. That is a deliberate choice and it replaces an earlier -version that split each line into two half-sentence translatable strings, which no -translator could work with ("Tell us what you're" / "building."). - -Run this after changing a line, and commit the generated file. It is a developer -tool; nothing here ships. - - pip install fonttools uharfbuzz - python3 tools/generate-panel-type.py /path/to/SohneBreit-Buch.otf - -Text is shaped through HarfBuzz so kerning and ligatures match the real typeface; -laying the glyphs out on raw advance widths loses both. -""" - -import json -import subprocess -import sys -from pathlib import Path - -import uharfbuzz as hb -from fontTools.pens.svgPathPen import SVGPathPen -from fontTools.ttLib import TTFont - -# Keyed by wizard step index. Each step gets one or two lines, each rendered as its -# own SVG so they can rise independently. -LINES = { - # Step 1 is the start screen, so its panel carries the prototype's start-screen - # display copy rather than a line about the wizard. - 0: [ 'Grow your audience.', 'Speed up your site.', 'Keep it secure.' ], - 1: [ 'Set up in minutes.', 'We do the rest.' ], - 2: [ 'The essentials,', 'switched on.' ], - 3: [ 'Ready when you are.' ], -} - -OUT = Path( __file__ ).parent.parent / '_inc/components/onboarding-screen/wizard/panel-type.ts' - -HEADER = '''/** - * GENERATED FILE — do not edit by hand. - * - * The onboarding panel's display copy, outlined from Söhne Breit. Regenerate with - * `tools/generate-panel-type.py` after changing a line; that script holds the copy. - * - * These lines are brand copy and read the same in every locale by design, so they - * carry no `__()` call. Each entry keeps its text for the accessible name. - */ - -export type PanelLine = { -\t// The words, for the accessible name and the visually hidden copy. -\ttext: string; -\t// SVG path data for the whole line, already shaped and kerned. -\tpath: string; -\t// Width as a multiple of the line box, so one font-size scales the line. -\tratio: number; -}; - -export const PANEL_LINES: Record< number, PanelLine[] > = ''' - - -def shape( font, tt, glyph_set, order, text ): - """Return path data and advance width for one shaped line.""" - buf = hb.Buffer() - buf.add_str( text ) - buf.guess_segment_properties() - hb.shape( font, buf, { 'kern': True, 'liga': True } ) - - x = 0 - parts = [] - for info, pos in zip( buf.glyph_infos, buf.glyph_positions ): - pen = SVGPathPen( glyph_set ) - glyph_set[ order[ info.codepoint ] ].draw( pen ) - commands = pen.getCommands() - if commands: - parts.append( f'' ) - x += pos.x_advance - return ''.join( parts ), x - - -def main(): - if len( sys.argv ) < 2: - sys.exit( 'usage: generate-panel-type.py /path/to/SohneBreit-Buch.otf' ) - - font_path = sys.argv[ 1 ] - blob = hb.Blob.from_file_path( font_path ) - font = hb.Font( hb.Face( blob ) ) - tt = TTFont( font_path ) - glyph_set = tt.getGlyphSet() - order = tt.getGlyphOrder() - ascent, descent = tt[ 'hhea' ].ascent, tt[ 'hhea' ].descent - box = ascent - descent - - out = {} - for step, texts in LINES.items(): - out[ step ] = [] - for text in texts: - path, advance = shape( font, tt, glyph_set, order, text ) - out[ step ].append( { - 'text': text, - 'path': path, - 'ratio': round( advance / box, 4 ), - } ) - - body = json.dumps( out, indent = '\t', ensure_ascii = False ) - OUT.write_text( f'{ HEADER }{ body };\n' ) - - # The viewBox is the same for every line, so the component holds it rather than - # repeating it 8 times in the data. - print( f'wrote { OUT }' ) - print( f'viewBox for the component: 0 { -ascent } WIDTH { box }' ) - print( f'ascent { ascent } descent { descent } box { box }' ) - print( f'{ OUT.stat().st_size / 1024:.1f} KB' ) - - # Match the repo's formatting rather than leaving a generated file that fails lint. - subprocess.run( [ 'pnpm', 'exec', 'prettier', '--write', str( OUT ) ], check = False ) - - -if __name__ == '__main__': - main() diff --git a/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy b/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy new file mode 100644 index 000000000000..0bf51c82ea95 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-panel-and-copy @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +My Jetpack: polish the setup wizard's panel, copy and controls. From 877532d288b3e55703f3d9dd724d015222960d05 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Tue, 29 Sep 2026 07:07:27 -0400 Subject: [PATCH 07/15] My Jetpack: fill the window with the onboarding wizard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sheet, the rail and the panel were each capped at 944px and centred, so a tall window put bands of shell above and below all three. On a 1255px window that is 155px top and bottom; at 1800 it is 444px, half the screen. The cap could not simply go. Its own comment records why it was added: without it the content sat in the top quarter and the rest was a blank cliff. Measured, deleting it gives the site-type step 562px of empty sheet under the last option at 1255 and 1107px at 1800 — a worse defect than the bands, and the free-text branch puts the field you type in 691px above the button you press. The heading is what made centring look impossible. Auto margins on the content moved it 147px between steps 2 and 3, because the content is a different height on each. So the block that centres is a fixed height instead, and the content sits inside it: the same block on every step centres to the same pixel on all of them. Measured at 800, 1255 and 1800: the heading lands where the capped sheet already put it, and does not move between steps. Only the bands become sheet. The rail goes back to running full height with its steps at the top, which is where a sidebar's belong. Capping it was the wrong lever for a real symptom — the steps sitting 160px away from the card — and the symptom is gone once the sheet fills. Separately, the finish pane clipped its frozen wash discs sideways but not downwards, so they stayed scrollable long after fading out: 319px of dead scroll at 1440 by 800, and one nudge of the wheel took the badge and the heading off the top. Clipped on both axes now, and the dead scroll is zero. Three agents on this: one measured what the content needs, one prototyped every option in the live page, one tried to break it at short windows, the rail breakpoint, phone widths and the finish screen. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/styles.module.scss | 91 +++++++++---------- .../fix-my-jetpack-onboarding-full-height | 4 + .../fix-my-jetpack-onboarding-full-height | 4 + 3 files changed, 51 insertions(+), 48 deletions(-) create mode 100644 projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-full-height create mode 100644 projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-full-height diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index 23d840a0e5ee..26843a47f71a 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -10,21 +10,6 @@ */ $rail-width: 300px; -/* - * How tall the sheet gets before it stops growing and starts centring. Past - * this the sheet only adds white: at an 1800px window the content sat in the - * top quarter and the rest was a blank cliff. - * - * Measured against the tallest step, the feature list, at the width the panel - * leaves it: its content, the body's 48 of padding, a 73px footer, the column's - * 56px offset, and this element's own 32 of inset. Re-measure it if that step - * grows — a sheet a few pixels short is a scroll container with nowhere to go, - * which moves the heading under anyone who nudges the wheel. - * - * It only holds for the copy as written. A longer translation scrolls, which is - * the designed behaviour and not this number's job to prevent. - */ -$sheet-max-height: 944px; $panel-width: 38%; /* @@ -236,6 +221,20 @@ $step-column-width: 470px; */ $step-column-offset: 56px; +/* + * The step column's own height, and the sheet's old 944px cap re-expressed. The + * sheet fills the window now, and this is the block that centres inside it, so + * that the heading lands on the same pixel whatever the step is. + * + * Same measurement the cap carried: the tallest step's 670, this element's own + * offset, and the 65 of slack the cap already had over the top of them. + * + * Re-measure it if the feature step grows. A block a few pixels short stops + * centring and starts scrolling, which moves the heading under anyone who + * nudges the wheel. + */ +$content-block-height: 735px + $step-column-offset; + /* * The feature row's icon tile. Was the prototype's `size-12`, 48px; at that * size it is the heaviest thing in a row whose job is the words beside it. 40 @@ -392,14 +391,14 @@ $rail-row-min-height: 40px; */ .canvas { display: flex; - align-self: center; min-inline-size: 0; min-block-size: 0; - // A height, not a maximum: a maximum lets the sheet size to its content, and - // then it is a different height on every step and the footer moves with it. - block-size: min(100%, #{$sheet-max-height}); + // The window, less the shell's own gutter. A height, not a maximum: a maximum + // lets the sheet size to its content, and then it is a different height on + // every step and the footer moves with it. + block-size: 100%; padding: $canvas-inset; /* @@ -449,21 +448,6 @@ $rail-row-min-height: 40px; min-inline-size: 0; padding-block: var(--wpds-dimension-padding-lg); - /* - * Sized and centred with the sheet, for the reason already written on the - * brand panel: the three are one object. The sheet and the panel were capped - * and this was not, so on a window taller than the cap the steps climbed away - * from the card they belong to — 160px apart on a 1264px window, which reads - * as two layouts that have come apart. - * - * The ground is the shell's, not the rail's, so this moves the steps and - * leaves the dark full-bleed behind them. - */ - @media (min-width: $rail-breakpoint) { - align-self: center; - block-size: min(100%, #{$sheet-max-height}); - } - /* * Collapsed it is a header bar, and a header bar wants a header's gaps. It * kept the column's, so the mark, the title and the count sat 16 apart in a @@ -626,16 +610,23 @@ $rail-row-min-height: 40px; } /* - * Top-anchored, not centred. An auto top margin moved the heading 147px between - * steps 2 and 3 and 135px back again, and the step change only reads as a - * sequence if the heading holds its place through the swap. The bottom margin - * stays auto so a short step does not stretch. + * Centred as a block of one height, never as its own content. Auto margins on + * the content moved the heading 147px between steps 2 and 3 and 135px back + * again, because the content is a different height on each. A block that is + * $content-block-height on every step centres to the same pixel on all of + * them, so the step change still reads as a sequence. + * + * The clamp to 100% is what keeps a short window honest. Without it the + * block is taller than the sheet, the margins have nothing to distribute, + * and a short step scrolls down onto its own empty tail. */ .panel-content { inline-size: 100%; max-inline-size: $step-column-width; - margin-block: $step-column-offset auto; + min-block-size: min(#{$content-block-height}, 100%); + margin-block: auto; margin-inline: auto; + padding-block-start: $step-column-offset; animation-name: step-enter; animation-duration: $appear-duration; animation-timing-function: $house-easing; @@ -674,12 +665,11 @@ $rail-row-min-height: 40px; @media (min-width: $panel-breakpoint) { display: block; - align-self: center; min-block-size: 0; - // Sized with the sheet, or the two stop being the same object on a tall - // window: one card and one full-height column beside it. - block-size: min(100%, #{$sheet-max-height}); + // Full height, with the sheet. The artwork takes whatever the window + // gives it, so this is the one column that can absorb any amount. + block-size: 100%; padding: var(--wpds-dimension-padding-lg); padding-inline-start: 0; } @@ -1540,6 +1530,7 @@ $rail-row-min-height: 40px; flex-grow: 1; min-block-size: 0; margin-block: 0; + padding-block-start: 0; } } @@ -1600,11 +1591,15 @@ $rail-row-min-height: 40px; .finish { display: flex; - // The wash discs end at 12 to 15 times the badge and stay there, frozen by - // their fill mode, so below about 1024px they drag the sheet sideways onto - // blank white. Clipped rather than hidden: the column itself still has to - // scroll vertically on a short window. - overflow-x: clip; + /* + * The wash discs are frozen at full reach by their fill mode, so they carry + * on being scrollable overflow long after they have faded out. Sideways they + * dragged the sheet onto blank white; downwards they gave the pane up to + * 500px of dead scroll, and one nudge of the wheel took the badge and the + * heading off the top of it. Both axes, and clipped rather than hidden so + * nothing tries to scroll to them. + */ + overflow: clip; min-block-size: 100%; align-items: center; justify-content: center; diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-full-height b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-full-height new file mode 100644 index 000000000000..65d7cab6b01f --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-full-height @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: fill the window rather than floating in it, and stop the finish screen scrolling to nothing. diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-full-height b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-full-height new file mode 100644 index 000000000000..0b0c0739b28f --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-full-height @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: the setup wizard fills the window instead of leaving bands above and below it. From 6f10bfced2cfac8b30de0f4243aeb6bfa6f3b5f7 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Tue, 29 Sep 2026 07:37:19 -0400 Subject: [PATCH 08/15] My Jetpack: stop the onboarding blanking and redrawing between steps Pressing Continue showed an empty sheet first. The outgoing step is gone the instant the step changes, and every incoming element waited for its wave, so the first frames were white. The heading leads now, and the sheet is never empty. The content column was also rising under children that were rising themselves: the column carried the step-swap animation while its heading, its description and its list each carried a wave. Only the waves move now. The row cascade started at 0.12s, before the list it sits in began its own wave at 0.26s, so every row carried two rises at once. It starts where the list does, derived from the wave rather than a number of its own. The panel artwork was keyed by step, which remounts it and replays the draw: 2.6 seconds of the same mark erasing and redrawing itself on every Continue, saying something had changed when nothing had. It draws once now and holds. That only became noise when the per-step display copy went; before that the panel really did change. Verified on the live site: the heading is fading in at 105ms where the sheet used to be blank, and the artwork element survives a step change rather than being replaced. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/styles.module.scss | 28 +++++++++++-------- .../onboarding-screen/wizard/wizard.tsx | 9 +++--- .../fix-my-jetpack-onboarding-motion | 4 +++ .../fix-my-jetpack-onboarding-motion | 4 +++ 4 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-motion create mode 100644 projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-motion diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index 26843a47f71a..a643ffd23632 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -176,7 +176,7 @@ $portrait-shadow: 0 21.255px 21.255px rgba(15, 36, 117, 0.05), 0 42px 42px rgba(15, 36, 117, 0.1); -$panel-art-width: 92%; +$panel-art-width: 68%; $panel-art-draw-duration: 1.4s; /* @@ -265,7 +265,6 @@ $feature-glyph-offset: 3px; */ $option-cascade-duration: 0.3s; $option-cascade-rise: 10px; -$option-cascade-base: 0.12s; $option-cascade-step: 0.05s; /* @@ -276,6 +275,15 @@ $heading-tracking: -0.025em; $wave-base: 0.1s; $wave-step: 0.08s; +/* + * The cascade starts where the list's own wave does, not before it. At the + * prototype's 0.12 the rows were rising inside a list that had not begun to + * move, so each row carried two rises at once and the list read as mush. + * + * After the waves, because Sass resolves in source order. + */ +$option-cascade-base: $wave-base + 2 * $wave-step; + /* * The finish screen's badge and the discs washing out from behind it. Durations * and delays are the prototype's, measured. @@ -627,14 +635,6 @@ $rail-row-min-height: 40px; margin-block: auto; margin-inline: auto; padding-block-start: $step-column-offset; - animation-name: step-enter; - animation-duration: $appear-duration; - animation-timing-function: $house-easing; - - @media (prefers-reduced-motion: reduce) { - animation-name: fade-in; - animation-duration: $appear-reduced-duration; - } } @keyframes step-enter { @@ -1910,8 +1910,14 @@ $rail-row-min-height: 40px; } // Named rather than written per element, because four screens now use them. + +/* + * The heading leads. It used to wait $wave-base like everything else, and since + * nothing else is on screen yet that was a blank sheet for the length of it — + * the outgoing step is gone the instant the step changes. + */ .wave-1 { - animation-delay: $wave-base; + animation-delay: 0s; } .wave-2 { diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx index d9c4a4af0387..69d7bf05c313 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx @@ -580,14 +580,15 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { * the prototype does: that screen says what we read the site as and * asks whether it is right, so the site is the subject of it. * - * Everywhere else the art is the subject. It is drawn in on each of - * those steps and keyed so the draw replays: the animation is CSS, - * so a repeat means a fresh element. + * Everywhere else the art is the subject, and it is drawn once. It + * used to be keyed by step, which remounts it and replays the draw: + * 2.6 seconds of the same mark erasing and redrawing itself on every + * Continue, saying something changed when nothing had. */ } { showPortrait ? ( ) : ( - + ) } diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-motion b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-motion new file mode 100644 index 000000000000..8f56558bcfc4 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-motion @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: stop the sheet blanking between steps and the panel artwork redrawing itself on each one. diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-motion b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-motion new file mode 100644 index 000000000000..575dd12cf7d7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-motion @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: smooth out the setup wizard's step transitions. From 11be9be927a25c452b99d96dbf2cd0dbff99ea29 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Tue, 29 Sep 2026 07:41:50 -0400 Subject: [PATCH 09/15] My Jetpack: centre the onboarding start screen again The start screen is one screen, not a step in a sequence, so it has no reason to sit in the block that holds the heading still across the steps that follow. Top-anchored in that block it read high: 236px of white above it and 471 below. It centres in the sheet now, the way the finish screen already does. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/styles.module.scss | 18 ++++++++++++++++++ .../onboarding-screen/wizard/wizard.tsx | 8 +++++++- .../fix-my-jetpack-onboarding-start-centre | 4 ++++ .../fix-my-jetpack-onboarding-start-centre | 4 ++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-start-centre create mode 100644 projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-start-centre diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss index a643ffd23632..e4c689f225c4 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/styles.module.scss @@ -1492,6 +1492,24 @@ $rail-row-min-height: 40px; * rather than not rendering them keeps the grid and the region landmarks intact * for the steps either side of it. */ + +/* + * The start screen is one screen rather than a step in a sequence, so it + * centres in the sheet instead of sitting in the block that holds the heading + * still across the steps that follow. In that block it was top-anchored and + * read high: 236px of white above it and 471 below. + */ +.layout--start { + + .panel-content { + display: flex; + flex-direction: column; + justify-content: center; + min-block-size: 100%; + padding-block-start: 0; + } +} + .layout--finish { .rail, diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx index 69d7bf05c313..2f585de78de0 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx @@ -376,7 +376,13 @@ export function Wizard( { exitUrl, dashboardUrl, site }: WizardProps ) { return ( -
+
{ /* * The sidebar region, as the Site Editor builds it: a NavigableRegion * holding the screen's exit control, title, and navigation. diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-start-centre b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-start-centre new file mode 100644 index 000000000000..7538c5915283 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-start-centre @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: centre the start screen in the sheet again. diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-start-centre b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-start-centre new file mode 100644 index 000000000000..6185e662eb52 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-start-centre @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: centre the setup wizard's first screen again. From 8c2bb426c016499b977d6b9ce0e45ffc68f8f518 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Tue, 29 Sep 2026 14:55:11 -0400 Subject: [PATCH 10/15] My Jetpack: centre each onboarding step in the sheet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The steps are not the same height — the site-type question is 508px and the feature list 670 — so the sheet carries 162px more empty space under the shorter one. That is a conservation law, not a bug in a number: while the heading holds its place across the step change, no block height, offset or clamp deletes those 162px. They can only be moved. So the shorter step spends them on itself. The block is the tallest step with the heading's offset above it and the same again below, every step stretches to fill it, and the answer rows take the surplus: 80px a row becomes 101. The list holds a seat open the size of the free-text field. Without it the rows absorb the field's height too, and the row you clicked to open the field jumps 45px out from under the pointer that chose it. With it, the field drops into the space that was already there and nothing moves. Measured on the live site at 800, 1255 and 1800: heading drift zero, the feature step centred to the pixel, and opening the free-text field moves nothing. Two corrections. The old comment claimed centring moved the heading 147px; measured, it is 81. And the block carried 65px of slack inherited from the height cap it replaced, which was 65px of white under every step for nothing. The stretch runs through named classes rather than a structural selector, because the content column also holds the connected notice and a bare child selector would have stretched that too. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/steps/choice-step.tsx | 4 +- .../wizard/steps/features-step.tsx | 2 +- .../wizard/styles.module.scss | 69 +++++++++++++++++-- .../update-my-jetpack-onboarding-centre | 4 ++ .../update-my-jetpack-onboarding-centre | 4 ++ 5 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-centre create mode 100644 projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-centre diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx index cf3407a0dbf3..112200d39b82 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx @@ -183,7 +183,7 @@ export function ChoiceStep( { const tabStop = chosen?.value ?? options[ 0 ]?.value; return ( - + { options.length > 0 && ( -
+
+ *` here also catches the connected notice. */ +.step-body { + flex-grow: 1; + min-block-size: 0; +} + +.step-answer { + display: flex; + flex-direction: column; + flex-grow: 1; + min-block-size: 0; +} + .layout--start { .panel-content { diff --git a/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-centre b/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-centre new file mode 100644 index 000000000000..5b363418b4c4 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-centre @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Onboarding: centre each step's content in the sheet. diff --git a/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-centre b/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-centre new file mode 100644 index 000000000000..49b08ef3f69f --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-centre @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +My Jetpack: centre the setup wizard's content. From cb26a37c30a9bebf30b2679119688b320149d055 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Tue, 29 Sep 2026 15:39:10 -0400 Subject: [PATCH 11/15] My Jetpack: clean up the onboarding wizard One real defect: a stale `.finish-row*` block was still in the stylesheet after the finish card was rebuilt, and its `option-cascade` animation bled onto the live rows. `--row-index` is never set on a finish `
  • `, so the delay it computed was invalid and every row fired at once. The card carries its own entrance now. The rest is removal. Six comments described code that had changed under them: an artwork share of 77% that is 68%, placeholder steps that are real, an option description said to be unrendered that renders, a breakpoint named as the panel's that is the rail's, and finish-wash scales given as fixed multiples now that they are shares of the viewport. Around thirty more were over the comment budget and are cut to it, and personal names and dates are out of the source entirely. The local `useReducedMotion` is gone in favour of the one in `@wordpress/compose`, which caches per window, drives `useSyncExternalStore` and handles a missing `matchMedia`. `site` is nullable end to end now. The page really does send null on the dashboard, where counting attachments is not worth its query, and the PHP `@return`, `global.d.ts`, the wizard's props and `hasPortrait` all said otherwise. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/connected-notice.tsx | 14 +- .../onboarding-screen/wizard/lib.ts | 30 +- .../onboarding-screen/wizard/panel-art.tsx | 21 +- .../wizard/site-portrait.tsx | 30 +- .../wizard/steps/choice-step.tsx | 16 +- .../wizard/steps/finish-step.tsx | 14 +- .../wizard/steps/start-step.tsx | 15 +- .../wizard/styles.module.scss | 299 ++++-------------- .../wizard/test/site-portrait.test.tsx | 7 +- .../wizard/test/smoke.test.tsx | 8 - .../wizard/use-reduced-motion.ts | 34 -- .../onboarding-screen/wizard/use-saved-run.ts | 10 +- .../wizard/use-setup-modules.ts | 18 +- .../onboarding-screen/wizard/use-site-shot.ts | 37 +-- .../onboarding-screen/wizard/wizard.tsx | 26 +- projects/packages/my-jetpack/global.d.ts | 3 +- .../my-jetpack/src/class-initializer.php | 2 +- .../php/Onboarding_Site_Portrait_Test.php | 5 - 18 files changed, 140 insertions(+), 449 deletions(-) delete mode 100644 projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/use-reduced-motion.ts diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx index e33aaea55b24..61b96139fa47 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx @@ -1,18 +1,15 @@ +import { useReducedMotion } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import { check } from '@wordpress/icons'; import { Icon, Text } from '@wordpress/ui'; import clsx from 'clsx'; import styles from './styles.module.scss'; -import { useReducedMotion } from './use-reduced-motion'; /** * The arrival moment, on the step the user lands on after connecting. * - * Connecting is the hardest thing in the flow and the likeliest to fail, and - * the ones who get through it used to land back here with nothing to say it - * worked. The mark blooms once, in the finish screen's own language at a - * smaller scale, and the line stays rather than fading: a confirmation that - * disappears on a timer is not a confirmation. + * The mark blooms once, in the finish screen's own language at a smaller scale. + * The line stays rather than fading: a confirmation on a timer is not one. * * @return The rendered notice. */ @@ -23,9 +20,8 @@ export function ConnectedNotice() {
    { /* - * Not rendered at all under reduced motion, which is a different - * render rather than a shorter animation; same call as the finish - * screen's, and the same reason it has to ask in JavaScript. + * Not rendered at all under reduced motion; see `.finish-wash` in + * the stylesheet. */ } { ! reduced && ( <> diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts index 0530fc701ce2..aa690051fa22 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts @@ -19,7 +19,7 @@ import { export interface WizardStepOption { value: string; label: string; - // Not rendered by the hairline row, which is label-only; kept for stage 3. + // The line under the label on a choice card. description: string; icon: typeof plus; // Opens a text field for an answer the list does not cover. @@ -52,7 +52,7 @@ export type WizardStepKind = 'start' | 'question' | 'features' | 'finish'; * A step, as the rail and the question column both read it. */ export interface WizardStepMeta { - // Stable across reorders: the React key, and the analytics name stage 2 reports. + // Stable across reorders: the React key, and how `siteTypeAnswer` finds its step. id: string; // Which component the shell renders for this step. kind: WizardStepKind; @@ -90,11 +90,9 @@ const UNKNOWN_CONNECTION_ERROR = 'unknown_error'; /** * The bounded code for a failed registration, safe to send to Tracks. * - * Either the server's own `WP_Error` code or, when the request never got as far - * as a parsed body, the name of the error class the API client threw - * (`JsonParseError`, `Api404Error`, `FetchNetworkError`, and so on). Both are - * fixed vocabularies. The error's `message` is deliberately not considered: - * it interpolates the server's prose and can carry the site's own URL. + * The server's own `WP_Error` code, or the name of the class the API client + * threw. The `message` is deliberately not considered: it interpolates the + * server's prose and can carry the site's own URL. * * @param error - The rejection from `handleRegisterSite`, or the stored error. * @return A slug from a fixed set, never free text. @@ -155,7 +153,7 @@ export interface WizardState { } /** - * The steps, in order. Placeholder content until stage 3 brings the real steps. + * The steps, in order. * * @return One entry per step, translated at call time. */ @@ -323,10 +321,8 @@ export function settleOnboarding( outcome: SettleOutcome ): Promise< unknown > { * Whether a module is switched on, given what the user has moved. * * The wizard recommends all six, so an untouched row is on even where the site - * has the module off — which is the whole point of offering Downtime Monitor, - * the one of the six that does not ship on. One function so the switch and the - * request cannot disagree, which they did: the row read as on while the request - * asked for no change, and the finish screen then said five of six. + * has the module off. One function, so the switch and the request cannot + * disagree — they did, and the finish screen then said five of six. * * @param wanted - What the user has moved, by slug. * @param slug - The module in question. @@ -354,14 +350,8 @@ export function siteTypeAnswer( state: WizardState ): string | undefined { /** * The line under the feature heading, per site type. One whole sentence each * rather than a name interpolated into a frame: a translator given "For %s" and - * a list of nouns cannot agree the article or the case. - * - * It claims only what the order does. All six are still offered and all six - * still start on, so "these matter most" is about what is at the top of the - * list, and nothing here says anything was left out. - * - * Each one is short enough to set on one line at the column's 470px. The - * longest, the business line, uses all of it, so a translation will wrap. + * a list of nouns cannot agree the article or the case. Each is short enough to + * set on one line at the column's 470px, so a translation will wrap. * * @return The line for each site type that has one, translated at call time. */ diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-art.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-art.tsx index aaa6c476f6d3..9920baab66a8 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-art.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/panel-art.tsx @@ -4,15 +4,9 @@ import styles from './styles.module.scss'; /** * The brand artwork's own geometry: 14 hairline strokes making the isometric - * Jetpack bolt inside two organic circles. - * - * Copied verbatim from the prototype's `components/onboarding/panel-art.tsx`, - * which inlined it from Layer_1.svg. It is hand-drawn brand art: the path data - * and the two stroke widths are not to be redrawn, rounded or simplified. - * - * The stroke colour is not here. The prototype writes `#48FF50` on every path; - * that value is `$brand-gradient-green-bright` in styles.module.scss, so the - * paths take `currentColor` and the stylesheet is the one place it lives. + * Jetpack bolt inside two organic circles. Hand-drawn brand art, copied + * verbatim — not to be redrawn, rounded or simplified. The colour is not here: + * the paths take `currentColor` so the stylesheet is the one place it lives. */ const ART_PATHS: { d: string; width: number }[] = [ { @@ -90,11 +84,10 @@ type PanelArtProps = { /** * The brand panel's artwork. * - * Each path's own length is measured and published as `--draw-length`, which the - * dash rules read. `pathLength` would be tidier, but Chrome only normalises - * against it for presentation attributes: a `stroke-dasharray` coming from a - * stylesheet stays in user units, so the whole bolt draws as a 1px dotted line - * at a third of a pixel wide and nothing appears on screen. + * Each path's length is measured and published as `--draw-length`, which the + * dash rules read. `pathLength` would be tidier, but Chrome normalises against + * it only for presentation attributes, so a stylesheet's dasharray stays in user + * units and the whole bolt draws as a 1px dotted line. * * @param props - The component props. * @param props.animate - Whether the paths draw themselves in. diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx index 19e21f1fee08..c0e040ae256d 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/site-portrait.tsx @@ -1,9 +1,9 @@ +import { useReducedMotion } from '@wordpress/compose'; import { createInterpolateElement } from '@wordpress/element'; import { _n, sprintf } from '@wordpress/i18n'; import clsx from 'clsx'; import { useEffect, useRef, useState } from 'react'; import styles from './styles.module.scss'; -import { useReducedMotion } from './use-reduced-motion'; import type { OnboardingSite } from './lib'; import type { ReactNode } from 'react'; @@ -46,14 +46,9 @@ function Lights() { /** * What this site has, one line each. * - * Whole sentences with the number inside them, marked up rather than split: a - * translator handed "posts published" on its own cannot tell what agrees with - * what, and several languages need the number to place the noun. - * - * A zero is left out. It is how an unmeasured field is spelled at least as - * often as it is a real count, and "0 posts published" on a site with posts is - * worse than saying nothing — which is what the prototype found on a site whose - * media endpoint answered 401. + * Whole sentences with the number marked up inside them, not split: a translator + * handed "posts published" alone cannot tell what agrees with what. A zero is + * left out, being how an unmeasured field is spelled as often as a real count. * * @param counts - What the page counted. * @return One entry per count worth showing. @@ -202,18 +197,9 @@ function StatRow( { text, value }: { text: string; value: number } ) { /** * This site, as a browser window in a receding stack, over what is in it. * - * The prototype's identity stage, and the one screen it shows this on: where we - * say what we read the site as and ask whether that is right. Ours asks the - * same question, so it is the same screen. - * - * The backs are blank rather than labelled. The prototype writes the site's - * feed URLs on them because its scan really read those pages; we read nothing, - * so a URL there would be a claim about a fetch that never happened. - * - * Hidden from the accessibility tree in full. Every fact in it is decorative - * here — the question being asked is on the left, the picture is of a site the - * user is sitting inside, and read aloud the counts are four numbers with no - * bearing on the answer. + * The backs are blank: the prototype labels them with feed URLs its scan really + * read, and we read nothing. Hidden from the accessibility tree in full, because + * every fact in it is decorative beside the question being asked on the left. * * @param props - The component props. * @param props.site - What the page told us about this site. @@ -285,6 +271,6 @@ export function SitePortrait( { site, shot }: { site: OnboardingSite; shot: stri * @param site - What the page told us, if anything. * @return True when there is a picture coming. */ -export function hasPortrait( site: OnboardingSite | undefined ): site is OnboardingSite { +export function hasPortrait( site: OnboardingSite | null | undefined ): site is OnboardingSite { return Boolean( site?.canPhotograph ); } diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx index 112200d39b82..966b86836905 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/choice-step.tsx @@ -38,13 +38,10 @@ const HORIZONTAL_STEP_BY_KEY: Record< string, number > = { /** * The field an option opens, and the only thing that mounts with it. * - * Focus is moved here on mount rather than by `autoFocus`, and only when the row - * was activated deliberately. Arrowing onto the row merely previews it, and - * taking focus then is a trap: the arrow keys belong to the radio group, so once - * they land in a text field there is no way back up the list. - * - * The ref sits on the wrapper and the input is found inside it, because the - * control owns its own markup and forwarding is not part of its contract. + * Focus moves here on mount only when the row was activated deliberately: + * arrowing onto it merely previews it, and the arrow keys belong to the radio + * group, so a field that takes focus then is a trap. The ref sits on the + * wrapper because the control owns its own markup. * * @param props - The component props. * @param props.value - What has been typed so far. @@ -234,9 +231,8 @@ export function ChoiceStep( { { /* - * The line under the label was written and translated and then - * never rendered. It is what tells someone whose site is two of - * these which one we mean. + * The line under the label is what tells someone whose site is + * two of these which one we mean. */ }
    ) } diff --git a/projects/packages/my-jetpack/_inc/components/connection-status-card/test/component.tsx b/projects/packages/my-jetpack/_inc/components/connection-status-card/test/component.tsx index a184bc1e1f7c..74a06da13f65 100644 --- a/projects/packages/my-jetpack/_inc/components/connection-status-card/test/component.tsx +++ b/projects/packages/my-jetpack/_inc/components/connection-status-card/test/component.tsx @@ -169,7 +169,25 @@ describe( 'ConnectionStatusCard', () => { asAdmin(); setup(); expect( screen.getByText( 'Site not connected' ) ).toBeInTheDocument(); - expect( screen.getByText( 'Connect your site with one click.' ) ).toBeInTheDocument(); + expect( screen.getByText( 'Connect your site to use Jetpack.' ) ).toBeInTheDocument(); + } ); + + it( 'offers the promised click, as a route to the connect screen', () => { + asAdmin(); + setup(); + expect( screen.getByRole( 'link', { name: 'Connect your site' } ) ).toHaveAttribute( + 'href', + '#/connection?skip_pricing=true' + ); + } ); + + it( 'states the standing as text, with no disconnect to offer', () => { + asAdmin(); + setup(); + expect( screen.getByText( 'Site not connected' ) ).toBeInTheDocument(); + expect( + screen.queryByRole( 'button', { name: /Site not connected/ } ) + ).not.toBeInTheDocument(); } ); it( 'points a user who cannot connect at an admin instead', () => { @@ -178,7 +196,8 @@ describe( 'ConnectionStatusCard', () => { expect( screen.getByText( 'A site admin will need to connect this site to Jetpack.' ) ).toBeInTheDocument(); - expect( screen.queryByText( 'Connect your site with one click.' ) ).not.toBeInTheDocument(); + // And offers them no route to a screen that would turn them away. + expect( screen.queryByRole( 'link', { name: 'Connect your site' } ) ).not.toBeInTheDocument(); } ); } ); @@ -197,7 +216,7 @@ describe( 'ConnectionStatusCard', () => { it( 'renders the correct copy for the site connection line item', () => { asAdmin(); setup(); - expect( screen.getByText( 'Connect your site with one click.' ) ).toBeInTheDocument(); + expect( screen.getByText( 'Connect your site to use Jetpack.' ) ).toBeInTheDocument(); } ); } ); @@ -551,10 +570,12 @@ describe( 'ConnectionStatusCard', () => { global.JetpackScriptData.site.host = 'standard'; } ); - it( 'disables the manage connection button for WoA connection owners', () => { + it( 'states the standing as text, since WoA owners cannot manage the connection', () => { setup(); - const button = screen.getByRole( 'button', { name: /Site and account connected/ } ); - expect( button ).toBeDisabled(); + expect( screen.getByText( 'Site and account connected' ) ).toBeInTheDocument(); + expect( + screen.queryByRole( 'button', { name: /Site and account connected/ } ) + ).not.toBeInTheDocument(); } ); } ); @@ -726,10 +747,10 @@ describe( 'ConnectionStatusCard', () => { ); }; - it( 'disables the manage connection button for non-admins', () => { + it( 'states the standing as text, since non-admins cannot manage the connection', () => { setup(); - const button = screen.getByRole( 'button', { name: /Site connected/ } ); - expect( button ).toBeDisabled(); + expect( screen.getByText( 'Site connected' ) ).toBeInTheDocument(); + expect( screen.queryByRole( 'button', { name: /Site connected/ } ) ).not.toBeInTheDocument(); } ); } ); @@ -757,10 +778,10 @@ describe( 'ConnectionStatusCard', () => { global.JetpackScriptData.user.current_user.capabilities = {}; } ); - it( 'disables the manage connection button since WoA sites cannot be disconnected', () => { + it( 'states the standing as text, since WoA sites cannot be disconnected', () => { setup(); - const button = screen.getByRole( 'button', { name: /Site connected/ } ); - expect( button ).toBeDisabled(); + expect( screen.getByText( 'Site connected' ) ).toBeInTheDocument(); + expect( screen.queryByRole( 'button', { name: /Site connected/ } ) ).not.toBeInTheDocument(); } ); } ); } ); diff --git a/projects/packages/my-jetpack/_inc/components/connection-status-card/test/use-connection-state.test.ts b/projects/packages/my-jetpack/_inc/components/connection-status-card/test/use-connection-state.test.ts index 708d77aadc2e..c0b62af0e3d1 100644 --- a/projects/packages/my-jetpack/_inc/components/connection-status-card/test/use-connection-state.test.ts +++ b/projects/packages/my-jetpack/_inc/components/connection-status-card/test/use-connection-state.test.ts @@ -21,12 +21,14 @@ interface StoreSelect { } interface StoreOverrides { + isRegistered?: boolean; isUserConnected?: boolean; connectionErrors?: ConnectionErrorMap; connectionOwner?: ConnectionOwner | null; } const setConnectionStore = ( { + isRegistered = true, isUserConnected = false, connectionErrors = {}, connectionOwner = null, @@ -39,7 +41,7 @@ const setConnectionStore = ( { jest .spyOn( storeSelect, 'getConnectionStatus' ) .mockReset() - .mockReturnValue( { isRegistered: true, isUserConnected, hasConnectedOwner: true } ); + .mockReturnValue( { isRegistered, isUserConnected, hasConnectedOwner: true } ); jest .spyOn( storeSelect, 'getUserConnectionData' ) .mockReset() @@ -99,6 +101,38 @@ const renderConnectionState = () => { wrapper: Providers } ); +describe( 'useConnectionState — before the site is registered', () => { + afterEach( () => { + global.JetpackScriptData.user.current_user.capabilities = { manage_options: true }; + } ); + + it( 'names the connect-site action, and promises no more clicks than it takes', () => { + setConnectionStore( { isRegistered: false } ); + + const { result } = renderConnectionState(); + + expect( result.current ).toEqual( { + label: 'Site not connected', + description: 'Connect your site to use Jetpack.', + action: 'CONNECT_SITE', + status: 'error', + } ); + } ); + + it( 'names no action for a user who cannot connect the site', () => { + global.JetpackScriptData.user.current_user.capabilities = {}; + setConnectionStore( { isRegistered: false } ); + + const { result } = renderConnectionState(); + + expect( result.current ).toEqual( { + label: 'Site not connected', + description: 'A site admin will need to connect this site to Jetpack.', + status: 'error', + } ); + } ); +} ); + // The tint is the only sign of the error here, so it is the package's rating, not a flat 'error'. describe( 'useConnectionState — status while the account is still to be connected', () => { it( 'softens a break only the owner can repair to a warning', () => { diff --git a/projects/packages/my-jetpack/_inc/components/connection-status-card/use-connection-state.ts b/projects/packages/my-jetpack/_inc/components/connection-status-card/use-connection-state.ts index b53a587b0473..7069bc762c54 100644 --- a/projects/packages/my-jetpack/_inc/components/connection-status-card/use-connection-state.ts +++ b/projects/packages/my-jetpack/_inc/components/connection-status-card/use-connection-state.ts @@ -49,7 +49,7 @@ export function useConnectionState( error: ConnectionErrorStanding ): Connection return { label: __( 'Site not connected', 'jetpack-my-jetpack' ), - description: __( 'Connect your site with one click.', 'jetpack-my-jetpack' ), + description: __( 'Connect your site to use Jetpack.', 'jetpack-my-jetpack' ), action: 'CONNECT_SITE', status: 'error', }; diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-connection-card-disconnected b/projects/packages/my-jetpack/changelog/fix-my-jetpack-connection-card-disconnected new file mode 100644 index 000000000000..0d4af317df5a --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-connection-card-disconnected @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Connection: link the disconnected card to the connect screen, and stop it offering to disconnect a site that is not connected. diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-connect-handlers b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-connect-handlers new file mode 100644 index 000000000000..0ae57ed7edbe --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-connect-handlers @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: interrupt My Jetpack only, so Jetpack's own connection pages finish what they started, and stop sending a registered site with no connected WordPress.com account into a setup screen it has no way out of. The connection card it lands on instead now says what connecting is for. diff --git a/projects/packages/my-jetpack/src/class-initializer.php b/projects/packages/my-jetpack/src/class-initializer.php index 6c65ac850974..62bce38cac14 100644 --- a/projects/packages/my-jetpack/src/class-initializer.php +++ b/projects/packages/my-jetpack/src/class-initializer.php @@ -164,10 +164,6 @@ public static function init() { add_action( 'admin_init', array( __CLASS__, 'setup_historically_active_jetpack_modules_sync' ) ); - /* - * On every Jetpack screen rather than only on My Jetpack, so someone who has - * just activated the plugin meets setup wherever they go first. - */ add_action( 'admin_init', array( __CLASS__, 'maybe_redirect_to_onboarding' ) ); // Nothing else gets to talk over the takeover. See both methods for why it @@ -258,8 +254,7 @@ public static function admin_init() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No nonce needed for redirect flow control $step = isset( $_GET['step'] ) ? sanitize_text_field( wp_unslash( $_GET['step'] ) ) : ''; - // The redirect itself runs on `admin_init` for every Jetpack screen, which is - // earlier than this and covers this page too. + // The redirect into setup has already run, on `admin_init`. // If the user reaches the onboarding page, add a class to the body if ( $step === 'onboarding' ) { @@ -274,10 +269,8 @@ public static function admin_init() { /** * The admin screens the onboarding takeover may interrupt. * - * The Jetpack plugin's own pages, not every plugin whose page happens to start - * with `jetpack-`. Boost, Protect, Social and the rest each ship a connection - * screen of their own, and taking those over is their teams' call, not ours. - * The filter is how they would opt in. + * My Jetpack only: `admin_init` runs before `page=jetpack` answers `action=register` + * and `connect_url_redirect`, so redirecting from there drops their arguments. * * @internal Not part of the package's public API. * @@ -291,10 +284,7 @@ public static function get_onboarding_screens() { * * @param string[] $screens Values of the `page` query arg. */ - return (array) apply_filters( - 'jetpack_my_jetpack_onboarding_screens', - array( 'my-jetpack', 'jetpack', 'jetpack_modules', 'stats' ) - ); + return (array) apply_filters( 'jetpack_my_jetpack_onboarding_screens', array( 'my-jetpack' ) ); } /** @@ -330,16 +320,19 @@ public static function is_onboarding_settled() { } /** - * Send the user into setup when they land on a Jetpack screen without one. + * Send the user into setup when they land on My Jetpack without one. * - * Hooked on `admin_init` rather than on the My Jetpack page load, so someone who - * has just activated the plugin meets setup on whichever Jetpack screen they open - * first. It runs on ordinary page views only: a form post or an async request that - * happened to carry the page argument must not be answered with a redirect. + * Hooked on `admin_init` rather than the page load, so a fresh activation meets setup + * on the way in, and only for an ordinary GET: a form post must not be redirected. * * @return void */ public static function maybe_redirect_to_onboarding() { + // Network admin links to the network's own Jetpack pages, and setup is per site. + if ( is_network_admin() ) { + return; + } + if ( wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { return; } @@ -355,13 +348,21 @@ public static function maybe_redirect_to_onboarding() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No nonce needed for redirect flow control $step = isset( $_GET['step'] ) ? sanitize_text_field( wp_unslash( $_GET['step'] ) ) : ''; + $wizard_enabled = self::is_onboarding_wizard_enabled(); + $connection = new Connection_Manager(); + + // Only the wizard connects a user, so only it may count a site-only connection as + // unfinished setup. The single screen can only register the site, so asking it for + // an owner leaves that site on a screen with no way back out. + $connection_done = $wizard_enabled ? $connection->has_connected_owner() : $connection->is_connected(); + // Onboarding's only action is the connect request, which answers a user // without `jetpack_connect` with a 403. $redirect_args = self::get_onboarding_redirect_args( $step, - ( new Connection_Manager() )->is_connected(), + $connection_done, self::is_onboarding_available() && current_user_can( 'jetpack_connect' ), - self::is_onboarding_wizard_enabled(), + $wizard_enabled, self::is_onboarding_settled() ); @@ -433,20 +434,21 @@ public static function get_partner_coupon_screen() { * @internal Not part of the package's public API. * * @param string $step The current `step` query param. - * @param bool $is_connected Whether the site is connected to WordPress.com. + * @param bool $connection_done Whether the connection the takeover asks for is in place: + * a connected owner with the wizard, a connected site without it. * @param bool $onboarding_available Whether the onboarding flow is available on this site. * @param bool $wizard_enabled Whether the takeover renders the setup wizard. * @param bool $is_settled Whether this user has already finished or skipped setup. * @return array|null Query args for the redirect, or null to stay on the current page. */ - public static function get_onboarding_redirect_args( $step, $is_connected, $onboarding_available, $wizard_enabled = false, $is_settled = false ) { + public static function get_onboarding_redirect_args( $step, $connection_done, $onboarding_available, $wizard_enabled = false, $is_settled = false ) { /* * Only the automatic redirect is suppressed once setup is settled. Asking for * the onboarding page by its own URL still works, so someone who skipped can * go back to it, and so can a second admin the site-wide flag does not cover. */ - if ( $onboarding_available && ! $is_connected && ! $is_settled && $step !== 'onboarding' ) { - // Redirect to onboarding if not connected + if ( $onboarding_available && ! $connection_done && ! $is_settled && $step !== 'onboarding' ) { + // The connection setup asks for is not in place, so setup is unfinished. return array( 'page' => 'my-jetpack', 'step' => 'onboarding', @@ -454,13 +456,13 @@ public static function get_onboarding_redirect_args( $step, $is_connected, $onbo } // The wizard connects mid-flow: the user authorizes on WordPress.com and is sent - // back here to finish setup, so a connected user on it has not finished. - if ( $step === 'onboarding' && $is_connected && $onboarding_available && $wizard_enabled ) { + // back here to finish setup, so arriving connected is not the same as finishing. + if ( $step === 'onboarding' && $connection_done && $onboarding_available && $wizard_enabled ) { return null; } - if ( $step === 'onboarding' && ( ! $onboarding_available || $is_connected ) ) { - // Redirect away from onboarding if already connected or onboarding is not available on this site + if ( $step === 'onboarding' && ( ! $onboarding_available || $connection_done ) ) { + // Nothing left to set up here, or onboarding does not apply on this site. return array( 'page' => 'my-jetpack' ); } @@ -517,7 +519,7 @@ public static function hide_onboarding_jitms( $show, $screen_id ) { // phpcs:ign * @return string The modified body classes. */ public static function add_onboarding_admin_body_class( $classes ) { - $classes .= 'jetpack-admin-full-screen'; + $classes .= ' jetpack-admin-full-screen'; return $classes; } @@ -592,7 +594,34 @@ public static function is_onboarding_wizard_enabled() { return false; } - return Feature_Flags::is_enabled( self::ONBOARDING_WIZARD_FEATURE_FLAG ); + if ( ! Feature_Flags::is_enabled( self::ONBOARDING_WIZARD_FEATURE_FLAG ) ) { + return false; + } + + // The wizard registers the site at its own first step, which writes the marker + // below, so asking again on the way back from WordPress.com would drop someone + // out of a run already under way. + if ( ( new Connection_Manager() )->is_connected() ) { + return true; + } + + return self::has_never_registered_jetpack(); + } + + /** + * Whether the Jetpack plugin has never registered this site. + * + * `unique_registrations` is written on `jetpack_site_registered` by the Jetpack plugin + * alone, so a site that has only ever run a standalone plugin still reads as new here. + * + * @internal Not part of the package's public API. + * + * @since $$next-version$$ + * + * @return bool + */ + public static function has_never_registered_jetpack() { + return ! \Jetpack_Options::get_option( 'unique_registrations' ); } /** @@ -1178,7 +1207,11 @@ public static function register_rest_endpoints() { new REST_Zendesk_Chat(); ( new REST_Jetpack_AI_JWT() )->register_rest_route(); new REST_Recommendations_Evaluation(); - ( new REST_Onboarding() )->register_rest_routes(); + + // There is nothing to settle where the wizard never renders. + if ( self::is_onboarding_wizard_enabled() ) { + ( new REST_Onboarding() )->register_rest_routes(); + } if ( self::is_features_tab_enabled() ) { ( new REST_Main_Features() )->register_rest_routes(); diff --git a/projects/packages/my-jetpack/tests/php/Initializer_Test.php b/projects/packages/my-jetpack/tests/php/Initializer_Test.php index 5a297ddf6d17..e525a7095394 100644 --- a/projects/packages/my-jetpack/tests/php/Initializer_Test.php +++ b/projects/packages/my-jetpack/tests/php/Initializer_Test.php @@ -48,14 +48,33 @@ public function tear_down() { private function reset_state() { Constants::clear_constants(); StatusCache::clear(); - unset( $_GET['step'], $_GET['showCouponRedemption'] ); + unset( + $_GET['page'], + $_GET['step'], + $_GET['showCouponRedemption'], + $_GET['action'], + $_GET['connect_url_redirect'], + $_GET['from'], + $_GET['skip_pricing'], + $_GET['redirect_after_auth'] + ); wp_set_current_user( 0 ); - Jetpack_Options::delete_option( array( 'id', 'blog_token', 'master_user', 'user_tokens', Partner_Coupon::$coupon_option ) ); + Jetpack_Options::delete_option( + array( + 'id', + 'blog_token', + 'master_user', + 'user_tokens', + 'unique_registrations', + Partner_Coupon::$coupon_option, + ) + ); remove_all_filters( 'jetpack_partner_coupon_supported_partners' ); remove_all_filters( 'jetpack_partner_coupon_supported_presets' ); remove_all_filters( 'jetpack_partner_coupon_products' ); remove_all_filters( 'jetpack_my_jetpack_should_initialize' ); remove_all_filters( 'jetpack_offline_mode' ); + remove_all_filters( 'jetpack_feature_flag_enabled_my-jetpack-onboarding-wizard' ); // Connection_Manager memoizes is_connected() in a process-wide static that // WorDBless teardown does not reset. The admin_init tests that depend on that @@ -250,15 +269,15 @@ public static function provide_settled_onboarding_cases() { * * @dataProvider provide_settled_onboarding_cases * - * @param string $step The `step` query param. - * @param bool $is_connected Whether the site is connected. - * @param array|null $expected Expected redirect query args, or null to stay. + * @param string $step The `step` query param. + * @param bool $connection_done Whether the connection setup asks for is in place. + * @param array|null $expected Expected redirect query args, or null to stay. */ #[DataProvider( 'provide_settled_onboarding_cases' )] - public function test_settled_onboarding_is_not_offered_again( $step, $is_connected, $expected ) { + public function test_settled_onboarding_is_not_offered_again( $step, $connection_done, $expected ) { $this->assertSame( $expected, - Initializer::get_onboarding_redirect_args( $step, $is_connected, true, false, true ) + Initializer::get_onboarding_redirect_args( $step, $connection_done, true, false, true ) ); } @@ -355,18 +374,23 @@ public function test_jitms_are_hidden_on_the_takeover_only() { } /** - * The takeover reaches the Jetpack screens, and only those. + * The full-screen class is appended, not glued onto whatever came before it. */ - public function test_onboarding_screens_cover_jetpacks_own_pages() { - $screens = Initializer::get_onboarding_screens(); + public function test_the_full_screen_body_class_survives_an_earlier_filter() { + $this->assertSame( + 'wp-admin jetpack-admin-full-screen', + Initializer::add_onboarding_admin_body_class( 'wp-admin' ) + ); + } - $this->assertContains( 'my-jetpack', $screens ); - $this->assertContains( 'jetpack', $screens ); + /** + * The takeover reaches My Jetpack and nothing else, with the flag on or off. + */ + public function test_the_takeover_reaches_my_jetpack_only() { + $this->assertSame( array( 'my-jetpack' ), Initializer::get_onboarding_screens() ); - // The standalone products ship their own connection screens, so taking those - // over is their teams' call. The filter is how they would opt in. - $this->assertNotContains( 'jetpack-boost', $screens ); - $this->assertNotContains( 'jetpack-protect', $screens ); + $this->enable_wizard_flag(); + $this->assertSame( array( 'my-jetpack' ), Initializer::get_onboarding_screens() ); add_filter( 'jetpack_my_jetpack_onboarding_screens', fn () => array( 'jetpack-boost' ) ); $this->assertSame( array( 'jetpack-boost' ), Initializer::get_onboarding_screens() ); @@ -380,19 +404,19 @@ public function test_onboarding_screens_cover_jetpacks_own_pages() { * @dataProvider provide_onboarding_redirect_cases * * @param string $step The `step` query param. - * @param bool $is_connected Whether the site is connected. + * @param bool $connection_done Whether the connection setup asks for is in place. * @param bool $onboarding_available Whether onboarding is available on this site. * @param bool $wizard_enabled Whether the takeover renders the wizard. * @param array|null $expected Expected redirect query args, or null to stay. */ #[DataProvider( 'provide_onboarding_redirect_cases' )] - public function test_get_onboarding_redirect_args( $step, $is_connected, $onboarding_available, $wizard_enabled, $expected ) { - $this->assertSame( $expected, Initializer::get_onboarding_redirect_args( $step, $is_connected, $onboarding_available, $wizard_enabled ) ); + public function test_get_onboarding_redirect_args( $step, $connection_done, $onboarding_available, $wizard_enabled, $expected ) { + $this->assertSame( $expected, Initializer::get_onboarding_redirect_args( $step, $connection_done, $onboarding_available, $wizard_enabled ) ); if ( ! $wizard_enabled ) { // Omitting the argument has to decide exactly as passing it false does, // so every existing caller keeps its behaviour. - $this->assertSame( $expected, Initializer::get_onboarding_redirect_args( $step, $is_connected, $onboarding_available ) ); + $this->assertSame( $expected, Initializer::get_onboarding_redirect_args( $step, $connection_done, $onboarding_available ) ); } } @@ -560,6 +584,307 @@ public function test_admin_init_bounces_a_user_who_cannot_connect_off_an_onboard $this->assertStringNotContainsString( 'step=onboarding', $location ); } + /** + * The route that settles setup only exists where the wizard does. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_the_settle_route_is_registered_only_with_the_wizard() { + $this->assertArrayNotHasKey( '/my-jetpack/v1/site/onboarding/settled', $this->capture_rest_routes() ); + + $this->enable_wizard_flag(); + + $this->assertArrayHasKey( '/my-jetpack/v1/site/onboarding/settled', $this->capture_rest_routes() ); + } + + /** + * Register My Jetpack's REST routes against a fresh server and return them. + * + * @return array The registered routes, keyed by path. + */ + private function capture_rest_routes() { + $register = array( Initializer::class, 'register_rest_endpoints' ); + // A fresh server, and through the action: core warns about routes registered + // anywhere else, and the warning fails the run. + $GLOBALS['wp_rest_server'] = null; + add_action( 'rest_api_init', $register ); + $routes = rest_get_server()->get_routes(); + remove_action( 'rest_api_init', $register ); + + return $routes; + } + + /** + * A plain visit to the Jetpack dashboard is not ours to take over, flag on. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_a_plain_jetpack_page_visit_alone() { + $this->log_in_as_admin(); + $this->enable_wizard_flag(); + $_GET['page'] = 'jetpack'; + + $this->assertNull( $this->capture_onboarding_redirect() ); + } + + /** + * With the flag off, page=jetpack is not ours to take over either. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_the_jetpack_page_alone_without_the_wizard() { + $this->log_in_as_admin(); + $_GET['page'] = 'jetpack'; + + $this->assertNull( $this->capture_onboarding_redirect() ); + } + + /** + * Network admin is left alone: its Jetpack links are plain and belong to the network. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_network_admin_alone() { + $this->log_in_as_admin(); + $this->enable_wizard_flag(); + unset( $GLOBALS['current_screen'] ); + define( 'WP_NETWORK_ADMIN', true ); + + $this->assertTrue( is_network_admin() ); + $this->assertNull( $this->capture_onboarding_redirect() ); + } + + /** + * `action=register` belongs to Jetpack::admin_page_load(), which runs on a later hook. + * + * Answering it here sends an unregistered site to onboarding instead of to + * WordPress.com, and rebuilds the URL without the `redirect` and `from` it carried. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_a_register_request_to_the_jetpack_plugin() { + $this->log_in_as_admin(); + $this->enable_wizard_flag(); + $_GET['page'] = 'jetpack'; + $_GET['action'] = 'register'; + $_GET['from'] = 'jetpack-settings'; + + $this->assertNull( $this->capture_onboarding_redirect() ); + } + + /** + * `connect_url_redirect` belongs to the connection package's Webhooks, likewise. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_a_connect_url_redirect_to_the_webhooks() { + $this->log_in_as_admin(); + $this->enable_wizard_flag(); + $_GET['page'] = 'jetpack'; + $_GET['connect_url_redirect'] = '1'; + $_GET['from'] = 'checkout'; + $_GET['skip_pricing'] = '1'; + $_GET['redirect_after_auth'] = 'https://example.org/wp-admin/admin.php?page=jetpack'; + + $this->assertNull( $this->capture_onboarding_redirect() ); + } + + /** + * My Jetpack's own arguments must not call off the redirect. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_still_redirects_my_jetpack_carrying_other_args() { + $this->log_in_as_admin(); + $_GET['page'] = 'my-jetpack'; + $_GET['showCouponRedemption'] = '1'; + + $location = $this->capture_onboarding_redirect(); + + $this->assertNotNull( $location, 'Expected My Jetpack to stay exempt.' ); + $this->assertStringContainsString( 'step=onboarding', $location ); + } + + /** + * A site only a standalone plugin has registered still gets the wizard. + * + * The gate reads `unique_registrations`, which the Jetpack plugin alone writes, so the + * blog ID Boost, Protect or Social left behind is not Jetpack history. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_the_wizard_runs_for_a_standalone_plugin_user() { + $this->enable_wizard_flag(); + // A blog ID with no token: registered by a standalone plugin, not connected now. + Jetpack_Options::update_option( 'id', 1234 ); + ( new Connection_Manager() )->reset_connection_status(); + + $this->assertTrue( Initializer::has_never_registered_jetpack() ); + $this->assertTrue( Initializer::is_onboarding_wizard_enabled() ); + $this->assertNotNull( Initializer::get_onboarding_wizard_state() ); + } + + /** + * A site the Jetpack plugin has registered before does not get the wizard. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_a_previous_jetpack_registration_closes_the_wizard() { + $this->enable_wizard_flag(); + Jetpack_Options::update_option( 'unique_registrations', 2 ); + + $this->assertFalse( Initializer::has_never_registered_jetpack() ); + $this->assertFalse( Initializer::is_onboarding_wizard_enabled() ); + $this->assertNull( Initializer::get_onboarding_wizard_state() ); + } + + /** + * Connecting mid-run does not close the wizard on the user doing it. + * + * The wizard registers the site at its first step, and registration is where the + * Jetpack plugin counts it. Without the connected site exempting itself, the trip back + * from WordPress.com would land on the plain connection screen instead of step two. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_connecting_mid_run_does_not_close_the_wizard() { + $user_id = $this->log_in_as_admin(); + $this->enable_wizard_flag(); + $this->connect_owner( $user_id ); + Jetpack_Options::update_option( 'unique_registrations', 1 ); + + $this->assertFalse( Initializer::has_never_registered_jetpack() ); + $this->assertTrue( Initializer::is_onboarding_wizard_enabled() ); + $this->assertNotNull( Initializer::get_onboarding_wizard_state() ); + } + + /** + * A site-only connection is not a finished setup, so the user is sent back into it. + * + * Leaving at the WordPress.com stage registers the site and connects nobody, which + * `is_connected()` reports as connected for good. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_sends_a_site_only_connection_back_into_setup() { + $this->log_in_as_admin(); + $this->enable_wizard_flag(); + $this->connect_site_only(); + + $this->assertTrue( ( new Connection_Manager() )->is_connected() ); + $this->assertFalse( ( new Connection_Manager() )->has_connected_owner() ); + + $location = $this->capture_onboarding_redirect(); + + $this->assertNotNull( $location, 'Expected a redirect back into setup.' ); + $this->assertStringContainsString( 'step=onboarding', $location ); + } + + /** + * With the wizard off, the same site-only connection is left where it is. + * + * The single screen's one control registers a site that is already registered, and it + * hides the admin menu, the toolbar and the footer, so arriving there is a dead end. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_a_site_only_connection_alone_without_the_wizard() { + $this->log_in_as_admin(); + $this->connect_site_only(); + + $this->assertFalse( Initializer::is_onboarding_wizard_enabled() ); + $this->assertTrue( ( new Connection_Manager() )->is_connected() ); + $this->assertFalse( ( new Connection_Manager() )->has_connected_owner() ); + + $this->assertNull( $this->capture_onboarding_redirect() ); + } + + /** + * An onboarding request on that site is sent home, so nobody stays stranded on it. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_bounces_a_site_only_connection_out_of_setup_without_the_wizard() { + $this->log_in_as_admin(); + $this->connect_site_only(); + $_GET['step'] = 'onboarding'; + + $location = $this->capture_onboarding_redirect(); + + $this->assertNotNull( $location, 'Expected a redirect out of setup.' ); + $this->assertStringContainsString( 'page=my-jetpack', $location ); + $this->assertStringNotContainsString( 'step=onboarding', $location ); + } + + /** + * A connection whose owner was removed is left alone too, with the wizard off. + * + * The owner resolves through `get_userdata()`, so deleting that user makes a fully + * connected site answer no, on any host and not just the Atomic one the wizard's + * gate describes. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + #[RunInSeparateProcess] + #[PreserveGlobalState( false )] + public function test_admin_init_leaves_a_connection_without_an_owner_alone_without_the_wizard() { + $this->log_in_as_admin(); + // Reporting the missing owner is a request to WordPress.com. + $this->block_http(); + $removed_id = 4242; + Jetpack_Options::update_option( 'id', 1234 ); + Jetpack_Options::update_option( 'blog_token', 'asdasd.123123' ); + Jetpack_Options::update_option( 'master_user', $removed_id ); + Jetpack_Options::update_option( 'user_tokens', array( $removed_id => "honey.badger.$removed_id" ) ); + ( new Connection_Manager() )->reset_connection_status(); + + $this->assertFalse( get_userdata( $removed_id ) ); + $this->assertTrue( ( new Connection_Manager() )->is_connected() ); + $this->assertFalse( ( new Connection_Manager() )->has_connected_owner() ); + + $this->assertNull( $this->capture_onboarding_redirect() ); + } + /** * Run Initializer::admin_init() and capture the redirect it attempts. * @@ -580,8 +905,7 @@ function ( $redirect_location ) use ( &$location ) { }; $trigger = $trigger === null ? array( Initializer::class, 'maybe_redirect_to_onboarding' ) : $trigger; - // The redirect now runs for every Jetpack screen rather than only on the - // My Jetpack page load, so it checks both before deciding anything. + // The redirect reads `page` and answers nothing but a GET. $_GET['page'] ??= 'my-jetpack'; $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -859,6 +1183,15 @@ static function () { Jetpack_Options::update_option( Partner_Coupon::$coupon_option, 'JPTST_JPTA_abc123' ); } + /** + * Register the site and connect nobody: the state leaving setup early produces. + */ + private function connect_site_only() { + Jetpack_Options::update_option( 'id', 1234 ); + Jetpack_Options::update_option( 'blog_token', 'asdasd.123123' ); + ( new Connection_Manager() )->reset_connection_status(); + } + /** * Register the site and connect the given user as its owner. * diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-connection-card-disconnected b/projects/plugins/jetpack/changelog/fix-my-jetpack-connection-card-disconnected new file mode 100644 index 000000000000..63b4c013d0c2 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-connection-card-disconnected @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: link the disconnected connection card to the connect screen, and stop it offering to disconnect a site that is not connected. diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-connect-handlers b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-connect-handlers new file mode 100644 index 000000000000..49dc1a344807 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-connect-handlers @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: setup no longer interrupts the Jetpack connection flow, and no longer traps a site that is registered without a connected WordPress.com account on a setup screen with no way out. The connection card it lands on instead now says what connecting is for. From 1b703aa02e2562577af5eb6460133b6a3cfee347 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Sun, 4 Oct 2026 22:41:34 -0400 Subject: [PATCH 15/15] My Jetpack: make every way out of the wizard record the same thing Three exits, three different behaviours, and one of them lost work. - A modified or middle click on Skip setup recorded the run as skipped and deleted the saved run while the user was still on the wizard in that tab. React state kept the step on screen, so the loss only showed on the next reload, which restarted at step 0 and was never offered setup again. Opening a link elsewhere is not leaving, so those gestures now change nothing at all. - The rail's exit had no handler, so leaving by it recorded nothing and parked the user on wp-admin, the one screen the takeover does not watch. It settles like the footer's. - The rail and the finish screen's secondary exit shared a name while doing different things, and the name was wrong for where they go. Both now read "Back to your WordPress site". Also: the finish screen's tally pluralised on the first count and hung its verb over the second, so one branch could read "1 feature was switched on and 2 switched off". Each count now declines its own noun. The step's unreachable Finish branch is gone, along with the helper it was the last caller of. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01ReATUyBCovcuj1bAfZ4VNJ --- .../wizard/connected-notice.tsx | 2 +- .../onboarding-screen/wizard/lib.ts | 10 - .../wizard/steps/finish-step.tsx | 72 +++--- .../wizard/test/smoke.test.tsx | 213 +++++++++++++++--- .../onboarding-screen/wizard/wizard.tsx | 103 ++++----- .../fix-my-jetpack-onboarding-skip-failure | 4 + ...pdate-my-jetpack-onboarding-devin-feedback | 4 + .../fix-my-jetpack-onboarding-skip-failure | 4 + ...pdate-my-jetpack-onboarding-devin-feedback | 4 + 9 files changed, 293 insertions(+), 123 deletions(-) create mode 100644 projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-skip-failure create mode 100644 projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-devin-feedback create mode 100644 projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-skip-failure create mode 100644 projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-devin-feedback diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx index 61b96139fa47..0ece11824f39 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/connected-notice.tsx @@ -39,7 +39,7 @@ export function ConnectedNotice() { } className={ styles.connected__text }> - { __( 'Connected to WordPress.com', 'jetpack-my-jetpack' ) } + { __( 'Your site is connected', 'jetpack-my-jetpack' ) }
  • ); diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts index 1952c5067f66..2676b22a180f 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/lib.ts @@ -425,13 +425,3 @@ export function canContinue( step: WizardStep, state: WizardState ): boolean { */ return chosen.freeText ? Boolean( state.freeText?.trim() ) : true; } - -/** - * Whether the given step is the final one. - * - * @param step - The current step index. - * @return True on the last step. - */ -export function isLastStep( step: WizardStep ): boolean { - return step === TOTAL_STEPS - 1; -} diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/finish-step.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/finish-step.tsx index cd6646e3de82..2aaeec61a7cf 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/finish-step.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/steps/finish-step.tsx @@ -16,7 +16,7 @@ type FinishStepProps = { // Where the two ways out lead. dashboardUrl: string; exitUrl: string; - // Records that setup is finished, then follows the link. + // Records that setup is finished. onLeave: ( event: MouseEvent< HTMLElement > ) => void; }; @@ -63,16 +63,32 @@ function summarise( results: SetupModuleResult[] ) { }; } +/** + * A number of features, with the word for them. + * + * Its own string so that each number in the tally agrees with its own noun: one + * `_n()` over the whole sentence can only decline on one of the two. + * + * @param count - How many features. + * @return The count and its noun. + */ +function featureCount( count: number ): string { + return sprintf( + /* translators: %d: a number of Jetpack features. */ + _n( '%d feature', '%d features', count, 'jetpack-my-jetpack' ), + count + ); +} + /** * What this run actually did, as a sentence. * - * Only what changed. Five of the six ship on, so most runs send no request at - * all, and the line used to say "6 of 6 switched on in this session" for a run - * that touched nothing — and "4 of 6 switched on" for one whose only two - * requests were switching things off. + * Only what changed: five of the six ship on, so most runs send no request at + * all. Each line names setup, because the rows show end state and a bare count + * reads as their total. * * @param results - What became of each module. - * @return The line under the list. + * @return The line above the list. */ function sessionTally( results: SetupModuleResult[] ): string { const on = results.filter( result => result.changed && result.wanted && result.ok ).length; @@ -84,25 +100,25 @@ function sessionTally( results: SetupModuleResult[] ): string { if ( on && off ) { return sprintf( - /* translators: 1: how many features were switched on. 2: how many were switched off. */ - __( '%1$d switched on and %2$d switched off.', 'jetpack-my-jetpack' ), - on, - off + /* translators: 1: a number of features switched on, e.g. "2 features". 2: a number switched off, e.g. "1 feature". */ + __( 'Setup switched on %1$s and switched off %2$s.', 'jetpack-my-jetpack' ), + featureCount( on ), + featureCount( off ) ); } if ( on ) { return sprintf( - /* translators: %d: how many features were switched on. */ - _n( '%d switched on.', '%d switched on.', on, 'jetpack-my-jetpack' ), - on + /* translators: %s: a number of features switched on, e.g. "2 features". */ + __( 'Setup switched on %s.', 'jetpack-my-jetpack' ), + featureCount( on ) ); } return sprintf( - /* translators: %d: how many features were switched off. */ - _n( '%d switched off.', '%d switched off.', off, 'jetpack-my-jetpack' ), - off + /* translators: %s: a number of features switched off, e.g. "2 features". */ + __( 'Setup switched off %s.', 'jetpack-my-jetpack' ), + featureCount( off ) ); } @@ -204,6 +220,14 @@ export function FinishStep( { { rows.length > 0 && (
    + } + className={ clsx( styles[ 'finish-note' ], styles.wave, styles[ 'wave-3' ] ) } + > + { tally } + + { /* Safari drops the list role off a `list-style: none` list, so the count goes unsaid. */ }
      ) ) }
    - - } - className={ clsx( styles[ 'finish-note' ], styles.wave, styles[ 'wave-3' ] ) } - > - { tally } -
    ) }
    - { __( 'Back to WordPress', 'jetpack-my-jetpack' ) } + { __( 'Go to My Jetpack', 'jetpack-my-jetpack' ) } - { __( 'Go to My Jetpack', 'jetpack-my-jetpack' ) } + { __( 'Back to your WordPress site', 'jetpack-my-jetpack' ) }
    diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx index db0c9c92d82c..5117333f8269 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/test/smoke.test.tsx @@ -1,7 +1,15 @@ import { readFileSync } from 'node:fs'; import { render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { bell, chartBar, border, drafts, published } from '@wordpress/icons'; +import { + bell, + chartBar, + border, + drafts, + envelope, + postCommentsForm, + published, +} from '@wordpress/icons'; import { Children, isValidElement } from 'react'; import { startBenefits } from '../lib'; import { Wizard } from '../wizard'; @@ -51,9 +59,9 @@ jest.mock( '../../../../hooks/use-analytics', () => ( { } ) ); /* - * The six modules the feature step offers. Mocked here rather than driven through - * the modules store: these tests are about the shell and the way through it, and - * the hook has its own tests for what it does with the store. + * What the feature step offers, mocked rather than driven through the modules store. + * These tests are about the shell and the way through it, and two modules start on + * and two off so a run can switch more than one in either direction. */ const mockModules = [ { @@ -63,6 +71,13 @@ const mockModules = [ icon: chartBar, activated: true, }, + { + slug: 'subscriptions', + name: 'Subscriptions', + description: 'Sends new posts out by email.', + icon: envelope, + activated: true, + }, { slug: 'monitor', name: 'Downtime Monitor', @@ -70,6 +85,13 @@ const mockModules = [ icon: bell, activated: false, }, + { + slug: 'contact-form', + name: 'Contact Form', + description: 'A form people can write in.', + icon: postCommentsForm, + activated: false, + }, ]; const mockApply = jest.fn( ( modules: typeof mockModules, wanted: Record< string, boolean > ) => @@ -116,6 +138,9 @@ jest.mock( '../assign-location', () => ( { const assignedHref = () => mockAssignLocation.mock.calls.at( -1 )?.[ 0 ] ?? null; +// The run as session storage holds it, so a test can see it survive or go. +const savedRun = () => window.sessionStorage.getItem( 'jetpack-onboarding-run' ); + beforeEach( () => { mockAssignLocation.mockClear(); mockApiFetch.mockClear(); @@ -133,6 +158,7 @@ beforeEach( () => { // The run is kept in session storage now, so one test's answers would // otherwise be the next one's starting point. window.sessionStorage.clear(); + window.location.hash = ''; } ); /** @@ -434,7 +460,7 @@ describe( 'Wizard resume after connecting', () => { setupWizard( { isUserConnected: true } ); - expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'Connected to WordPress.com' ); + expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'Your site is connected' ); } ); /* @@ -574,7 +600,7 @@ describe( 'Wizard shell', () => { it( 'sends the rail out to WordPress and the footer back to My Jetpack', () => { setupWizard(); - const railExit = screen.getByRole( 'link', { name: 'Back to WordPress' } ); + const railExit = screen.getByRole( 'link', { name: 'Back to your WordPress site' } ); const skip = screen.getByRole( 'link', { name: 'Skip setup' } ); expect( railExit ).toHaveAttribute( 'href', dashboardUrl ); @@ -715,21 +741,28 @@ describe( 'Wizard shell', () => { expect( heading() ).toHaveTextContent( "What's this site for?" ); } ); - it( 'replaces Continue with Finish on the last step', async () => { + it( 'hands the last step its own two ways out instead of the footer’s', async () => { const { user } = setupWizard( { isUserConnected: true } ); await advance( user, 2 ); - // The finish step carries its own two ways out instead of the footer's. expect( screen.queryByRole( 'button', { name: 'Continue' } ) ).not.toBeInTheDocument(); - expect( screen.getByRole( 'link', { name: 'Back to WordPress' } ) ).toHaveAttribute( - 'href', - dashboardUrl - ); + expect( screen.getByRole( 'link', { name: 'Go to My Jetpack' } ) ).toHaveAttribute( 'href', exitUrl ); + expect( screen.getByRole( 'link', { name: 'Back to your WordPress site' } ) ).toHaveAttribute( + 'href', + dashboardUrl + ); + + // My Jetpack is the primary, so it leads. The class that styles it as one is + // stubbed out under Jest, which leaves the order as what can be asserted. + expect( screen.getAllByRole( 'link' ).map( link => link.textContent ) ).toEqual( [ + 'Go to My Jetpack', + 'Back to your WordPress site', + ] ); } ); } ); @@ -820,29 +853,119 @@ describe( 'Leaving setup', () => { it( 'records a finish rather than a skip', async () => { const { user } = setupWizard( { isUserConnected: true } ); - // Walk to the last step, which is the only one that offers Finish. + // Walk to the last step, which carries the only exits that record a finish. await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); - await user.click( await screen.findByRole( 'link', { name: 'Back to WordPress' } ) ); + await user.click( await screen.findByRole( 'link', { name: 'Back to your WordPress site' } ) ); expect( mockApiFetch ).toHaveBeenCalledWith( { path: '/my-jetpack/v1/site/onboarding/settled', method: 'POST', data: { outcome: 'completed' }, } ); + + // And it goes where the link says. + await waitFor( () => expect( mockAssignLocation ).toHaveBeenCalledWith( dashboardUrl ) ); } ); - // A failed write costs the user being offered setup once more. Being held on a - // screen they asked to leave would cost a great deal more. - it( 'leaves even when the record fails', async () => { + // wp-admin is the one door the takeover does not watch. + it( 'sends a disconnected user out by a door that does not redirect back', async () => { mockApiFetch.mockRejectedValueOnce( new Error( 'nope' ) ); const { user } = setupWizard(); await user.click( screen.getByRole( 'link', { name: 'Skip setup' } ) ); + await waitFor( () => expect( assignedHref() ).toBe( dashboardUrl ) ); + } ); + + // Only the disconnected get diverted: everyone else asked for a particular door. + it( 'still follows the link a connected user clicked when the record fails', async () => { + const { user } = setupWizard( { isUserConnected: true } ); + await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); + await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); + await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); + + // Rejected only now, so nothing on the way here is answered with it. + mockApiFetch.mockRejectedValueOnce( new Error( 'nope' ) ); + await user.click( await screen.findByRole( 'link', { name: 'Go to My Jetpack' } ) ); + await waitFor( () => expect( assignedHref() ).toBe( exitUrl ) ); } ); + + it( 'is not an exit when a middle click opens the link somewhere else', async () => { + const { user } = setupWizard(); + const held = savedRun(); + expect( held ).not.toBeNull(); + + await user.pointer( { + keys: '[MouseMiddle]', + target: screen.getByRole( 'link', { name: 'Skip setup' } ), + } ); + + expect( mockApiFetch ).not.toHaveBeenCalled(); + expect( mockAssignLocation ).not.toHaveBeenCalled(); + expect( savedRun() ).toBe( held ); + } ); + + it( 'is not an exit when all that opened is the context menu', async () => { + const { user } = setupWizard(); + + await user.pointer( { + keys: '[MouseRight]', + target: screen.getByRole( 'link', { name: 'Skip setup' } ), + } ); + + expect( mockApiFetch ).not.toHaveBeenCalled(); + expect( mockAssignLocation ).not.toHaveBeenCalled(); + } ); + + it( 'leaves a modified click to the browser and changes nothing', async () => { + const user = userEvent.setup(); + // A hash is the only href jsdom will follow, so arriving at it is the only way + // to see that the default action was left alone. + render( ); + + const held = savedRun(); + expect( held ).not.toBeNull(); + + await user.keyboard( '{Meta>}' ); + await user.click( screen.getByRole( 'link', { name: 'Skip setup' } ) ); + await user.keyboard( '{/Meta}' ); + + expect( window.location.hash ).toBe( '#skipped' ); + expect( mockApiFetch ).not.toHaveBeenCalled(); + expect( mockAssignLocation ).not.toHaveBeenCalled(); + expect( savedRun() ).toBe( held ); + } ); + + // It sits beside Skip setup and leads out of Jetpack, so the two have to record + // the same thing. + it( 'records the exit by the rail, as the footer does', async () => { + const { user } = setupWizard(); + + await user.click( screen.getByRole( 'link', { name: 'Back to your WordPress site' } ) ); + + expect( mockApiFetch ).toHaveBeenCalledWith( { + path: '/my-jetpack/v1/site/onboarding/settled', + method: 'POST', + data: { outcome: 'skipped' }, + } ); + await waitFor( () => expect( assignedHref() ).toBe( dashboardUrl ) ); + expect( savedRun() ).toBeNull(); + } ); + + it( 'is not an exit when the finish step’s own links are middle-clicked', async () => { + const { user } = setupWizard( { isUserConnected: true } ); + await advance( user, 2 ); + + for ( const name of [ 'Go to My Jetpack', 'Back to your WordPress site' ] ) { + await user.pointer( { keys: '[MouseMiddle]', target: screen.getByRole( 'link', { name } ) } ); + } + + expect( mockApiFetch ).not.toHaveBeenCalled(); + expect( mockAssignLocation ).not.toHaveBeenCalled(); + } ); } ); describe( 'Clicking Continue twice', () => { @@ -929,19 +1052,31 @@ describe( 'Coming back to a run in progress', () => { } ); describe( 'What the finish screen claims', () => { - /* - * Five of the six ship on, so most runs change nothing at all. The line used - * to read "6 of 6 switched on in this session" for a run that sent no request, - * and "4 of 6 switched on" for one whose only two requests switched things off. - */ it( 'counts only what this run actually changed', async () => { const { user } = setupWizard( { isUserConnected: true } ); await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); - // Stats was already on and is left on; Downtime Monitor was off and goes on. - await expect( screen.findByText( '1 switched on.' ) ).resolves.toBeInTheDocument(); + // The two already on are left alone; the two that were off come on. + const note = await screen.findByText( 'Setup switched on 2 features.' ); + + // Below the rows it would read as their total. `getAllByText` is in document order. + expect( screen.getAllByText( /^Setup switched|^On$/ )[ 0 ] ).toBe( note ); + } ); + + it( 'counts one in the singular', async () => { + const { user } = setupWizard( { isUserConnected: true } ); + await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); + await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); + + // Leaves Downtime Monitor as the only one with anywhere to go. + await user.click( screen.getByRole( 'checkbox', { name: 'Contact Form' } ) ); + await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); + + await expect( + screen.findByText( 'Setup switched on 1 feature.' ) + ).resolves.toBeInTheDocument(); } ); it( 'says nothing was needed when nothing was', async () => { @@ -949,8 +1084,9 @@ describe( 'What the finish screen claims', () => { await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); - // Leave Stats on as it already is, and Downtime Monitor off as it already is. + // Every switch left where the site already has it. await user.click( screen.getByRole( 'checkbox', { name: 'Downtime Monitor' } ) ); + await user.click( screen.getByRole( 'checkbox', { name: 'Contact Form' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); await expect( @@ -958,17 +1094,34 @@ describe( 'What the finish screen claims', () => { ).resolves.toBeInTheDocument(); } ); + // Two one way and one the other, so each number has to decline its own noun. + it( 'names both directions when the run went both ways', async () => { + const { user } = setupWizard( { isUserConnected: true } ); + await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); + await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); + + await user.click( screen.getByRole( 'checkbox', { name: 'Jetpack Stats' } ) ); + await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); + + await expect( + screen.findByText( 'Setup switched on 2 features and switched off 1 feature.' ) + ).resolves.toBeInTheDocument(); + } ); + // Switching something off is not switching something on. it( 'does not call a deactivation an activation', async () => { const { user } = setupWizard( { isUserConnected: true } ); await user.click( screen.getByRole( 'radio', { name: 'A blog or publication' } ) ); await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); - await user.click( screen.getByRole( 'checkbox', { name: 'Jetpack Stats' } ) ); - await user.click( screen.getByRole( 'checkbox', { name: 'Downtime Monitor' } ) ); + for ( const name of [ 'Jetpack Stats', 'Subscriptions', 'Downtime Monitor', 'Contact Form' ] ) { + await user.click( screen.getByRole( 'checkbox', { name } ) ); + } await user.click( screen.getByRole( 'button', { name: 'Continue' } ) ); - await expect( screen.findByText( '1 switched off.' ) ).resolves.toBeInTheDocument(); + await expect( + screen.findByText( 'Setup switched off 2 features.' ) + ).resolves.toBeInTheDocument(); expect( screen.queryByText( /switched on/ ) ).not.toBeInTheDocument(); } ); } ); @@ -1153,7 +1306,9 @@ describe( 'Guards on the way through', () => { await advance( user, 2 ); expect( screen.queryByRole( 'link', { name: 'Skip setup' } ) ).not.toBeInTheDocument(); - expect( screen.getByRole( 'link', { name: 'Back to WordPress' } ) ).toBeInTheDocument(); + expect( + screen.getByRole( 'link', { name: 'Back to your WordPress site' } ) + ).toBeInTheDocument(); } ); // Every switch reports its own outcome, so a rejection is the request layer diff --git a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx index 093252935dfa..be35970a50f0 100644 --- a/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx +++ b/projects/packages/my-jetpack/_inc/components/onboarding-screen/wizard/wizard.tsx @@ -20,7 +20,6 @@ import { DataInArt } from './data-in'; import { EverywhereArt } from './everywhere'; import { canContinue, - isLastStep, featuresDescription, openingStep, siteTypeAnswer, @@ -220,20 +219,39 @@ export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { /* * Leaving is recorded before it happens, so the takeover does not interrupt this - * person again. The navigation is in `finally`: a failed write only costs them - * being offered setup once more, and holding them on a screen they asked to - * leave would cost a great deal more. + * person again. A failed write records nothing and My Jetpack sends a + * disconnected user straight back in, so only that case leaves by wp-admin. */ const handleExit = useCallback( ( outcome: SettleOutcome ) => ( event: MouseEvent< HTMLElement > ) => { + /* + * A modified click opens the link somewhere else and leaves this tab on + * the wizard, so nothing is recorded and the run is kept. A middle click + * and the context menu fire no `click` at all, so they arrive here never. + */ + if ( + event.button !== 0 || + event.metaKey || + event.ctrlKey || + event.shiftKey || + event.altKey + ) { + return; + } + event.preventDefault(); - // The run is over either way, so it must not be waiting on the next visit. + + const destination = event.currentTarget.getAttribute( 'href' ) || exitUrl; + + // The run is over, so it must not be waiting on the next visit. forgetRun(); - settleOnboarding( outcome ) - .catch( () => {} ) - .finally( () => assignLocation( exitUrl ) ); + + settleOnboarding( outcome ).then( + () => assignLocation( destination ), + () => assignLocation( isUserConnected ? destination : dashboardUrl ) + ); }, - [ exitUrl, forgetRun ] + [ exitUrl, dashboardUrl, forgetRun, isUserConnected ] ); const handleBack = useCallback( @@ -406,10 +424,11 @@ export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { tone="neutral" size="compact" href={ dashboardUrl } + onClick={ handleExit( 'skipped' ) } className={ styles.exit } > - { __( 'Back to WordPress', 'jetpack-my-jetpack' ) } + { __( 'Back to your WordPress site', 'jetpack-my-jetpack' ) } @@ -477,24 +496,14 @@ export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { gap="md" wrap="wrap" > - { /* - * Gone on the last step, where the work is already done and Finish - * is the way out. Skipping there would record this person as having - * declined setup and never write the site-wide completion, so the - * next admin would be offered it again on a configured site. - */ } - { isLastStep( step ) ? ( - - ) : ( - - { __( 'Skip setup', 'jetpack-my-jetpack' ) } - - ) } + + { __( 'Skip setup', 'jetpack-my-jetpack' ) } + { /* The start screen carries its own primary, so the footer keeps only the exit. */ } { ! isStart && ( @@ -510,33 +519,17 @@ export function Wizard( { exitUrl, dashboardUrl }: WizardProps ) { { __( 'Back', 'jetpack-my-jetpack' ) } ) } - { isLastStep( step ) ? ( - // Nothing else is saved yet, so finishing records that it - // happened and leaves. - - { __( 'Finish', 'jetpack-my-jetpack' ) } - - ) : ( - - ) } + ) } diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-skip-failure b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-skip-failure new file mode 100644 index 000000000000..5d9c57f94993 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-onboarding-skip-failure @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Onboarding: when leaving setup cannot be recorded, take a user who has not connected to wp-admin, because My Jetpack would send them straight back in. A connected user still goes where they clicked, and the finish screen's tally now says it is counting what setup switched on or off. diff --git a/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-devin-feedback b/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-devin-feedback new file mode 100644 index 000000000000..624d775148ba --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-my-jetpack-onboarding-devin-feedback @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Onboarding: say the site is connected, move the finish screen's count above the rows it is not a total of, and make My Jetpack the primary way out. diff --git a/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-skip-failure b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-skip-failure new file mode 100644 index 000000000000..bf6ab9b83265 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-my-jetpack-onboarding-skip-failure @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +My Jetpack: leaving the setup wizard now works even when the site cannot record that it happened: a user who has not connected lands in wp-admin rather than back in setup, and a connected user goes where they clicked. The wizard's finish screen also says what its count is counting. diff --git a/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-devin-feedback b/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-devin-feedback new file mode 100644 index 000000000000..e51aa93595b2 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-my-jetpack-onboarding-devin-feedback @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +My Jetpack: clarify the setup wizard's connection notice and finish screen, and point it at My Jetpack on the way out.