-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Description
A critical deadlock occurs when resolvers implement the isFulfilled callback, causing promises returned by mapResolveSelector or thrown by mapSuspendSelector to hang indefinitely.
The root cause lies within fulfillSelector. When a resolver's isFulfilled method returns true, the function exits early without dispatching a finishResolution action to the metadata store. Despite this early exit, the selectorResolver retains its hasResolver property set to true.
This creates a fatal mismatch: both mapResolveSelector and mapSuspendSelector detect selector.hasResolver as true and attempt to check the metadata store for resolution status. However, since no metadata entry was created due to the early return, the promises enter an infinite wait state, never finding the resolution they expect.
The Problem
When resolver.isFulfilled returns true in fulfillSelector index.js:705-711:
if (
resolversCache.isRunning( selectorName, args ) ||
( typeof resolver.isFulfilled === 'function' &&
resolver.isFulfilled( state, ...args ) )
) {
return; // Early return - no metadata entry created!
}But both mapResolveSelector index.js:559-607 and mapSuspendSelector index.js:617-663 expect a metadata entry to exist:
In mapResolveSelector:
const hasFinished = () => {
return boundMetadataSelectors.hasFinishedResolution(
selectorName,
args
);
};
// This check will always fail - no metadata entry exists
if ( hasFinished() ) {
return finalize( result );
}
// Creates a subscription that waits forever
const unsubscribe = subscribe( () => {
if ( hasFinished() ) {
finalize( getResult() );
unsubscribe();
}
});In mapSuspendSelector:
if ( isFinished ) {
if ( hasResolutionFailed ) {
throw metadata.error;
}
return result;
}
// Throws a promise that will never resolve
throw new Promise( ( resolve ) => {
unsubscribe = subscribe( () => {
if ( boundMetadataSelectors.hasFinishedResolution( selectorName, args ) ) {
resolve();
unsubscribe();
}
});
});Result: The promise waits forever for a finishResolution action that will never come, because the resolver was never started due to the isFulfilled early return.
Step-by-step reproduction instructions
- Implement a selector/resolver pair, with the resolver implementing
isFulfilled. - Attempt to await the value using
resolveSelect.
Screenshots, screen recording, code snippet
No response
Environment info
@wordpress/dataversion10.26.0.
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure