@kawaiininja/fetch 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,6 +22,6 @@ export interface ApiProviderProps {
|
|
|
22
22
|
export declare const ApiContext: React.Context<ApiContextValue | null>;
|
|
23
23
|
/**
|
|
24
24
|
* ApiProvider
|
|
25
|
-
* 🛡️ GOD-LEVEL STABILITY:
|
|
25
|
+
* 🛡️ GOD-LEVEL STABILITY: Decouples helper identity from render cycles.
|
|
26
26
|
*/
|
|
27
27
|
export declare function ApiProvider({ config, children }: ApiProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback,
|
|
2
|
+
import { createContext, useCallback, useMemo, useRef, useEffect } from "react";
|
|
3
3
|
export const INTERNAL_HEADER = {
|
|
4
4
|
"x-internal-service": "zevrinix-main",
|
|
5
5
|
};
|
|
6
6
|
export const ApiContext = createContext(null);
|
|
7
7
|
/**
|
|
8
8
|
* ApiProvider
|
|
9
|
-
* 🛡️ GOD-LEVEL STABILITY:
|
|
9
|
+
* 🛡️ GOD-LEVEL STABILITY: Decouples helper identity from render cycles.
|
|
10
10
|
*/
|
|
11
11
|
export function ApiProvider({ config, children }) {
|
|
12
12
|
const baseUrlRef = useRef(config?.baseUrl || "");
|
|
@@ -16,8 +16,8 @@ export function ApiProvider({ config, children }) {
|
|
|
16
16
|
onErrorRef.current = config?.onError;
|
|
17
17
|
}, [config?.baseUrl, config?.onError]);
|
|
18
18
|
/**
|
|
19
|
-
* 🛡️
|
|
20
|
-
* Identity is
|
|
19
|
+
* 🛡️ PERMANENT IDENTITY URL HELPER
|
|
20
|
+
* Identity is fixed for the life of the App. No downstream loops possible.
|
|
21
21
|
*/
|
|
22
22
|
const apiUrl = useCallback((path) => {
|
|
23
23
|
const base = baseUrlRef.current;
|
package/dist/hooks/useFetch.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { ApiSurface } from "./utils";
|
|
|
2
2
|
export { clearNativeAuthVault } from "./useFetch.vault";
|
|
3
3
|
/**
|
|
4
4
|
* useFetch Hook
|
|
5
|
-
* 🛡️ STACK PROTECTION: Macro-task Flattening
|
|
5
|
+
* 🛡️ STACK PROTECTION: Macro-task Flattening + Identity Locking
|
|
6
6
|
*/
|
|
7
7
|
export declare const useFetch: <T = any>(endpoint: string, baseOptions?: any) => ApiSurface<T>;
|
package/dist/hooks/useFetch.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createApiMethods } from "./utils";
|
|
|
6
6
|
export { clearNativeAuthVault } from "./useFetch.vault";
|
|
7
7
|
/**
|
|
8
8
|
* useFetch Hook
|
|
9
|
-
* 🛡️ STACK PROTECTION: Macro-task Flattening
|
|
9
|
+
* 🛡️ STACK PROTECTION: Macro-task Flattening + Identity Locking
|
|
10
10
|
*/
|
|
11
11
|
export const useFetch = (endpoint, baseOptions = {}) => {
|
|
12
12
|
const { apiUrl, onError, debug } = useApiConfig();
|
|
@@ -15,10 +15,19 @@ export const useFetch = (endpoint, baseOptions = {}) => {
|
|
|
15
15
|
const mounted = useRef(true);
|
|
16
16
|
const isRequestingRef = useRef(false);
|
|
17
17
|
// 🔒 Hold baseOptions in a Ref to prevent render-cycle re-triggers
|
|
18
|
+
// Removed Math.random() fallback which was causing infinite loops.
|
|
18
19
|
const optionsRef = useRef(baseOptions);
|
|
20
|
+
const optionsHash = useMemo(() => {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(baseOptions);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return endpoint;
|
|
26
|
+
}
|
|
27
|
+
}, [baseOptions, endpoint]);
|
|
19
28
|
useEffect(() => {
|
|
20
29
|
optionsRef.current = baseOptions;
|
|
21
|
-
}, [
|
|
30
|
+
}, [optionsHash]);
|
|
22
31
|
const [state, setState] = useState({
|
|
23
32
|
data: null,
|
|
24
33
|
loading: false,
|
|
@@ -27,9 +36,8 @@ export const useFetch = (endpoint, baseOptions = {}) => {
|
|
|
27
36
|
});
|
|
28
37
|
/**
|
|
29
38
|
* 🛡️ MACRO-TASK SETTER
|
|
30
|
-
* Using setTimeout(0)
|
|
31
|
-
*
|
|
32
|
-
* fully stop "Maximum call stack" errors in heavy Capacitor apps.
|
|
39
|
+
* Using setTimeout(0) forces a physical stack clear by the JS event loop.
|
|
40
|
+
* This stops the "Stack Pile" effect in production APKs.
|
|
33
41
|
*/
|
|
34
42
|
const safeSet = useCallback((fn) => {
|
|
35
43
|
if (!mounted.current)
|
|
@@ -59,9 +67,7 @@ export const useFetch = (endpoint, baseOptions = {}) => {
|
|
|
59
67
|
}
|
|
60
68
|
catch (err) {
|
|
61
69
|
if (err.name !== "AbortError") {
|
|
62
|
-
const msg = err.message || "Network
|
|
63
|
-
if (debug)
|
|
64
|
-
console.error(`[useFetch] [${endpoint}] Error:`, msg);
|
|
70
|
+
const msg = err.message || "Network Error";
|
|
65
71
|
safeSet(() => ({ error: msg, status: lastStatus }));
|
|
66
72
|
if (onError)
|
|
67
73
|
onError(msg, lastStatus);
|