From b39f2f0256c3754b1f2b708c97603db167965ed7 Mon Sep 17 00:00:00 2001 From: ella Date: Thu, 27 Nov 2025 11:03:25 +0100 Subject: [PATCH 1/2] Private APIs: remove re-registration check --- packages/private-apis/src/implementation.ts | 34 --------------------- packages/private-apis/src/test/index.js | 7 +---- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/packages/private-apis/src/implementation.ts b/packages/private-apis/src/implementation.ts index 6b1e676df75b6c..f8179e8a1c1aa2 100644 --- a/packages/private-apis/src/implementation.ts +++ b/packages/private-apis/src/implementation.ts @@ -43,12 +43,6 @@ const CORE_MODULES_USING_PRIVATE_APIS = [ '@wordpress/global-styles-ui', ]; -/** - * A list of core modules that already opted-in to - * the privateApis package. - */ -const registeredPrivateApis: Array< string > = []; - /* * Warning for theme and plugin developers. * @@ -66,9 +60,6 @@ const registeredPrivateApis: Array< string > = []; const requiredConsent = 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.'; -// The safety measure is meant for WordPress core where IS_WORDPRESS_CORE is set to true. -const allowReRegistration = globalThis.IS_WORDPRESS_CORE ? false : true; - /** * Called by a @wordpress package wishing to opt-in to accessing or exposing * private private APIs. @@ -90,21 +81,6 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( 'your product will inevitably break on one of the next WordPress releases.' ); } - if ( - ! allowReRegistration && - registeredPrivateApis.includes( moduleName ) - ) { - // This check doesn't play well with Story Books / Hot Module Reloading - // and isn't included in the Gutenberg plugin. It only matters in the - // WordPress core release. - throw new Error( - `You tried to opt-in to unstable APIs as module "${ moduleName }" which is already registered. ` + - 'This feature is only for JavaScript modules shipped with WordPress core. ' + - 'Please do not use it in plugins and themes as the unstable APIs will be removed ' + - 'without a warning. If you ignore this error and depend on unstable features, ' + - 'your product will inevitably break on one of the next WordPress releases.' - ); - } if ( consent !== requiredConsent ) { throw new Error( `You tried to opt-in to unstable APIs without confirming you know the consequences. ` + @@ -114,7 +90,6 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( 'your product will inevitably break on the next WordPress release.' ); } - registeredPrivateApis.push( moduleName ); return { lock, @@ -225,12 +200,3 @@ export function resetAllowedCoreModules() { CORE_MODULES_USING_PRIVATE_APIS.pop(); } } -/** - * Private function to allow the unit tests to reset - * the list of registered private apis. - */ -export function resetRegisteredPrivateApis() { - while ( registeredPrivateApis.length ) { - registeredPrivateApis.pop(); - } -} diff --git a/packages/private-apis/src/test/index.js b/packages/private-apis/src/test/index.js index 36e57ee58165d0..96e060b06af578 100644 --- a/packages/private-apis/src/test/index.js +++ b/packages/private-apis/src/test/index.js @@ -2,14 +2,9 @@ * Internal dependencies */ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '../'; -import { - resetRegisteredPrivateApis, - resetAllowedCoreModules, - allowCoreModule, -} from '../implementation'; +import { resetAllowedCoreModules, allowCoreModule } from '../implementation'; beforeEach( () => { - resetRegisteredPrivateApis(); resetAllowedCoreModules(); allowCoreModule( '@privateApis/test' ); allowCoreModule( '@privateApis/test-consumer' ); From f4bb8ed0fc9fb50ba939d46383fad074af8d30a4 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 12:35:27 +0100 Subject: [PATCH 2/2] Remove failing unit test for re-registration check --- packages/private-apis/src/test/index.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/private-apis/src/test/index.js b/packages/private-apis/src/test/index.js index 96e060b06af578..097ee042d5819d 100644 --- a/packages/private-apis/src/test/index.js +++ b/packages/private-apis/src/test/index.js @@ -32,18 +32,7 @@ describe( '__dangerousOptInToUnstableAPIsOnlyForCoreModules', () => { /This feature is only for JavaScript modules shipped with WordPress core/ ); } ); - it( 'Should not register the same module twice', () => { - expect( () => { - __dangerousOptInToUnstableAPIsOnlyForCoreModules( - requiredConsent, - '@privateApis/test' - ); - __dangerousOptInToUnstableAPIsOnlyForCoreModules( - requiredConsent, - '@privateApis/test' - ); - } ).toThrow( /is already registered/ ); - } ); + it( 'Should grant access to unstable APIs when passed both a consent string and a previously unregistered package name', () => { const unstableAPIs = __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent,