@adventurelabs/scout-core 1.0.56 → 1.0.58

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.
@@ -11,6 +11,7 @@ export function useScoutDbListener(scoutSupabase) {
11
11
  const maxReconnectAttempts = 10;
12
12
  const baseDelay = 1000; // 1 second
13
13
  const maxDelay = 5000; // 5 seconds
14
+ const lastChannelIdRef = useRef(null);
14
15
  function handleTagInserts(payload) {
15
16
  console.log("[DB Listener] Tag INSERT received:", payload.new);
16
17
  dispatch(addTag(payload.new));
@@ -89,7 +90,12 @@ export function useScoutDbListener(scoutSupabase) {
89
90
  const setupChannel = () => {
90
91
  if (!scoutSupabase)
91
92
  return null;
92
- const mainChannel = scoutSupabase.channel("schema_db_changes");
93
+ const channelId = `scout_realtime_${Date.now()}_${Math.random()
94
+ .toString(36)
95
+ .substr(2, 9)}`;
96
+ const mainChannel = scoutSupabase.channel(channelId);
97
+ lastChannelIdRef.current = channelId;
98
+ console.log(`[DB Listener] Creating channel: ${channelId}`);
93
99
  // Subscribe to all events
94
100
  mainChannel
95
101
  .on("postgres_changes", { event: "INSERT", schema: "public", table: "plans" }, handlePlanInserts)
@@ -114,16 +120,23 @@ export function useScoutDbListener(scoutSupabase) {
114
120
  reconnectAttemptsRef.current = 0; // Reset reconnect attempts on successful connection
115
121
  }
116
122
  else if (status === "CHANNEL_ERROR") {
117
- console.error("[DB Listener] ❌ Channel error occurred. Reconnecting...");
123
+ console.warn("[DB Listener] ❌ Channel error occurred. Reconnecting...");
118
124
  handleReconnect();
119
125
  }
120
126
  else if (status === "TIMED_OUT") {
121
- console.error("[DB Listener] ⏰ Subscription timed out. Reconnecting...");
127
+ console.warn("[DB Listener] ⏰ Subscription timed out. Reconnecting...");
122
128
  handleReconnect();
123
129
  }
124
130
  else if (status === "CLOSED") {
125
- console.log("[DB Listener] 🔒 Channel closed. Reconnecting...");
126
- handleReconnect();
131
+ console.log(`[DB Listener] 🔒 Channel closed: ${lastChannelIdRef.current}`);
132
+ // Only reconnect if this isn't an immediate closure after subscription
133
+ if (reconnectAttemptsRef.current > 0) {
134
+ console.log("[DB Listener] Reconnecting...");
135
+ handleReconnect();
136
+ }
137
+ else {
138
+ console.log("[DB Listener] Channel closed immediately after subscription, not reconnecting");
139
+ }
127
140
  }
128
141
  });
129
142
  return mainChannel;
@@ -168,8 +181,9 @@ export function useScoutDbListener(scoutSupabase) {
168
181
  clearTimeout(reconnectTimeoutRef.current);
169
182
  reconnectTimeoutRef.current = null;
170
183
  }
171
- // Reset reconnect attempts
184
+ // Reset reconnect attempts and channel tracking
172
185
  reconnectAttemptsRef.current = 0;
186
+ lastChannelIdRef.current = null;
173
187
  // Clean up channels
174
188
  cleanupChannels();
175
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,8 +44,8 @@
44
44
  "typescript": "^5.0.0"
45
45
  },
46
46
  "dependencies": {
47
- "@supabase/supabase-js": "^2.45.6",
48
- "@supabase/ssr": "^0.5.1",
47
+ "@supabase/supabase-js": "^2.53.0",
48
+ "@supabase/ssr": "^0.6.1",
49
49
  "@reduxjs/toolkit": "^2.0.0",
50
50
  "zustand": "^4.0.0"
51
51
  }