-
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
SlotFill: fix dependencies of registration effects, deduplicate code #67071
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. |
@@ -11,7 +11,7 @@ import useSlot from './use-slot'; | |||
import type { FillComponentProps } from './types'; | |||
|
|||
export default function Fill( { name, children }: FillComponentProps ) { | |||
const { registerFill, unregisterFill } = useContext( SlotFillContext ); | |||
const registry = useContext( SlotFillContext ); |
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 a stable value?
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, as long as the context provider is the same, the registry
is a constant object.
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.
This simplifies things a lot. It's way more clear now.
23864f6
to
52f0c8f
Compare
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 improvement. Thank you, @jsnajdr!
For some reason the e2es are failing repeatedly. It's a low level failure -- failed WP database connection. |
Flaky tests detected in 52f0c8f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11892091496
|
This PR tidies up the code for a
Fill
registration and rendering.For registration and unregistration, there used to be two effects: one runs on mount/unmount, another on
name
change. They can be easily merged into one with a[ name ]
dependency. Registration and unregistration still happens at exactly the right times. And also theref.current.name
value is updated whenname
changes.There's also a second effect that updates
ref.current.children
and rerenders the slot whenchildren
change. This one needs additionalslot
dependency. Theslot
object is constant the entire time a slot is mounted.