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

Composite: fix legacy implementation passing store prop #65821

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Oct 2, 2024

What?

Extracted from #65720

Fix internal implementation of Composite to make it work better with legacy usages

Why?

This fixes a big that could cause Composite to stop working as expected when used via its legacy, unstable exports

How?

By explicitly grabbing the store prop and explicitly prioritizing it against the store read from internal context.

This is necessary because of how the legacy implementation of Composite works, which allows folks to pass a state prop to the old version of the component, which we needed to "translate" to passing a store prop in our legacy compat layer.

Testing Instructions

  • All tests should pass
  • The legacy Storybook examples of Composite should continue to work
  • Make a change in Composite.Item that relies on the store logic (like the one applied in Composite: make items tabbable if active element gets removed #65720). On trunk, the change has a chance to break the CompositeItem legacy component, because it's not using the right store. This PR makes sure that, if the legacy implementation is passing a store via props, that store will be used instead.

@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Oct 2, 2024
@ciampo ciampo requested a review from a team October 2, 2024 11:04
@ciampo ciampo self-assigned this Oct 2, 2024
@ciampo ciampo requested a review from ajitbohra as a code owner October 2, 2024 11:04
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests well and code LGTM 👍 🚀 Thanks!

Just left a minor suggestion I made across all components about simplifying the code a bit.

packages/components/src/composite/group-label.tsx Outdated Show resolved Hide resolved
packages/components/src/composite/group.tsx Outdated Show resolved Hide resolved
packages/components/src/composite/hover.tsx Outdated Show resolved Hide resolved
packages/components/src/composite/item.tsx Outdated Show resolved Hide resolved
packages/components/src/composite/row.tsx Outdated Show resolved Hide resolved
packages/components/src/composite/typeahead.tsx Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Oct 2, 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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ciampo ciampo force-pushed the fix/composite-legacy-store-prop branch from 3a4e49c to 41ab175 Compare October 2, 2024 12:45
@ciampo
Copy link
Contributor Author

ciampo commented Oct 2, 2024

Copy link

github-actions bot commented Oct 2, 2024

Flaky tests detected in 41ab175.
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/11144041957
📝 Reported issues:

@ciampo
Copy link
Contributor Author

ciampo commented Oct 2, 2024

I tested on my machine and feel confident about the latest set of changes. Will merge once CI checks pass

@ciampo ciampo enabled auto-merge (squash) October 2, 2024 13:13
@tyxla
Copy link
Member

tyxla commented Oct 2, 2024

Yep, I can confirm the fix works as expected 👍

@ciampo ciampo merged commit 695600a into trunk Oct 2, 2024
63 checks passed
@ciampo ciampo deleted the fix/composite-legacy-store-prop branch October 2, 2024 13:49
@github-actions github-actions bot added this to the Gutenberg 19.4 milestone Oct 2, 2024
huubl pushed a commit to huubl/gutenberg that referenced this pull request Oct 2, 2024
)

* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
huubl added a commit to huubl/gutenberg that referenced this pull request Oct 2, 2024
draganescu pushed a commit that referenced this pull request Oct 2, 2024
* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
@ciampo ciampo added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

There was a conflict while trying to cherry-pick the commit to the wp/6.7 branch. Please resolve the conflict manually and create a PR to the wp/6.7 branch.

PRs to wp/6.7 are similar to PRs to trunk, but you should base your PR on the wp/6.7 branch instead of trunk.

# Checkout the wp/6.7 branch instead of trunk.
git checkout wp/6.7
# Create a new branch for your PR.
git checkout -b my-branch
# Cherry-pick the commit.
git cherry-pick 695600a5c4ab8b5f93ed896ed3b426e247107c57
# Check which files have conflicts.
git status
# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue
# Push the branch to the repository
git push origin my-branch
# Create a PR and set the base to the wp/6.7 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.

ciampo added a commit that referenced this pull request Oct 3, 2024
* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
@ciampo ciampo mentioned this pull request Oct 3, 2024
ciampo added a commit that referenced this pull request Oct 3, 2024
* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
ciampo added a commit that referenced this pull request Oct 3, 2024
* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
ciampo added a commit that referenced this pull request Oct 3, 2024
* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
@noisysocks noisysocks added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants