react-notify-sdk 1.0.37 → 1.0.38

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.
@@ -25,9 +25,37 @@ export const FeatureMessageProvider = ({ projectKey,
25
25
  }) => {
26
26
  const [message, setMessage] = useState(null);
27
27
  const [visible, setVisible] = useState(false);
28
+ const [pathname, setPathname] = useState(() => typeof window !== 'undefined' ? window.location.pathname : '');
28
29
  const device = useDeviceDetection();
29
30
  // Create supabase client with project key header
30
31
  const supabaseClient = getSupabaseClient(projectKey);
32
+ // Effect to track pathname changes
33
+ useEffect(() => {
34
+ if (typeof window === 'undefined')
35
+ return;
36
+ const updatePathname = () => {
37
+ setPathname(window.location.pathname);
38
+ };
39
+ // Listen for browser back/forward navigation
40
+ window.addEventListener('popstate', updatePathname);
41
+ // Listen for programmatic navigation (pushState/replaceState)
42
+ const originalPushState = window.history.pushState;
43
+ const originalReplaceState = window.history.replaceState;
44
+ window.history.pushState = function (...args) {
45
+ originalPushState.apply(window.history, args);
46
+ updatePathname();
47
+ };
48
+ window.history.replaceState = function (...args) {
49
+ originalReplaceState.apply(window.history, args);
50
+ updatePathname();
51
+ };
52
+ return () => {
53
+ window.removeEventListener('popstate', updatePathname);
54
+ window.history.pushState = originalPushState;
55
+ window.history.replaceState = originalReplaceState;
56
+ };
57
+ }, []);
58
+ // Your main effect - now uses the reactive pathname state
31
59
  useEffect(() => {
32
60
  if (typeof window === 'undefined')
33
61
  return; // Skip on server
@@ -36,12 +64,12 @@ export const FeatureMessageProvider = ({ projectKey,
36
64
  .from('feature_messages')
37
65
  .select('*')
38
66
  .eq('project_key', projectKey)
39
- .eq('route', window.location.pathname)
67
+ .eq('route', pathname)
40
68
  .eq('is_active', true)
41
69
  .order('created_at', { ascending: false });
42
70
  //.limit(1)
43
71
  //.single();
44
- const match = data?.find((msg) => routeMatches(msg.route, window.location.pathname));
72
+ const match = data?.find((msg) => routeMatches(msg.route, pathname));
45
73
  if (match) {
46
74
  setMessage(match);
47
75
  setVisible(true); // Fade in
@@ -61,7 +89,7 @@ export const FeatureMessageProvider = ({ projectKey,
61
89
  table: 'feature_messages',
62
90
  }, (payload) => {
63
91
  const msg = payload.new;
64
- if (msg.project_key === projectKey && msg.is_active && routeMatches(msg.route, window.location.pathname)) {
92
+ if (msg.project_key === projectKey && msg.is_active && routeMatches(msg.route, pathname)) {
65
93
  setMessage(msg);
66
94
  setVisible(true);
67
95
  }
@@ -74,7 +102,7 @@ export const FeatureMessageProvider = ({ projectKey,
74
102
  return () => {
75
103
  supabaseClient.removeChannel(subscription);
76
104
  };
77
- }, [window.location.pathname, projectKey]);
105
+ }, [pathname, projectKey]);
78
106
  if (!message)
79
107
  return null;
80
108
  //const defaultClasses = `absolute ${message?.position}-6 left-1/2 transform -translate-x-1/2 z-20 w-full md:w-[${message?.width}%] px-3 py-1 bg-[${message?.backgroundColor}] border border-[${message?.borderColor}] text-[${message?.textColor}] rounded-lg shadow`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-notify-sdk",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "SDK for displaying real-time route-specific messages in React apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",