-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Add error handle to the 'registry.batch' method #62322
Conversation
Size Change: +39 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for tightening it up @Mamaduka 👍
Could this also use a unit test?
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
That would be great. I tried to add unit tests, but it's been a while since I've worked on store tests and properly emulated the reducer's error. If you have any pointers, I would be happy to take it from there. |
callback(); | ||
emitter.resume(); | ||
Object.values( stores ).forEach( ( store ) => store.emitter.resume() ); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also wrap with try/catch/finally
the callback()
that we run if we're already batching above (L319)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L319 returns early and doesn't touch emitters. Bubbling the errors should be okay there.
Could be something straightforward, like simulating an error by an unallowed operation inside the reducer. For example,
This should simulate a |
On second thought, I'm not sure the |
You put it better in words. I think I had the same problem when trying initially. |
expect( () => { | ||
registry.batch( () => { | ||
throw error; | ||
} ); | ||
} ).toThrow( error ); | ||
expect( listener ).not.toHaveBeenCalled(); | ||
|
||
registry.batch( () => { | ||
store.dispatch( { type: 'dummy' } ); | ||
store.dispatch( { type: 'dummy' } ); | ||
} ); | ||
expect( listener ).toHaveBeenCalledTimes( 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyxla, what do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - thanks for adding a test!
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mr2P <mr2p@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mr2P <mr2p@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mr2P <mr2p@git.wordpress.org>
This was cherry-picked to the wp/6.6 branch. |
What?
Resolves: #62311.
PR adds an error handler to the
registry.batch
method and avoids pausing all store emitters during the error.Testing Instructions
wp.data.select( 'core' ).getEntityRecords( 'root', 'site' );
.Testing Instructions for Keyboard
Same.