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

Inserter: patterns refresh when selecting different blocks #65920

Closed
annezazu opened this issue Oct 7, 2024 · 17 comments · Fixed by #66159
Closed

Inserter: patterns refresh when selecting different blocks #65920

annezazu opened this issue Oct 7, 2024 · 17 comments · Fixed by #66159
Assignees
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@annezazu
Copy link
Contributor

annezazu commented Oct 7, 2024

Using 6.7 beta 1, I noticed that if I have the patterns tab open for the Inserter, it seems to be regularly re-rendering the list of patterns whenever I am clicking around the page. This sometimes leads to a "no results" similar to what's described here #65833

refreshing.inserter.mov

I am noting this as an enhancement as something to smooth out but it feels like a bug in many ways :)

@annezazu annezazu added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement. labels Oct 7, 2024
@andrewserong
Copy link
Contributor

but it feels like a bug in many ways

Same here. Just in case, I've added it to the 6.7 board, but feel free to remove if anyone thinks it's more of an enhancement idea.

@ndiego
Copy link
Member

ndiego commented Oct 7, 2024

Let's reclassify it as a bug. All enhancements should be removed from the 6.7 board at this point, and I agree that it feels very "buggy".

@ndiego ndiego added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. labels Oct 7, 2024
@colorful-tones
Copy link
Member

I feel like this may be a duplicate of #65833? 🤔

@ndiego
Copy link
Member

ndiego commented Oct 9, 2024

I feel like this may be a duplicate of #65833? 🤔

Definitely related, but I do not feel it's a duplicate. I added more testing feedback in that ticket.

@kevin940726
Copy link
Member

I might be missing something obvious, but this might be the expected behavior. When clicking around the page, we also move the focus to different blocks. Some blocks don't allow inserting patterns, thus it shows "no results." I think this becomes more visible because we no longer close the inserter when moving focus. I agree that the UI and the wording are confusing and feel "buggy," but I'm not sure what the expected behavior should be 🤔. Someone more familiar with the recent changes might be able to verify whether this is indeed a bug. 🙏

@ndiego
Copy link
Member

ndiego commented Oct 10, 2024

I am not sure how to achieve this from a technical standpoint, but the pattern panel should only visibly update if the available selection of patterns needs to change. Right now, it visually refreshes every time you click on something, even if the patterns that are available to the user do not actually change.

@ndiego
Copy link
Member

ndiego commented Oct 10, 2024

For example, in the video below, IMO the pattern panel should not visually refresh when clicking on the two blocks since the patterns that are available to the user do not change.

pattern-refreshing.mp4

@ramonjd
Copy link
Member

ramonjd commented Oct 15, 2024

I was just looking at #66053 and I'm also not sure how to do this. Memoizing the incoming block and shown patterns, or abstracting the list into a separate component doesn't seem to mitigate the refresh.

Somehow I think it's related to the AsyncList, passed to the component as shownPatterns.

Notice how its value changes between identical blocks. The patterns end up being the same, but not before they're not 😄

2024-10-15.12.19.58.mp4

For example, the flash completely goes away without it. E.g.,

					<BlockPatternsList
						ref={ scrollContainerRef }
/*
						shownPatterns={ pagingProps.categoryPatternsAsyncList }
*/
						shownPatterns={ pagingProps.categoryPatterns }
						blockPatterns={ pagingProps.categoryPatterns }

I'm not saying we remove it, only trying to identify the cause of the rerender trigger. 🤔

@kevin940726
Copy link
Member

I think a part of the reason why we introduced AsyncList here is because rendering patterns is too slow. I hope that someday we can revive #54999 and make them fast enough that we don't need this kind of hack. 🤔

@madhusudhand
Copy link
Member

The PR #66053 addresses the flickering problem.

I think a part of the reason why we introduced AsyncList here is because rendering patterns is too slow.

Part of the fix is to render only the async list instead of entire pattern list, which is fixing the problem.
I agree, removing the async list and fixing the block preview rendering gives better user experience.

@kevin940726
Copy link
Member

I also believe AsyncList was first introduced when we were not using any pagination, so that might not be needed now.

@madhusudhand
Copy link
Member

I also believe AsyncList was first introduced when we were not using any pagination, so that might not be needed now.

Created #66114 which removes async list and render performance is much better without it.

@getdave
Copy link
Contributor

getdave commented Oct 15, 2024

@WordPress/gutenberg-core Anyone with good experience of asyncList who could help here as this bug if going to be very noticeable for Zoom Out in WordPress 6.7.

Specifically

  • can we safely drop asyncList usage now we have pagination? Rendering 20 patterns upfront still seems high to me.
  • why does async list seem to return inconsistent results with the initial result sometimes higher than subsequent results?
  • other suggestions for avoiding the Patterns re-rendering as we move between blocks.

@youknowriad
Copy link
Contributor

can we safely drop asyncList usage now we have pagination? Rendering 20 patterns upfront still seems high to me.

Probably if we limit to 20 patterns. We should consider the Async component that is used in the site editor as a replacement.

@jsnajdr
Copy link
Member

jsnajdr commented Oct 15, 2024

The useAsyncList component ensures that we render only 5 patterns at a time. Then it schedules another 5 to be rendered a bit later and so on. This was useful when the component was limiting "unlimited" renders to 5, but maybe it's not so useful for limiting only 20 to 5.

When the component gets an identical list (but a different array) on a render update, it explicitly tries to find out if some part of the list is already rendered, see the getFirstItemsPresentInState function. So, if we click between two blocks that have the same list of patterns to select from, then it's a different array (filtered based on different criteria), but the result is the same. The hook should be able to detect that, it should not rerender the whole list with a "flash of empty content". If this doesn't happen, it's worth debugging why.

@jsnajdr
Copy link
Member

jsnajdr commented Oct 15, 2024

If the useAsyncList hook is presented with a new list that contains the same patterns, it will rerender them all from scratch anyway because the pattern objects are not really identical. The __experimentalGetAllowedPatterns selector does a mapping like this:

patterns.map( ( pattern ) => ( {
  ...pattern,
  get blocks() {
    return getParsedPattern( pattern ).blocks;
  },
} ) );

where even identical patterns get transformed to non-identical objects.

It could help to memoize these mapped patterns with a weakmap: WeakMap<RawPattern, EnhancedPattern>.

Then the flashes should go away. I can try it out in the next 24 hours.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Oct 16, 2024
@jsnajdr
Copy link
Member

jsnajdr commented Oct 16, 2024

#66159 is fixing this for me. The patterns list is stable and doesn't rerender when switching between selected blocks.

But locally I see another strange bug, I wonder if anyone else sees it, too:

Image

There is a really big vertical space between the patterns in the pattern list, each item occupies the entire height of the viewport. It's caused by the .block-editor-block-patterns-list__item element having a height: 100% style. The styles are old, there's no recent change. It seems like some change at another place changed the element against which the relative 100% value is calculated.

@github-project-automation github-project-automation bot moved this from 🔎 Needs Review to ✅ Done in WordPress 6.7 Editor Tasks Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
Status: Done
10 participants