@indietabletop/appkit 4.0.0 → 4.0.3

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.
@@ -51,6 +51,7 @@ export function CurrentUserFetcher(props: CurrentUserFetcherProps) {
51
51
  const { result, reload } = useCurrentUserResult({
52
52
  // We only want to fetch the current user if they exist in local storage
53
53
  performFetch: !!localUser,
54
+ revalidateOnFocus: true,
54
55
  });
55
56
 
56
57
  if (result.isFailure && result.failure.type === "API_ERROR") {
@@ -10,8 +10,18 @@ export function useCurrentUserResult(options?: {
10
10
  * @default true
11
11
  */
12
12
  performFetch?: boolean;
13
+
14
+ /**
15
+ * Fetch new data every time the window is focused.
16
+ *
17
+ * Note that `performFetch` has to be enabled for this option to have an
18
+ * effect — we are not revalidating when there is no fetch to do!
19
+ *
20
+ * @default false
21
+ */
22
+ revalidateOnFocus?: boolean;
13
23
  }) {
14
- const { performFetch = true } = options ?? {};
24
+ const { performFetch = true, revalidateOnFocus = false } = options ?? {};
15
25
  const client = useClient();
16
26
  const [latestAttemptTs, setLatestAttemptTs] = useState(Date.now());
17
27
 
@@ -31,12 +41,14 @@ export function useCurrentUserResult(options?: {
31
41
  // Invoke the fetch action
32
42
  fetchUserAndStoreResult();
33
43
 
34
- // Set up listeners for data revalidation
35
- window.addEventListener("focus", fetchUserAndStoreResult);
44
+ if (revalidateOnFocus) {
45
+ const controller = new AbortController();
46
+ window.addEventListener("focus", fetchUserAndStoreResult, controller);
36
47
 
37
- return () => {
38
- window.removeEventListener("focus", fetchUserAndStoreResult);
39
- };
48
+ return () => {
49
+ controller.abort();
50
+ };
51
+ }
40
52
  }
41
53
  }, [client, latestAttemptTs, performFetch]);
42
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indietabletop/appkit",
3
- "version": "4.0.0",
3
+ "version": "4.0.3",
4
4
  "description": "A collection of modules used in apps built by Indie Tabletop Club",
5
5
  "private": false,
6
6
  "type": "module",
@@ -19,7 +19,10 @@
19
19
  "/lib"
20
20
  ],
21
21
  "author": "Artur Müller",
22
- "repository": "github:indietabletop/appkit",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/indietabletop/appkit.git"
25
+ },
23
26
  "license": "MIT",
24
27
  "peerDependencies": {
25
28
  "react": "^18.0.0 || ^19.0.0"