From 8d02b62ec0aa7a958acbbbd3d73f551b8ffc062a Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 7 Sep 2026 16:22:23 -0300 Subject: [PATCH 1/3] Jetpack notices: give each notice a stable React key so replacements remount SimpleNotice starts its dismiss timer in componentDidMount only. The redux notices list was keyed by array index, so a progress notice replaced in the same tick by a success notice reused the same element: no remount, no timer, and the toast stayed until dismissed by hand. Key the list on a per-creation instanceId instead. noticeId does not work as the key because every caller reuses it for the replacement. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01NfGbCrDbhYmgwY5hW68VLA --- .../components/global-notices/index.jsx | 4 +- .../global-notices/state/notices/actions.js | 2 + .../global-notices/test/component.jsx | 113 ++++++++++++++++++ .../jetpack/changelog/fix-toast-auto-dismiss | 4 + .../plugins/jetpack/tests/jest.config.gui.js | 1 + 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx create mode 100644 projects/plugins/jetpack/changelog/fix-toast-auto-dismiss diff --git a/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx b/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx index 6ee8efe3a0e2..4c1b2980a87e 100644 --- a/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx +++ b/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx @@ -69,10 +69,10 @@ class NoticesList extends Component { //and from the old component. When all notices are moved to redux store, this component //needs to be updated. noticesList = noticesList.concat( - this.props.storeNotices.map( function ( notice, index ) { + this.props.storeNotices.map( function ( notice ) { return ( , { store } ); + return store; +} + +describe( 'NoticesList', () => { + beforeEach( () => { + jest.useFakeTimers(); + } ); + + afterEach( () => { + jest.useRealTimers(); + } ); + + it( 'dismisses a notice that replaced an earlier one under the same id', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-info', 'Activating Image CDN…', { id: 'module-toggle' } ) ); + } ); + expect( screen.getByText( 'Activating Image CDN…' ) ).toBeInTheDocument(); + + act( () => { + store.dispatch( removeNotice( 'module-toggle' ) ); + store.dispatch( + createNotice( 'is-success', 'Image CDN has been activated.', { + id: 'module-toggle', + duration: 2000, + } ) + ); + } ); + expect( screen.getByText( 'Image CDN has been activated.' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Image CDN has been activated.' ) ).not.toBeInTheDocument(); + } ); + + it( 'dismisses a notice that replaced an earlier one under a different id', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-info', 'Updating settings…', { id: 'setting-update' } ) ); + } ); + + act( () => { + store.dispatch( removeNotice( 'setting-update' ) ); + store.dispatch( + createNotice( 'is-success', 'Updated settings.', { + id: 'setting-update-success', + duration: 2000, + } ) + ); + } ); + expect( screen.getByText( 'Updated settings.' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Updated settings.' ) ).not.toBeInTheDocument(); + } ); + + it( 'dismisses a notice added while another one is already on screen', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-info', 'Testing your connection…', { id: 'connection' } ) ); + } ); + + act( () => { + store.dispatch( + createNotice( 'is-success', 'Site is verified.', { id: 'verify', duration: 2000 } ) + ); + } ); + expect( screen.getByText( 'Site is verified.' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Site is verified.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); + } ); + + it( 'leaves the remaining notices alone when one of them expires', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-success', 'Saved.', { id: 'a', duration: 2000 } ) ); + store.dispatch( createNotice( 'is-info', 'Still working…', { id: 'b' } ) ); + } ); + expect( screen.getByText( 'Saved.' ) ).toBeInTheDocument(); + expect( screen.getByText( 'Still working…' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Saved.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Still working…' ) ).toBeInTheDocument(); + } ); +} ); diff --git a/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss b/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss new file mode 100644 index 000000000000..97e6cc407561 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Dismiss the Jetpack settings success notices automatically instead of leaving them on screen. diff --git a/projects/plugins/jetpack/tests/jest.config.gui.js b/projects/plugins/jetpack/tests/jest.config.gui.js index 94b4c94a1042..696b1102f582 100644 --- a/projects/plugins/jetpack/tests/jest.config.gui.js +++ b/projects/plugins/jetpack/tests/jest.config.gui.js @@ -20,6 +20,7 @@ module.exports = { '/_inc/client/ai/test/main.jsx', '/_inc/client/ai/test/tracks.js', '/_inc/client/at-a-glance/boost/test/component.jsx', + '/_inc/client/components/global-notices/test/component.jsx', '/_inc/client/components/jetpack-notices/test/state-notices.test.jsx', '/_inc/client/sharing/test/component.jsx', '/_inc/client/traffic/test/component.jsx', From 512c07f6e48afa472781d8e3ad62ff4b9ea0e1e9 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Mon, 7 Sep 2026 17:26:31 -0300 Subject: [PATCH 2/3] Jetpack notices: drop the notices test that passes without the fix `leaves the remaining notices alone when one of them expires` passes with the index key restored: both notices mount in the same render and the survivor stays at index 0, so no key shifts and nothing remounts. It reproduces no bug. The three remaining tests each fail without the fix. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01NfGbCrDbhYmgwY5hW68VLA --- .../global-notices/test/component.jsx | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx b/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx index c726d5f59d09..14a9464576a8 100644 --- a/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx +++ b/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx @@ -93,21 +93,4 @@ describe( 'NoticesList', () => { expect( screen.queryByText( 'Site is verified.' ) ).not.toBeInTheDocument(); expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); } ); - - it( 'leaves the remaining notices alone when one of them expires', () => { - const store = mountNotices(); - - act( () => { - store.dispatch( createNotice( 'is-success', 'Saved.', { id: 'a', duration: 2000 } ) ); - store.dispatch( createNotice( 'is-info', 'Still working…', { id: 'b' } ) ); - } ); - expect( screen.getByText( 'Saved.' ) ).toBeInTheDocument(); - expect( screen.getByText( 'Still working…' ) ).toBeInTheDocument(); - - act( () => { - jest.advanceTimersByTime( 2000 ); - } ); - expect( screen.queryByText( 'Saved.' ) ).not.toBeInTheDocument(); - expect( screen.getByText( 'Still working…' ) ).toBeInTheDocument(); - } ); } ); From 5e2c0e89f4328c436ffec80073bf67f53bd4f703 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Tue, 8 Sep 2026 09:18:46 -0300 Subject: [PATCH 3/3] Jetpack settings: give the two Security success notices a dismiss timer The WAF and IP allow list cards hand-roll their notice dispatches and pass no duration, so SimpleNotice never arms a timer for them. Also pin the notices tests to the notice under test with a duration-less control, and prefix the changelog entry. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01NfGbCrDbhYmgwY5hW68VLA --- .../_inc/client/components/global-notices/test/component.jsx | 4 ++++ projects/plugins/jetpack/_inc/client/security/allowList.jsx | 1 + projects/plugins/jetpack/_inc/client/security/waf.jsx | 1 + projects/plugins/jetpack/changelog/fix-toast-auto-dismiss | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx b/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx index 14a9464576a8..820dde803274 100644 --- a/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx +++ b/projects/plugins/jetpack/_inc/client/components/global-notices/test/component.jsx @@ -28,6 +28,7 @@ describe( 'NoticesList', () => { const store = mountNotices(); act( () => { + store.dispatch( createNotice( 'is-info', 'Testing your connection…', { id: 'connection' } ) ); store.dispatch( createNotice( 'is-info', 'Activating Image CDN…', { id: 'module-toggle' } ) ); } ); expect( screen.getByText( 'Activating Image CDN…' ) ).toBeInTheDocument(); @@ -47,12 +48,14 @@ describe( 'NoticesList', () => { jest.advanceTimersByTime( 2000 ); } ); expect( screen.queryByText( 'Image CDN has been activated.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); } ); it( 'dismisses a notice that replaced an earlier one under a different id', () => { const store = mountNotices(); act( () => { + store.dispatch( createNotice( 'is-info', 'Testing your connection…', { id: 'connection' } ) ); store.dispatch( createNotice( 'is-info', 'Updating settings…', { id: 'setting-update' } ) ); } ); @@ -71,6 +74,7 @@ describe( 'NoticesList', () => { jest.advanceTimersByTime( 2000 ); } ); expect( screen.queryByText( 'Updated settings.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); } ); it( 'dismisses a notice added while another one is already on screen', () => { diff --git a/projects/plugins/jetpack/_inc/client/security/allowList.jsx b/projects/plugins/jetpack/_inc/client/security/allowList.jsx index 2681ebcc3aaa..3af6dd15e2b0 100644 --- a/projects/plugins/jetpack/_inc/client/security/allowList.jsx +++ b/projects/plugins/jetpack/_inc/client/security/allowList.jsx @@ -59,6 +59,7 @@ const AllowList = class extends Component { this.props.removeNotice( 'module-setting-update' ); this.props.createNotice( 'is-success', __( 'Updated Settings.', 'jetpack' ), { id: 'module-setting-update-success', + duration: 2000, } ); } ) .catch( error => { diff --git a/projects/plugins/jetpack/_inc/client/security/waf.jsx b/projects/plugins/jetpack/_inc/client/security/waf.jsx index 2c73cbb4907d..a8f79f7f77f3 100644 --- a/projects/plugins/jetpack/_inc/client/security/waf.jsx +++ b/projects/plugins/jetpack/_inc/client/security/waf.jsx @@ -111,6 +111,7 @@ export const Waf = class extends Component { this.props.removeNotice( 'module-setting-update' ); this.props.createNotice( 'is-success', __( 'Updated Settings.', 'jetpack' ), { id: 'module-setting-update-success', + duration: 2000, } ); } ) .catch( error => { diff --git a/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss b/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss index 97e6cc407561..fb4c6b0b6af6 100644 --- a/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss +++ b/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss @@ -1,4 +1,4 @@ Significance: patch Type: bugfix -Dismiss the Jetpack settings success notices automatically instead of leaving them on screen. +Settings: Dismiss success notices automatically instead of leaving them on screen.