Fix: ToolsPanelItem: hasValue silently fails when it returns a non-boolean (e.g., undefined), causing the control to not render - #73069#73074
Conversation
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @ddryo. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
|
I'm not opposed to these changes but I don't think they are 100% necessary. I think there might have been a misunderstanding about the expected behaviour of the |
| // dependency to the useCallback hook! If needed, we should use a ref. | ||
| const hasValueCallback = useCallback( hasValue, [ panelId ] ); | ||
| const hasValueCallback = useCallback( | ||
| () => Boolean( hasValue() ), |
There was a problem hiding this comment.
I'm not sure casting this everywhere adds much.
The types define that hasValue should return a boolean so invalid props there should probably be caught during development. If they aren't the result without casting to a boolean is still functionally correct.
What?
Closes #73069
Why?
hasValueprop inToolsPanelItemcomponent, the component was not being rendered and it does not reproduce any console erorr, so user/dev can know the exact issue.How?
hasValueprop to Boolean and does not rely on user passed input so that the component can render without any issue.undefinedor any falsy or truthy value, the implementation intercepts and convert to actual Boolean True and False, such that it does not fails to render component.Testing Instructions
Add the implementation for above component, you will notice that it would render component.
Testing Instructions for Keyboard