Skip to content
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

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Nov 18, 2024

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 the ref.current.name value is updated when name changes.

There's also a second effect that updates ref.current.children and rerenders the slot when children change. This one needs additional slot dependency. The slot object is constant the entire time a slot is mounted.

@jsnajdr jsnajdr added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Nov 18, 2024
@jsnajdr jsnajdr self-assigned this Nov 18, 2024
Copy link

github-actions bot commented Nov 18, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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 );
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@youknowriad youknowriad left a 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.

Copy link
Member

@Mamaduka Mamaduka left a 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!

@jsnajdr
Copy link
Member Author

jsnajdr commented Nov 18, 2024

For some reason the e2es are failing repeatedly. It's a low level failure -- failed WP database connection.

Copy link

Flaky tests detected in 52f0c8f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11892091496
📝 Reported issues:

@jsnajdr jsnajdr merged commit f6e6e45 into trunk Nov 18, 2024
65 of 66 checks passed
@jsnajdr jsnajdr deleted the update/slot-fill-effects branch November 18, 2024 14:26
@github-actions github-actions bot added this to the Gutenberg 19.8 milestone Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants