SlotFill: remove registration API from useSlot result#67070
Merged
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 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. |
jsnajdr
commented
Nov 18, 2024
| ...slot, | ||
| ...api, | ||
| }; | ||
| return { ...slot }; |
Member
Author
There was a problem hiding this comment.
Returning { ...slot } instead of slot has two purposes:
- The hook always returns an object, even if the
slotisundefined. Important for compatibility. - The hook has a nice return type: an object with optional
refandfillPropsfields.
youknowriad
approved these changes
Nov 18, 2024
youknowriad
left a comment
Contributor
There was a problem hiding this comment.
Makes sense.
Thanks for checking the usage in the directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #67000 where @youknowriad pointed out in review that the API methods (
registerSlotetc) returned from__experimentalUseSlotare not used anywhere. This PR removes the API methods and leaves only theslotobject.I also update the
Fillcomponent to not useuseSlotat all: theregister/unregisterFillcan be accessed through context and to find out if there is a registeredslotand whether it has a DOM element, we can look atregistry.slotsdirectly.I was also searching for usages of
__experimentalUseSlot. And it seems to be not really used by plugins. Plugins like WooCommerce or Kubio want to know whether a particular slot has registered fills. If there are no fills, they usually don't render the slot at all. They use__experimentalUseSlotFills( name ).fills.length > 0to determine that. The__experimentalUseSlotfunction is called only for backward compatibility, because before #44642 there was only__experimentalUseSlotand it returned also the fills.The only place where
__experimentalUseSlotis really used is thePopovercomponent, to determine whether a slot with given name is registered.If we wanted to stabilize the
useSlotAPI and remove the__experimentalprefix, we need to solve these two use cases:name) has any registered fills. This is widely used to render slots conditionally, only if there are fills registered. Because even an empty slot renders an element and is visible in the UI, and that's often not wanted.name) is registered at all.