-
-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Describe the bug
First, thank you for this amazing library! I recently discovered Hyper Fetch and I’m really surprised it’s not more popular given its quality.
However, I’m facing an issue when adding custom storage (MMKV) to the fetchDispatcher and submitDispatcher.
When I configure them with my storage implementation, all requests stay in pending state and are never sent.
If I remove the storage from fetchDispatcher/submitDispatcher (or use an empty new Dispatcher({})), everything works fine.
To Reproduce
Steps to reproduce the behavior:
- Configure a client with MMKV storage adapters for cache, fetchDispatcher, and submitDispatcher.
- Create a simple GET request with
.createRequest(). - Try to execute the request.
- The request never leaves pending state.
Expected behavior
The request should be executed and return a response, just like when no storage is provided.
Code Snippets
Client configuration:
export const $hyperFetch = new Client({
url: ENV.EXPO_PUBLIC_API_URL,
appManager: () =>
new AppManager({
initiallyOnline: () =>
NetInfo.fetch().then((state) => !!state.isConnected),
onlineEvent: (setOnline) => {
return NetInfo.addEventListener((state) => {
setOnline(!!state.isConnected);
});
},
}),
cache: () => new Cache({ storage: cacheStorage }),
fetchDispatcher: () => new Dispatcher({ storage: fetchDispatcherStorage }),
submitDispatcher: () => new Dispatcher({ storage: submitDispatcherStorage }),
})
.onAuth((request) => {
const cookie = authClient.getCookie();
return request.setHeaders({
...request.headers,
Cookie: `${cookie}`,
});
})
.setDebug(true)
.addPlugin(DevtoolsPlugin({ appName: "Infinity-dev" }));Storage
export const fetchDispatcherStorage: DispatcherStorageType = {
set: (key, data) => fetchDispatcherMMKV.set(key, JSON.stringify(data)),
get: (key) => {
const value = fetchDispatcherMMKV.getString(key);
return value ? JSON.parse(value) : undefined;
},
keys: () => fetchDispatcherMMKV.getAllKeys(),
entries: function* () {
const keys = fetchDispatcherMMKV.getAllKeys();
for (const key of keys) {
yield [key, JSON.parse(fetchDispatcherMMKV.getString(key) || "null")] as [string, any];
}
},
delete: (key) => fetchDispatcherMMKV.delete(key),
clear: () => fetchDispatcherMMKV.clearAll(),
};Example request:
const getNotifications = $hyperFetch.createRequest()({
endpoint: "/notifications",
method: "GET",
cacheKey: "GET_NOTIFICATIONS",
});Desktop (please complete the following information):
- OS: macOS
- Browser: (not applicable, React Native)
- Version: latest
Smartphone (please complete the following information):
- Device: iPhone Simulator
- OS: iOS (Expo / React Native)
- Browser: N/A
Additional context
- If I remove the
fetchDispatcherandsubmitDispatcherstorage, everything works. - If I set them as
new Dispatcher({}), everything works. - With MMKV storage, requests remain in
pendingstate forever. - Environment: Expo + React Native.