Trac63946/rest lazy load namespaces#10080
Trac63946/rest lazy load namespaces#10080prettyboymp wants to merge 16 commits intoWordPress:trunkfrom
Conversation
|
Hi @prettyboymp! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…change around namespaces that partially match existing namespaces
| * ) ); | ||
| * } ); | ||
| */ | ||
| do_action( 'rest_lazy_load_namespace_' . $route_namespace ); |
There was a problem hiding this comment.
This somewhat breaks from convention around only using underscores for hooks since by their own convention namespaces are almost always going to contain dashes and slashes. Would it be better to convert these for the hook for the sake of convention or leave it as is?
There was a problem hiding this comment.
This also isn't a recommended pattern anymore. The namespace should just be it's own parameter.
There was a problem hiding this comment.
This also isn't a recommended pattern anymore. The namespace should just be it's own parameter.
@TimothyBJacobs, do you happen to have a reference to some relevant discussion around this? There seem to still be (relatively) recent hooks added with this pattern.
I would hate for every callback created for lazy route registration to have to start with if( '/my-plugin-namespace' === $route_namespace )....
There was a problem hiding this comment.
Usually WP provides hooks for both. e.g. do_action( 'rest_lazy_load_namespace_' . $route_namespace, $route_namespace ); and do_action( 'rest_lazy_load_namespace', $route_namespace );
|
I rebased against trunk and performed a Claude review. There may be some issues that need to be addressed so sharing them here before looking deeper and/or asking for more eyes. Review NotesPositives
Issues & Concerns1. After calling 'namespaces' => array_keys( $this->namespaces ),If a lazy-loaded namespace's action registers routes via 'namespaces' => array_keys( $this->namespaces + $this->lazy_namespaces ),2.
3. Namespace matching in if ( str_starts_with( trailingslashit( ltrim( $path, '/' ) ), $namespace ) ) {This checks if the path starts with the namespace string, but without a trailing slash on if ( str_starts_with( trailingslashit( ltrim( $path, '/' ) ), trailingslashit( $namespace ) ) ) {(Note: this bug likely pre-exists in trunk's 4. Validation order in The 5. Typo in comment
6. Missing
7. The generic 8. No test for The global 9. Route priority tests seem unrelated to lazy loading
|
- Fix namespace prefix collision in match_request_to_handler() by adding trailingslashit() to namespace comparison. - Reorder validation in register_rest_namespace() so is_string() check runs before empty() to avoid array-to-string warnings. - Fix "namespases" typo. - Add missing @SInCE tags to new methods. - Flesh out rest_lazy_load_namespace action docblock with description and @param. - Clarify route priority test docblocks to explain their relevance to lazy loading changes. - Resolve @todo in test: lazy namespaces intentionally excluded from get_namespaces() until loaded. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@kraftbj, thanks for the reviewing. I addressed several items in 9233b0f. 1. 2. 3. Namespace prefix collision — Fixed. Added 4. Validation order - Fixed. 5. Typo — Fixed. 6. Missing 7. Generic action docblock - Fixed. Added full description and 8. Validation path tests - Skipping for now, but happy to add if we think its helpful. There's no existing precedent for testing 9. Route priority test docblocks - Fixed. Added clarifying text that these document existing route priority behavior that the lazy loading changes to |
Adds support for registering namespaces to the REST API Server for the purposes of lazy loading. The server will trigger a action specific to that namespace when corresponding routes would need to be loaded. This provides a performance improvement when adding new namespaces and routes by reducing the number of routes that need to be checked for matches and avoiding unnecessary translation processing.
Trac ticket: https://core.trac.wordpress.org/ticket/63946
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.