-
Notifications
You must be signed in to change notification settings - Fork 4.5k
SlotFill: unify registry and fill implementation #68056
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
base: trunk
Are you sure you want to change the base?
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. |
Size Change: -41 B (0%) Total Size: 1.93 MB
ℹ️ View Unchanged
|
b91ec95
to
121e3d2
Compare
Flaky tests detected in b204c5a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17456528503
|
121e3d2
to
e569063
Compare
@jsnajdr given that all tests are passing, we can probably start with an initial round of code review? |
@ciampo Yes please, I believe the PR is ready, I just did not yet get to write some detailed description and comments. If you can make sense of the rather big diff, please go ahead. The idea is to merge both registries/providers into one, with records discriminated by a The The The only major issue was with the
Previously it didn't happen because the I fixed that by creating a |
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.
I'm having a bit of a hard time to wrap all changes around my head. I wonder if we could split them to multiple PRs, or maybe try to document them a bit better?
function render( ui, options ) { | ||
return baseRender( ui, { wrapper: SlotFillProvider, ...options } ); |
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.
Can't we remove options
altogether?
function render( ui, options ) { | |
return baseRender( ui, { wrapper: SlotFillProvider, ...options } ); | |
function render( ui ) { | |
return baseRender( ui, { wrapper: SlotFillProvider } ); |
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.
Yes, options
can be removed and I did that in the latest version of the PR.
import type { SlotKey } from '../types'; | ||
|
||
function useObservableValueWithSelector< K, V, S >( |
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.
Is this worth living next to useObservableValue()
?
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.
That means adding a new public API to @wordpress/compose
, a function that has only one use case right now. I'd rather wait until the helper proves more useful across mutliple parts of the codebase.
const length = useObservableValueWithSelector( | ||
registry.fills, | ||
name, | ||
getLength |
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.
Is observing the array length enough? Any concerns if the fills change but have the same length?
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.
Yes, the useSlotFills
hook is an odd one, it returns an array for back-compat reasons, but the only thing that really matters is the .length
of the array. Ideally the hook would return just a number. Now it returns an "opaque" array with a given length but no contents.
If you review usages of useSlotFills
, we always look just at the .length
. The hook is asking: does this slot have any fills registered? If it doesn't, we typically don't render the slot at all, avoiding an empty element in the UI.
d30ada7
to
e6dfe36
Compare
e6dfe36
to
b204c5a
Compare
@tyxla @ciampo @Mamaduka Inspired by #71469, I decide to revive this very old PR from last year. It's a significant simplification and unification of
Splitting to multiple PR is not really possible, because the changes are interconnected: as soon as the two registries are unified, the implementation of I'm afraid that doing a really thorough informed review requires some investment into learning how I can comment the code better though, that's one thing I can do 🙂 |
Unification of both
SlotFill
registries (context providers) into one that handles both types. The two types ofSlot
are distinguished by atype: 'children'
ortype: 'portal'
field.Also the
Fill
component is now only one. It looks at the type of the currently registered slot and conditionally renders a portal.Only the
Slot
components remain separate for now, because their implementation and even the prop types are wildly different.This is still a draft, to verify how unit and e2e tests are going.