Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data: recreate listeningStores set for every markListeningStores call #46607

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/data/src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function getStoreName( storeNameOrDescriptor ) {
export function createRegistry( storeConfigs = {}, parent = null ) {
const stores = {};
const emitter = createEmitter();
const listeningStores = new Set();
let listeningStores = null;

/**
* Global listener called for each store's update.
Expand Down Expand Up @@ -112,7 +112,7 @@ export function createRegistry( storeConfigs = {}, parent = null ) {
*/
function select( storeNameOrDescriptor ) {
const storeName = getStoreName( storeNameOrDescriptor );
listeningStores.add( storeName );
listeningStores?.add( storeName );
const store = stores[ storeName ];
if ( store ) {
return store.getSelectors();
Expand All @@ -122,11 +122,12 @@ export function createRegistry( storeConfigs = {}, parent = null ) {
}

function __unstableMarkListeningStores( callback, ref ) {
listeningStores.clear();
listeningStores = new Set();
try {
return callback.call( this );
} finally {
ref.current = Array.from( listeningStores );
listeningStores = null;
}
}

Expand All @@ -143,7 +144,7 @@ export function createRegistry( storeConfigs = {}, parent = null ) {
*/
function resolveSelect( storeNameOrDescriptor ) {
const storeName = getStoreName( storeNameOrDescriptor );
listeningStores.add( storeName );
listeningStores?.add( storeName );
const store = stores[ storeName ];
if ( store ) {
return store.getResolveSelectors();
Expand All @@ -165,7 +166,7 @@ export function createRegistry( storeConfigs = {}, parent = null ) {
*/
function suspendSelect( storeNameOrDescriptor ) {
const storeName = getStoreName( storeNameOrDescriptor );
listeningStores.add( storeName );
listeningStores?.add( storeName );
const store = stores[ storeName ];
if ( store ) {
return store.getSuspendSelectors();
Expand Down