diff --git a/packages/data/src/factory.js b/packages/data/src/factory.js index 9bc14f46666c9..be4ef8cf673c5 100644 --- a/packages/data/src/factory.js +++ b/packages/data/src/factory.js @@ -44,17 +44,16 @@ export function createRegistrySelector( registrySelector ) { // and that has the same API as a regular selector. Binding it in such a way makes it // possible to call the selector directly from another selector. const wrappedSelector = ( ...args ) => { + let selector = selectorsByRegistry.get( wrappedSelector.registry ); // We want to make sure the cache persists even when new registry // instances are created. For example patterns create their own editors // with their own core/block-editor stores, so we should keep track of // the cache for each registry instance. - if ( ! selectorsByRegistry.has( wrappedSelector.registry ) ) { - selectorsByRegistry.set( - wrappedSelector.registry, - registrySelector( wrappedSelector.registry.select ) - ); + if ( ! selector ) { + selector = registrySelector( wrappedSelector.registry.select ); + selectorsByRegistry.set( wrappedSelector.registry, selector ); } - return selectorsByRegistry.get( wrappedSelector.registry )( ...args ); + return selector( ...args ); }; /**