-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Revert introduction of useApiFetch hook and associated changes to Core Navigation block data fetching. #21674
Revert introduction of useApiFetch hook and associated changes to Core Navigation block data fetching. #21674
Conversation
Size Change: -572 B (0%) Total Size: 840 kB
ℹ️ View Unchanged
|
*loadPostTypeEntities
"
I'm fine with this. Because And a note here: Prior art: |
@aduth Looking at |
Leave it in place, yes. Normally we'd want to remove any associated documentation as well. In this instance, it turned out fortunate that we neglected to document the new hook, so there's nothing to do there. |
I like this hook personally and I believe if I had to use apiFetch for some reason on a component, it's better to use this hook over a custom lifecycle implementation. Not saying we shouldn't remove it since it's not used elsewhere but 🤷 I wouldn't mind if we replace our adhoc apiFetch calls with it. (Data store is better in most cases though) |
Inconvenience can be a feature. If we don't think this is an ideal way to implement components, we should go out of our way to avoid introducing conveniences. More: #18669 (comment) |
I agree with you but If I think as a plugin author, sometimes I have just one off personal endpoints and I don't want to create a whole store for that. In Gutenberg itself it's hard to find a use-cases where a store is not better though (aside the current limitations related to rights) |
If we had clear and well-respected guidelines around that, it might not be as much a concern. Currently I can't help but see it as being far too ripe for misuse. Personally, I'd rather spend the effort:
|
After using a similar library on a personal project (react-fetching-library), I found that it's perfect for most use-cases and useApiFetch is very similar. So I'm not saying that I'd use it just because it's more convenient than creating a store, I'd use it because the abstraction feels right for these use-cases, a store won't bring anything useful here no matter how easy it is to create. That said, I'm fine with removing it here right now (it can easily be created on the third-party code itself) |
Personally, I see no issue to just tell people to use something like |
Fair, but in that case why do we have an apiFetch package :), they could just use fetch right? |
This is the part where I relent my absolutism and grant there are balances to make. The value that |
I think this is a critical question and is a weakness of the current |
I've seen I wonder @aduth would you recommend creating a store for a single block?
I'll run with this. |
There's far too many considerations involved in a question like this to be able to give a single concrete answer. Most cases: Probably not? |
I've split this PR to make things easier to manage. One PR to rollback the Nav changes and one PR to deprecate useApiFetch. This should make things easier to manage and reason about and also to get approving reviews. Here are the new PRs:
|
* Adds deprecation notice to useApiFetch hook See #21674 (comment) * Simplify deprecation message * Fix e2e tests by expecting deprecation notice * Fix useApiFetch warning in related tests * Update lockfile * Update warning to use correct deprecation version * Update version ref in tests * Fix remaining versions refs in tests
This reverts commit f2b6778 which was based on #18669.
Description
The commit which this PR reverts introduced
apiFetch
over Core data entities.useApiFetch
which unduly promotes the use ofapiFetch
as a "preferred" API.The reason this needs to be reverted are:
apiFetch
should not be promoted as a first class API for data fetching. Therefore we should not make it easy to use via hooks such asuseAPIFetch
which was introduced. @aduth suggested the hook should be removed.edit
implementation was re-written to remove all entity based data fetching via Core Data mechanics in favour ofapiFetch
. This should be avoided for the reasons I set out here.You can also read more about why
apiFetch
might not be a good choice for data fetching.The only issue with reverting this PR is that we lose the fix to the
context
parameter which you can read about in the original PR descriptio. We could raise a followup PR to try and restore this functionality if desired.How has this been tested?
master
). This revert should cause no regressions.Types of changes
Breaking change (fix or feature that would cause existing functionality to not work as expected).
This removes a public API in the
useApiFetch
hook.Checklist: