Skip to content

Fix: pattern selection missing after making duplicate selection - #434

Merged
brookewp merged 3 commits into
trunkfrom
fix/pattern-issues
Mar 26, 2025
Merged

Fix: pattern selection missing after making duplicate selection#434
brookewp merged 3 commits into
trunkfrom
fix/pattern-issues

Conversation

@brookewp

Copy link
Copy Markdown
Contributor

@alecgeatches found an issue after selecting the same item in succession. When doing so, no patterns are available to select in the modal:

missingpatterns.mov

This appears to be due to a brief moment where __experimentalGetAllowedPatterns returns an empty array, and its state isn't updated. I believe this happened because __experimentalGetAllowedPatterns was extracted from useSelect as a function reference rather than tracking its return value.

Solution

In this PR, __experimentalGetAllowedPatterns(rootClientId) is now inside the selector function, to ensure its result is included in useSelect's state tracking.

restoredpatterns.mov

Testing

After selecting an item in a block (replicated in the art institute and airtable blocks), add another block and make the same selection. You should see patterns to select (ensure custom patterns are present in addition to default).

Signed-off-by: brookewp <brooke.kaminski@automattic.com>
Signed-off-by: brookewp <brooke.kaminski@automattic.com>
@brookewp brookewp added the bug Something isn't working label Mar 25, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Test this PR in WordPress Playground.

@chriszarate

chriszarate commented Mar 26, 2025

Copy link
Copy Markdown
Member

I believe this happened because __experimentalGetAllowedPatterns was extracted from useSelect as a function reference rather than tracking its return value.

This is correct, and my fault because I don't think I read the docs closely:

When data is only used in an event callback, the data should not be retrieved
on render, so it may be useful to get the selectors function instead.

Don’t use useSelect this way when calling the selectors in the render
function because your component won’t re-render on a data change.

I will do a review to find other spots where I made this mistake.

Note I pushed up a type improvement in ad920af.

@chriszarate chriszarate reopened this Mar 26, 2025

@alecgeatches alecgeatches left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@brookewp
brookewp merged commit 215f1f7 into trunk Mar 26, 2025
@brookewp
brookewp deleted the fix/pattern-issues branch March 26, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants