Fix ExcludePostsControl fetching all posts#160
Open
PatelUtkarsh wants to merge 20 commits intoryanwelcher:trunkfrom
Open
Fix ExcludePostsControl fetching all posts#160PatelUtkarsh wants to merge 20 commits intoryanwelcher:trunkfrom
PatelUtkarsh wants to merge 20 commits intoryanwelcher:trunkfrom
Conversation
Replace per_page: -1 with per_page: 25 and add search support in ExcludePostsControl, matching the existing IncludePostsControl pattern. This prevents endless paginated REST API calls that hang the editor on sites with many posts. Fixes: ryanwelcher#157
- Fetch saved exclude IDs separately via include param so saved selections are never dropped from the token field - Cache resolved posts in a ref so title lookups survive search input resets - Add search_columns: post_title so REST results match what FormTokenField filters client-side - Add _fields: id,title to keep responses lightweight - Set per_page: 10 to match IncludePostsControl
- debounce the search input - only call server when we have a search argument - limit search_column to title, and only return id and title - user friendly messages when searching instead of No items found with no spinner
- port UX improvements from PostIncludeControls
- both now use a common PostPickerControl - legacy support for ExcludePostsControl where the block attribute is an array of IDs
…y-title Fix/include posts search by title
…alues when called with the same state and parameters." warning
… returned from useSelect every time.
…y-title Refactor ExcludePostsControl and PostIncludesControl
…y-title fix JS linting errors
…y-title Addressing linting errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #157
Props to @trevormills-xwp for the PostPickerControl refactor, debounce, loading states, and backwards compat migration.
Problem
ExcludePostsControlcallsgetEntityRecordswithper_page: -1. The REST API middleware splits this into paginated requests of 100. On sites with thousands of posts, these requests pile up, hang the block editor, and block post saving and autosaves.Fix
Refactors both
ExcludePostsControlandPostIncludeControlsinto a sharedPostPickerControlcomponent that:per_page: -1withper_page: 10with debounced search-as-you-type (500ms)search_columns: post_titleso REST results match whatFormTokenFieldfilters client-side_fields: id,titleto keep responses lightweightSetto preventFormTokenFieldissuesBackwards compatibility:
exclude_postsattribute format changed from[id, id]to[{id, title}, ...]to matchinclude_postsuseSelect+useEffectExclude_Poststrait updated to handle numeric,{id, title}, and plain array formatsOther changes:
defined('ABSPATH') || exitchanged toifblock in PHP files for phpunit compatibilityTesting
exclude_posts(array of IDs) - confirm auto-migration to{id, title}format.wp/v2/postsrequests withper_page=10, not paginated chains.