-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Core Data: specify context=edit only when needed #30482
Conversation
Size Change: +39 B (0%) Total Size: 1.47 MB
ℹ️ View Unchanged
|
packages/core-data/src/entities.js
Outdated
@@ -39,13 +39,15 @@ export const defaultEntities = [ | |||
kind: 'root', | |||
key: 'slug', | |||
baseURL: '/wp/v2/types', | |||
params: { context: 'edit' }, |
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.
Should this be something more like "defaultParams" or something like that? (Don't take my suggestion as a recommendation, I'm no good at naming things, just trying to raise a discussion point)
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.
Good question! I updated to URLparams
and moved them all immediately below baseURL
to try and make it clearer these are for constructing the endpoint URL.
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 think this makes sense.
Looks like there's a valid test failure. The "types" endpoint does support the context argument. |
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.
It all seems to work fine, but I'm a bit unclear how I'm supposed to test this. 🤔
I've tried to compare this branch to trunk, and everything looks exactly the same — with the exception of the URLparams
property in the core
state (added to the appropriate elements of root.entities.config
).
Great point, @Copons. I made another update to the name of this:
@youknowriad I forgot to update the test entity object when changing the name of
@Copons One thing you can test is if the site icon (when set) shows in the upper left corner of the editor. With the filtering of Similarly, loading the editor fails (blank white screen) when the entity api paths don't match the critical preload paths. I know testing for "not failure" isn't ideal, but one thing you can do is verify that the entity urls generated by the resolver match those preload paths (just by console.log, if nothing else!) |
This approach looks great to me. I haven't tested for regressions though. |
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.
Thanks for the pointers @creativecoder!
I already tested in roughly the same ways you suggested and it worked as expected; I also haven't noticed any regressions in either post and site editors, so it should be good to go! 🙂
e94c91d
to
6825f8c
Compare
Note that I've added a new unit test for the Any other suggestions for regression testing this? Otherwise I think it's ready to merge. |
Does it require any changes in WordPress core? The list of preloaded paths is here: |
Good question! I don't think so: those existing preload paths match what core-data is using. A main goal of this PR was to remove the |
@creativecoder, nice. Thank you for checking 👍🏻 |
Description
API requests for fetching entities currently add
context=edit
to all requests. Some endpoints do not use this parameter, which can cause unexpected problems, like the need to preload both the/
and/?context=edit
endpoints (which both have exactly the same response).This change allows specifying query parameters specific to each entity, and adds
context=edit
only to the entities that use that parameter.This resolves the (rejected) Core ticket (https://core.trac.wordpress.org/ticket/50606) and removes the associated filter for preloading
/?context=edit
.Follows up on #22952.
How has this been tested?
/?context=edit
endpoint.context=edit
parameter is added only to the endpoints where it's a valid parameterYou can also compare resolver paths for entities with and without this branch applied, for example:
/?context=edit
/
/wp/v2/settings/?context=edit
/wp/v2/settings
/wp/v2/types/post?context=edit
/wp/v2/types/post?context=edit
/wp/v2/templates/tt1-blocks//single?context=edit
/wp/v2/templates/tt1-blocks//single?context=edit
/wp/v2/__experimental/global-styles/26?context=edit
/wp/v2/__experimental/global-styles/26?context=edit
/wp/v2/media/10?context=edit
/wp/v2/media/10?context=edit
/wp/v2/taxonomies/category?context=edit
/wp/v2/taxonomies/category?context=edit
/wp/v2/taxonomies/post_tag?context=edit
/wp/v2/taxonomies/post_tag?context=edit
/wp/v2/users/1?context=edit
/wp/v2/users/1?context=edit
Note how
/
and/settings
correctly no longer use?context=edit
, but other endpoints still do.Screenshots
Site icon displayed in upper left corner:
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.js
files for terms that need renaming or removal).