Core Data: Avoid duplicate id-less entity permission requests#78262
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. |
31ffddd to
c924a31
Compare
Site Editor evidenceI also checked the change against the Site Editor preload scenario that exposed the duplicate request. Environment:
Observed network behavior for
Representative captured rows: Aggregate run metrics:
I would not read the timing from this run as a stable performance win, because it was collected with |
dd5ad75 to
65856c0
Compare
|
Thanks, @chubes4! It looks like change is causing the test in packages/block-library/src/navigation/test/use-navigation-menu.js to fail. P.S. IMO, introducing |
65856c0 to
3815658
Compare
|
Thanks for catching that, @Mamaduka. I updated the Navigation unit test helper to resolve the same normalized id-less collection resource used by Verified locally: |
|
Thank you! 🦾 |
What?
Fixes duplicate permission resolution for id-less entity resources in
useResourcePermissions()by normalizing the collection resource once and using that same resource for bothcreateand id-lessreadchecks.Fixes #78260.
Why?
When callers pass an entity resource with
id: undefined,createwas resolved against the normalized collection resource whilereadwas resolved against the original object. For entities likewp_navigation, both checks target the same REST route, but they used different resolver arguments, so core-data could issue duplicateOPTIONS /wp/v2/navigationrequests.Testing Instructions
npm run test:unit -- --runTestsByPath packages/core-data/src/hooks/test/use-resource-permissions.js --runInBand.npm run lint:js -- packages/core-data/src/hooks/use-resource-permissions.ts packages/core-data/src/hooks/test/use-resource-permissions.js.Evidence
wp_navigationentity resource withid: undefined./wp/v2/navigationwas requested twice.core-datapatch removed the duplicate networkOPTIONS /wp/v2/navigationrequest. Homeboy run:2d3a992d-1326-4207-9d00-75aac9e8598f.AI assistance