@readyfor/api-client-base 1.56.0-pr1409.d6b038b → 1.56.0-pr1409.ed0166a

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.
@@ -9,12 +9,15 @@ const ApiClientConfigContext = (0, react.createContext)(require_apiClientConfigS
9
9
  /**
10
10
  * `config` オブジェクトのキー集合と各値を浅く比較する。
11
11
  * 関数プロパティは参照比較になる。
12
+ *
13
+ * キー集合の厳密一致を担保するため、長さチェックに加えて
14
+ * b 側に各キーが存在することも確認する。
12
15
  */
13
16
  const shallowEqual = (a, b) => {
14
17
  const aKeys = Object.keys(a);
15
18
  const bKeys = Object.keys(b);
16
19
  if (aKeys.length !== bKeys.length) return false;
17
- return aKeys.every((k) => a[k] === b[k]);
20
+ return aKeys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && a[k] === b[k]);
18
21
  };
19
22
  /**
20
23
  * API クライアントの設定を子ツリーへ提供するプロバイダ。
@@ -29,12 +32,16 @@ const shallowEqual = (a, b) => {
29
32
  const ApiClientConfigProvider = (props) => {
30
33
  const { swr: swr$1, ...config } = props.config;
31
34
  const prevConfigRef = (0, react.useRef)(null);
32
- if (typeof window !== "undefined") {
35
+ if (prevConfigRef.current === null && typeof window !== "undefined") {
36
+ require_apiClientConfigStore.store.setState(() => config);
37
+ prevConfigRef.current = config;
38
+ }
39
+ (0, react.useEffect)(() => {
33
40
  if (prevConfigRef.current === null || !shallowEqual(prevConfigRef.current, config)) {
34
41
  require_apiClientConfigStore.store.setState(() => config);
35
42
  prevConfigRef.current = config;
36
43
  }
37
- }
44
+ });
38
45
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ApiClientConfigContext.Provider, {
39
46
  value: require_apiClientConfigStore.store,
40
47
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(swr.SWRConfig, {
@@ -1,5 +1,5 @@
1
1
  import { i as mergeRequestInit, r as store } from "../apiClientConfigStore-DDleIkQN.mjs";
2
- import { createContext, useContext, useMemo, useRef } from "react";
2
+ import { createContext, useContext, useEffect, 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";
@@ -33,12 +33,15 @@ const ApiClientConfigContext = createContext(store);
33
33
  /**
34
34
  * `config` オブジェクトのキー集合と各値を浅く比較する。
35
35
  * 関数プロパティは参照比較になる。
36
+ *
37
+ * キー集合の厳密一致を担保するため、長さチェックに加えて
38
+ * b 側に各キーが存在することも確認する。
36
39
  */
37
40
  const shallowEqual = (a, b) => {
38
41
  const aKeys = Object.keys(a);
39
42
  const bKeys = Object.keys(b);
40
43
  if (aKeys.length !== bKeys.length) return false;
41
- return aKeys.every((k) => a[k] === b[k]);
44
+ return aKeys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && a[k] === b[k]);
42
45
  };
43
46
  /**
44
47
  * API クライアントの設定を子ツリーへ提供するプロバイダ。
@@ -53,12 +56,16 @@ const shallowEqual = (a, b) => {
53
56
  const ApiClientConfigProvider = (props) => {
54
57
  const { swr, ...config } = props.config;
55
58
  const prevConfigRef = useRef(null);
56
- if (typeof window !== "undefined") {
59
+ if (prevConfigRef.current === null && typeof window !== "undefined") {
60
+ store.setState(() => config);
61
+ prevConfigRef.current = config;
62
+ }
63
+ useEffect(() => {
57
64
  if (prevConfigRef.current === null || !shallowEqual(prevConfigRef.current, config)) {
58
65
  store.setState(() => config);
59
66
  prevConfigRef.current = config;
60
67
  }
61
- }
68
+ });
62
69
  return /* @__PURE__ */ jsx(ApiClientConfigContext.Provider, {
63
70
  value: store,
64
71
  children: /* @__PURE__ */ jsx(SWRConfig, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readyfor/api-client-base",
3
- "version": "1.56.0-pr1409.d6b038b",
3
+ "version": "1.56.0-pr1409.ed0166a",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",