@readyfor/api-client-base 1.165.0-pr1549.d32c36a → 1.166.0
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.
|
@@ -6,11 +6,24 @@ let swr = require("swr");
|
|
|
6
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
7
|
// src/react/ApiClientConfigProvider.tsx
|
|
8
8
|
const ApiClientConfigContext = (0, react.createContext)(require_apiClientConfigStore.store);
|
|
9
|
+
const isConfigEqual = (prev, next) => {
|
|
10
|
+
const prevRecord = prev;
|
|
11
|
+
const nextRecord = next;
|
|
12
|
+
const prevKeys = Object.keys(prevRecord);
|
|
13
|
+
return prevKeys.length === Object.keys(nextRecord).length && prevKeys.every((key) => Object.hasOwn(nextRecord, key) && prevRecord[key] === nextRecord[key]);
|
|
14
|
+
};
|
|
15
|
+
const syncConfig = (config) => {
|
|
16
|
+
if (!isConfigEqual(require_apiClientConfigStore.store.getState(), config)) require_apiClientConfigStore.store.setState(() => config);
|
|
17
|
+
};
|
|
18
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
9
19
|
const ApiClientConfigProvider = (props) => {
|
|
10
20
|
const { swr: swr$1, ...config } = props.config;
|
|
11
|
-
(0, react.
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
const isMountedRef = (0, react.useRef)(false);
|
|
22
|
+
if (!isMountedRef.current) syncConfig(config);
|
|
23
|
+
useIsomorphicLayoutEffect(() => {
|
|
24
|
+
isMountedRef.current = true;
|
|
25
|
+
syncConfig(config);
|
|
26
|
+
});
|
|
14
27
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ApiClientConfigContext.Provider, {
|
|
15
28
|
value: require_apiClientConfigStore.store,
|
|
16
29
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(swr.SWRConfig, {
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as mergeRequestInit, r as store } from "../apiClientConfigStore-DbTqjD1_.mjs";
|
|
2
|
-
import { createContext, useContext, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { SWRConfig } from "swr";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
@@ -29,11 +29,24 @@ const createSwrConfig = (config) => ({
|
|
|
29
29
|
});
|
|
30
30
|
// src/react/ApiClientConfigProvider.tsx
|
|
31
31
|
const ApiClientConfigContext = createContext(store);
|
|
32
|
+
const isConfigEqual = (prev, next) => {
|
|
33
|
+
const prevRecord = prev;
|
|
34
|
+
const nextRecord = next;
|
|
35
|
+
const prevKeys = Object.keys(prevRecord);
|
|
36
|
+
return prevKeys.length === Object.keys(nextRecord).length && prevKeys.every((key) => Object.hasOwn(nextRecord, key) && prevRecord[key] === nextRecord[key]);
|
|
37
|
+
};
|
|
38
|
+
const syncConfig = (config) => {
|
|
39
|
+
if (!isConfigEqual(store.getState(), config)) store.setState(() => config);
|
|
40
|
+
};
|
|
41
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
32
42
|
const ApiClientConfigProvider = (props) => {
|
|
33
43
|
const { swr, ...config } = props.config;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
const isMountedRef = useRef(false);
|
|
45
|
+
if (!isMountedRef.current) syncConfig(config);
|
|
46
|
+
useIsomorphicLayoutEffect(() => {
|
|
47
|
+
isMountedRef.current = true;
|
|
48
|
+
syncConfig(config);
|
|
49
|
+
});
|
|
37
50
|
return /* @__PURE__ */ jsx(ApiClientConfigContext.Provider, {
|
|
38
51
|
value: store,
|
|
39
52
|
children: /* @__PURE__ */ jsx(SWRConfig, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readyfor/api-client-base",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.166.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,9 +30,11 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/qs": "6.15.1",
|
|
32
32
|
"@types/react": "19.3.0",
|
|
33
|
+
"@types/react-dom": "19.3.0",
|
|
33
34
|
"@types/use-sync-external-store": "1.7.0",
|
|
34
35
|
"qs": "^6.15.2",
|
|
35
36
|
"react": "19.3.1",
|
|
37
|
+
"react-dom": "19.3.1",
|
|
36
38
|
"swr": "2.5.1",
|
|
37
39
|
"use-sync-external-store": "1.7.0",
|
|
38
40
|
"zod": "^4.3.6"
|