From a39c4375c7960849bd448dfc85a734f9fe85ef37 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 6 Sep 2024 13:51:15 +0200 Subject: [PATCH] Only use a11y module in GUTENBERG_PLUGIN --- packages/interactivity-router/src/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/interactivity-router/src/index.ts b/packages/interactivity-router/src/index.ts index 6c891ef159344d..5574ee925b1dfe 100644 --- a/packages/interactivity-router/src/index.ts +++ b/packages/interactivity-router/src/index.ts @@ -366,11 +366,19 @@ export const { state, actions } = store( 'core/router', { * @param ariaLive The politeness level for aria-live; default: 'polite'. */ function a11yAnnounce( message: string, ariaLive?: 'polite' | 'assertive' ) { - import( '@wordpress/a11y' ).then( - ( { speak } ) => speak( message, ariaLive ), - // Silence errors. - () => undefined - ); + if ( globalThis.IS_GUTENBERG_PLUGIN ) { + import( '@wordpress/a11y' ).then( + ( { speak } ) => speak( message, ariaLive ), + // Silence errors. + () => undefined + ); + } else { + state.navigation.message = + // Announce that the page has been loaded. If the message is the + // same, we use a no-break space similar to the @wordpress/a11y + // package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26 + message + ( state.navigation.message === message ? '\u00A0' : '' ); + } } // Add click and prefetch to all links.