WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.56k stars 4.22k forks source link

Core Data: Remove 'useQuerySelect' abstraction #64170

Open Mamaduka opened 3 months ago

Mamaduka commented 3 months ago

This is a proposal to remove the useQuerySelect hook, which was proposed in #38134 and used internally by the useEntityRecord(s) and useResourcePermissions public APIs.

The intention was to make it easier to query core data and its meta selectors. But it seems people (including me) are more comfortable working with plain old useSelect.

Example: A second store subscription for the useEntityRecord and the useEntityRecords hooks.

cc @adamziel, @gziolo, @jsnajdr, @tyxla, @youknowriad

tyxla commented 3 months ago

useQuerySelect never became a public API, right? Given that we only have internal usage, porting it will be relatively straightforward. With that in mind, the cost of removing it will be very little.

I actually find it better to use useSelect and to transparently query only for the selector resolution state that we'll actually use rather than querying it regardless of whether we're going to use it.

Furthermore, I think removing it will allow us to remove the last usage of memize and get rid of it as a dependency of the @wordpress/core-data package.

The only downside is that it might make the underlying useResourcePermissions and useEntityRecords code more complex. But it also makes us think - do we really need to always provide the resolution data alongside the actual permission data? Maybe we do, but in many other cases, we don't, so it's a good time to double-check our assumptions there.

Mamaduka commented 3 months ago

useQuerySelect never became a public API, right?

Yes, it's an internal/private API.

do we really need to always provide the resolution data alongside the actual permission data?

I can't think of any use case in the core when resolution status might be needed with permissions data. Usually, permissions return values act as resolutions. But we can't change that now since it's a public API.