@prismetic/next-preview-core 1.0.3 → 1.0.4

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/index.js CHANGED
@@ -46,6 +46,16 @@ function PreviewProviders({
46
46
  }
47
47
  })
48
48
  );
49
+ (0, import_react.useEffect)(() => {
50
+ if (!refetchOnWindowFocus) return;
51
+ const handleFocus = () => {
52
+ if (document.visibilityState === "visible") {
53
+ queryClient.invalidateQueries();
54
+ }
55
+ };
56
+ document.addEventListener("visibilitychange", handleFocus);
57
+ return () => document.removeEventListener("visibilitychange", handleFocus);
58
+ }, [queryClient, refetchOnWindowFocus]);
49
59
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children });
50
60
  }
51
61
 
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/PreviewProviders.tsx
4
4
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
- import { useState } from "react";
5
+ import { useState, useEffect } from "react";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  function PreviewProviders({
8
8
  children,
@@ -20,6 +20,16 @@ function PreviewProviders({
20
20
  }
21
21
  })
22
22
  );
23
+ useEffect(() => {
24
+ if (!refetchOnWindowFocus) return;
25
+ const handleFocus = () => {
26
+ if (document.visibilityState === "visible") {
27
+ queryClient.invalidateQueries();
28
+ }
29
+ };
30
+ document.addEventListener("visibilitychange", handleFocus);
31
+ return () => document.removeEventListener("visibilitychange", handleFocus);
32
+ }, [queryClient, refetchOnWindowFocus]);
23
33
  return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children });
24
34
  }
25
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismetic/next-preview-core",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Hybrid static/preview architecture for Next.js + Strapi projects",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -2,7 +2,7 @@
2
2
  "use client";
3
3
 
4
4
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
- import { useState } from "react";
5
+ import { useState, useEffect } from "react";
6
6
 
7
7
  /**
8
8
  * React Query provider for Preview Mode.
@@ -37,6 +37,19 @@ export function PreviewProviders({
37
37
  })
38
38
  );
39
39
 
40
+ useEffect(() => {
41
+ if (!refetchOnWindowFocus) return;
42
+
43
+ const handleFocus = () => {
44
+ if (document.visibilityState === "visible") {
45
+ queryClient.invalidateQueries();
46
+ }
47
+ };
48
+
49
+ document.addEventListener("visibilitychange", handleFocus);
50
+ return () => document.removeEventListener("visibilitychange", handleFocus);
51
+ }, [queryClient, refetchOnWindowFocus]);
52
+
40
53
  return (
41
54
  <QueryClientProvider client={queryClient}>
42
55
  {children}