-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Editor: Avoid unbound requests in inserter selectors #66817
base: trunk
Are you sure you want to change the base?
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -9 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Flaky tests detected in a2a817b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13071176532
|
Initially, this test existed to be able to hide the "reusable blocks" tab in the inserter entirely. Some folks didn't want reusable blocks at all. Now, I'm not sure if there's a way for the "patterns" tab to be removed entirely from the inserter and whether the change here impacts it. |
Regarding Riad's comment above, if the check is needed somewhere an alternative could be to have a new light request/selector to query just for one item. We do something similar for media categories |
Where is this reusable blocks tab? If you don't want reusable blocks, remove
This would mean another selector-setting that we need to pass through block-editor settings. It would be great if we can avoid that. |
I'm glad I found this PR. I had a similar idea when we worked on fixes for recent performance regressions related to patterns. |
65053ae
to
3e758b0
Compare
Sorry for the forced push, but it was the easiest way to resolve conflicts and introduce additional changes. I've also removed My only worry here was direct insert when |
@@ -2374,7 +2367,6 @@ export const getAllowedBlocks = createRegistrySelector( ( select ) => | |||
}, | |||
( state, rootClientId ) => [ | |||
getBlockTypes(), | |||
unlock( select( STORE_NAME ) ).getReusableBlocks(), | |||
...getInsertBlockTypeDependants( select )( state, rootClientId ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this dependent method, we'll have to keep using createRegistrySelector
. See #66833.
3e758b0
to
a2a817b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with this selector, but would it have any side effects if there were no reusable blocks on a site?
The only case I can think of is when the site disables all the blocks except I noticed that this change made the following test flaky - "Synced pattern › can be inserted after refresh". I need to investigate that before this is ready to land. |
Thanks for taking it over |
What?
Easier to review without whitespace.
This is part of an effort to refactor
getReusableBlocks
and make reusable blocks paginated.Why?
Currently,
getReusableBlocks
makes an unbound request, triggering the fetching of all reusable user blocks, page by page, until the last page.getAllowedBlocks
is used for example in the block inserter button, which means that simply selecting an empty paragraph, which shows the inserter button, triggers a cascade of requests. This is problematic for sites that have thousands of reusable user blocks.How?
The check is currently only done to conditionally include
core/block
in the list of allowed blocks. Why not assume that all sites have at least one reusable block and eliminate this call entirely?Testing Instructions
Open the network tab. Select an empty paragraph, or simply create a new post (which also shows the inserter button). Notice the cascade of requests. With this PR the requests should be gone. If you want to try adding many reusable blocks, use this command:
Testing Instructions for Keyboard
Screenshots or screencast