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

CreateTemplatePartModal: avoid identity warning in useSelect #67786

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Dec 10, 2024

This patch should fix the useSelect warning that @mirka reports in #67702 (comment). It happens because the defaultTemplatePartAreas select returns a different value on every call, even though the inputs are exactly the same. That's because:

  • the [] default empty array is a different instance every time
  • the areas.map call always returns a different array, even though the input and the contents of the output are always the same

I'm fixing this by extracting the [] defaulting and the .map call outside the useSelect hook. The defaultTemplatePartAreas value is processed by another .map call, so I'm merging both into one. Computing the icon value just-in-time when rendering.

@jsnajdr jsnajdr added [Type] Code Quality Issues or PRs that relate to code quality [Package] Fields /packages/fields labels Dec 10, 2024
@jsnajdr jsnajdr requested review from mirka and gigitux December 10, 2024 10:43
@jsnajdr jsnajdr self-assigned this Dec 10, 2024
Copy link

github-actions bot commented Dec 10, 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 <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

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

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.

Fixes the warning in the new template part / duplicate template part modal 👍

Thanks @jsnajdr 🚀

Copy link

Flaky tests detected in 08773a3.
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/12254426886
📝 Reported issues:

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.

Thanks, @jsnajdr!

@jsnajdr jsnajdr merged commit b62887b into trunk Dec 10, 2024
70 of 72 checks passed
@jsnajdr jsnajdr deleted the fix/default-template-part-areas-select branch December 10, 2024 11:49
@github-actions github-actions bot added this to the Gutenberg 19.9 milestone Dec 10, 2024
@gigitux
Copy link
Contributor

gigitux commented Dec 10, 2024

Thanks! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Fields /packages/fields [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants