You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Core data: postType/attachment and root/media entities duplicate one another #70815
Core data has two separate entities that represent the same document type / REST endpoint:
The postTypeattachment entity is dynamically created via loadPostTypeEntities
The rootmedia entity is declared in the list of entities
Both use the wp/v2/media REST endpoint.
The problem with having two entity types is that they maintain separate caches for the same data. We might invalidate the cache for one entity via a call like saveEntityRecord, and the other entity then contains stale data that hasn't been invalidated. There's no control over which one plugins and code in the wider WordPress ecosystem uses, so we can't easily consider that best practice is to use one of the entities.
The best solution might be to deprecate one of the entities and implement some kind of redirect to the other entity to maintain back compat.
Step-by-step reproduction instructions
With the block editor open, using the browser console, run wp.data.select( 'core' ).getEntityRecords( 'postType', 'attachment' );
In the network tab, observe a request to wp/v2/media is triggered
Now run wp.data.select( 'core' ).getEntityRecords( 'root', 'media' );
Observe an identical request to wp/v2/media was made
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Please confirm which theme type you used for testing.
The best solution might be to deprecate one of the entities and implement some kind of redirect to the other entity to maintain back compat.
To add, these entities aren't widely used. There's a small amount of usage of the media entity internally, none of attachment that I can see. The media entity has a small benefit that it treats caption and description as a raw field (meaning it's converted from an object to a string internally). Adding that handling to attachment is possible, but I think it would be a back compat break.
I've done a brief exploration of how we might deprecate and there aren't many good options. My first thought was to wrap the selectors, actions, and resolvers to handle the deprecation. Something like that might still be the best option. It's a lot of code.
I also considered using a proxy within the reducer to redirect any access to the entities, but I quickly learned that JS proxies have some pretty significant performance issues.
Found another option while exploring, which is to utilize the __unstableNormalizeArgs feature added by #52120. It works for selectors possibly also for resolvers (though I'd need to check it works when they're called via resolveSelect). I don't think it works for actions, so that would be needed.
I think it's similar to wrapping the functions in that it adds quite a lot of extra code, but using an existing API feels like a better solution.
Activity
talldan commentedon Jul 21, 2025
To add, these entities aren't widely used. There's a small amount of usage of the
mediaentity internally, none ofattachmentthat I can see. Themediaentity has a small benefit that it treatscaptionanddescriptionas a raw field (meaning it's converted from an object to a string internally). Adding that handling toattachmentis possible, but I think it would be a back compat break.I've done a brief exploration of how we might deprecate and there aren't many good options. My first thought was to wrap the selectors, actions, and resolvers to handle the deprecation. Something like that might still be the best option. It's a lot of code.
I also considered using a proxy within the reducer to redirect any access to the entities, but I quickly learned that JS proxies have some pretty significant performance issues.
Mamaduka commentedon Jul 21, 2025
I think this was an oversight on our side. The
root|mediashould be the only core entity for the attachment post types.DarkMatter-999 commentedon Jul 21, 2025
In that case, we can simply prevent the
attachmentPost type from registering inloadPostTypeEntities()asroot/mediatakes care of that.talldan commentedon Jul 22, 2025
Plugins might already be using the
attachmententity, so it's not as simple as removing it, that would break those plugins.talldan commentedon Jul 22, 2025
Found another option while exploring, which is to utilize the __unstableNormalizeArgs feature added by #52120. It works for selectors possibly also for resolvers (though I'd need to check it works when they're called via resolveSelect). I don't think it works for actions, so that would be needed.
I think it's similar to wrapping the functions in that it adds quite a lot of extra code, but using an existing API feels like a better solution.