Make WordPress Core

Opened 8 weeks ago

Last modified 6 weeks ago

#66105 new enhancement

Site Editor: Preserve block search state when returning from a block in Styles

Reported by: smhz101 Owned by:
Priority: normal Milestone: Awaiting Review
Component: Editor Version: 7.1
Severity: normal Keywords:
Cc: Focuses: ui

Description

When working in the Site Editor under Styles > Blocks, the search field is useful for finding related blocks.

The problem is that the search is cleared after opening one of the results and then going back to the Blocks list.

For example, if I search for "Post", open the Post Title block, make or review some style changes, and then go back, the search field is empty again and the full list of blocks is shown.

When working through several related blocks, this means entering the same search again after every block.

I think the previous search should be preserved when returning to the Blocks screen.

Steps to reproduce

  1. Open Appearance > Editor.
  2. Open Styles.
  3. Go to Blocks.
  4. Search for something, for example "Post".
  5. Open one of the blocks from the search results.
  6. Open or change its styles.
  7. Go back to the Blocks list.

Current result

The previous search is cleared and the full list of blocks is shown.

Expected result

The search term should still be present and the previous filtered results should still be shown.

For example:

Search "Post"
-> Open Post Title
-> Edit/review styles
-> Go back
-> Search "Post" is still active

This would make it easier to work through multiple related blocks without having to repeat the same search every time.

Change History (2)

#1 @abcd95
7 weeks ago

The search state in Styles > Blocks is held in a local useState inside the ScreenBlockList component (packages/global-styles-ui/src/screen-block-list.tsx). The Navigator component (which powers the sidebar's screen transitions) fully unmounts ScreenBlockList when you navigate into a block, and mounts a fresh copy when you go back, so the search value just doesn't exist anymore.

The fix is straightforward: lift filterValue (and styleFilter, which has the same problem) to the parent in global-styles-ui.tsx, which stays alive during the whole round-trip, and pass them down as props. That's already the established pattern in Gutenberg both the block inserter search and the patterns panel search hoist their filter state the same way, for exactly this reason.

I also want to remind you that this component lives in the global-styles-ui package in the ​Gutenberg repo here, so the code change itself would need to be a PR against WordPress/gutenberg. The Trac ticket is a good place to track it, but the actual fix lives upstream. So you can open an ​issue there for a better discussion.

#2 @smhz101
6 weeks ago

Thanks for pointing me in the right direction. I found Gutenberg issue #52851, which looks like the same issue:
​https://github.com/WordPress/gutenberg/issues/52851

It looks like it was recently closed as not planned due to lack of activity, but the issue is still reproducible in WordPress 7.1.

I'll add my current reproduction there and link back to this Trac ticket.

Note: See TracTickets for help on using tickets.