@kawaiininja/fetch 1.0.22 → 1.0.23
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.
- package/dist/context/ApiContext.js +22 -5
- package/package.json +1 -1
|
@@ -14,11 +14,28 @@ export const ApiContext = createContext(null);
|
|
|
14
14
|
* Constructs full API URLs from relative paths using the baseUrl.
|
|
15
15
|
*/
|
|
16
16
|
export function ApiProvider({ config, children }) {
|
|
17
|
-
//
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// 🛡️ STABILITY: Hash the config to detect REAL changes vs identity shifts
|
|
18
|
+
const configHash = useMemo(() => {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
baseUrl: config?.baseUrl,
|
|
22
|
+
version: config?.version,
|
|
23
|
+
debug: config?.debug,
|
|
24
|
+
// We can't stringify functions, so we use their existence/identity
|
|
25
|
+
hasOnError: !!config?.onError,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return Math.random();
|
|
30
|
+
}
|
|
31
|
+
}, [config?.baseUrl, config?.version, config?.debug, config?.onError]);
|
|
32
|
+
// Extract stable values based on the hash
|
|
33
|
+
const { baseUrl, version, debug, onError } = useMemo(() => ({
|
|
34
|
+
baseUrl: config?.baseUrl || "",
|
|
35
|
+
version: config?.version || "v1",
|
|
36
|
+
debug: !!config?.debug,
|
|
37
|
+
onError: config?.onError,
|
|
38
|
+
}), [configHash]);
|
|
22
39
|
/**
|
|
23
40
|
* 🛡️ HYPER-STABLE URL CONSTRUCTOR
|
|
24
41
|
* Memoized independently of the context value to prevent downstream loop invalidation.
|