@adventurelabs/scout-core 1.0.111 → 1.0.112
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.
|
@@ -91,6 +91,16 @@ export function useScoutRefresh(options = {}) {
|
|
|
91
91
|
}
|
|
92
92
|
return true;
|
|
93
93
|
}, []);
|
|
94
|
+
// Helper function to sort herd modules consistently by ID
|
|
95
|
+
const sortHerdModulesById = useCallback((herdModules) => {
|
|
96
|
+
if (!Array.isArray(herdModules))
|
|
97
|
+
return herdModules;
|
|
98
|
+
return [...herdModules].sort((a, b) => {
|
|
99
|
+
const aId = a?.herd?.id || 0;
|
|
100
|
+
const bId = b?.herd?.id || 0;
|
|
101
|
+
return aId - bId;
|
|
102
|
+
});
|
|
103
|
+
}, []);
|
|
94
104
|
// Helper function to find differences between herd modules for debugging
|
|
95
105
|
const findHerdModulesDifferences = useCallback((newData, currentData) => {
|
|
96
106
|
if (!Array.isArray(newData) || !Array.isArray(currentData)) {
|
|
@@ -99,14 +109,26 @@ export function useScoutRefresh(options = {}) {
|
|
|
99
109
|
if (newData.length !== currentData.length) {
|
|
100
110
|
return `Array length mismatch: new=${newData.length}, current=${currentData.length}`;
|
|
101
111
|
}
|
|
112
|
+
// Sort both arrays by herd ID for consistent comparison
|
|
113
|
+
const sortedNew = sortHerdModulesById(newData);
|
|
114
|
+
const sortedCurrent = sortHerdModulesById(currentData);
|
|
102
115
|
const differences = [];
|
|
103
|
-
for (let i = 0; i <
|
|
104
|
-
const newHerd =
|
|
105
|
-
const currentHerd =
|
|
116
|
+
for (let i = 0; i < sortedNew.length; i++) {
|
|
117
|
+
const newHerd = sortedNew[i];
|
|
118
|
+
const currentHerd = sortedCurrent[i];
|
|
106
119
|
if (!newHerd || !currentHerd) {
|
|
107
120
|
differences.push(`Herd ${i}: null/undefined mismatch`);
|
|
108
121
|
continue;
|
|
109
122
|
}
|
|
123
|
+
// Get herd identifiers for better debugging
|
|
124
|
+
const newHerdId = newHerd.herd?.id || "unknown";
|
|
125
|
+
const currentHerdId = currentHerd.herd?.id || "unknown";
|
|
126
|
+
const newHerdName = newHerd.herd?.name || "unknown";
|
|
127
|
+
const currentHerdName = currentHerd.herd?.name || "unknown";
|
|
128
|
+
// Check if herd IDs match (data shuffling detection)
|
|
129
|
+
if (newHerdId !== currentHerdId) {
|
|
130
|
+
differences.push(`Herd ${i}: ID mismatch - expected ${currentHerdId}(${currentHerdName}) got ${newHerdId}(${newHerdName})`);
|
|
131
|
+
}
|
|
110
132
|
// Check top-level fields
|
|
111
133
|
const fieldsToCheck = [
|
|
112
134
|
"timestamp_last_refreshed",
|
|
@@ -116,7 +138,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
116
138
|
];
|
|
117
139
|
fieldsToCheck.forEach((field) => {
|
|
118
140
|
if (newHerd[field] !== currentHerd[field]) {
|
|
119
|
-
differences.push(`Herd ${i}.${field}: ${currentHerd[field]} → ${newHerd[field]}`);
|
|
141
|
+
differences.push(`Herd ${i}(${newHerdName}).${field}: ${currentHerd[field]} → ${newHerd[field]}`);
|
|
120
142
|
}
|
|
121
143
|
});
|
|
122
144
|
// Check array lengths for nested data
|
|
@@ -134,7 +156,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
134
156
|
const currentArray = currentHerd[field];
|
|
135
157
|
if (Array.isArray(newArray) && Array.isArray(currentArray)) {
|
|
136
158
|
if (newArray.length !== currentArray.length) {
|
|
137
|
-
differences.push(`Herd ${i}.${field}[]: length ${currentArray.length} → ${newArray.length}`);
|
|
159
|
+
differences.push(`Herd ${i}(${newHerdName}).${field}[]: length ${currentArray.length} → ${newArray.length}`);
|
|
138
160
|
}
|
|
139
161
|
}
|
|
140
162
|
});
|
|
@@ -145,21 +167,28 @@ export function useScoutRefresh(options = {}) {
|
|
|
145
167
|
}, []);
|
|
146
168
|
// Helper function to conditionally dispatch only if data has changed
|
|
147
169
|
const conditionalDispatch = useCallback((newData, currentData, actionCreator, dataType, enableDebugging = false) => {
|
|
148
|
-
|
|
170
|
+
// For herd modules, sort both datasets by ID before comparison
|
|
171
|
+
let dataToCompare = newData;
|
|
172
|
+
let currentToCompare = currentData;
|
|
173
|
+
if (dataType.includes("Herd modules")) {
|
|
174
|
+
dataToCompare = sortHerdModulesById(newData);
|
|
175
|
+
currentToCompare = sortHerdModulesById(currentData);
|
|
176
|
+
}
|
|
177
|
+
if (!deepEqual(dataToCompare, currentToCompare)) {
|
|
149
178
|
console.log(`[useScoutRefresh] ${dataType} data changed, updating store`);
|
|
150
179
|
// Add debugging for herd modules to see what actually changed
|
|
151
180
|
if (enableDebugging && dataType.includes("Herd modules")) {
|
|
152
181
|
const differences = findHerdModulesDifferences(newData, currentData);
|
|
153
182
|
console.log(`[useScoutRefresh] ${dataType} differences: ${differences}`);
|
|
154
183
|
}
|
|
155
|
-
dispatch(actionCreator(newData));
|
|
184
|
+
dispatch(actionCreator(newData)); // Always dispatch original unsorted data
|
|
156
185
|
return true;
|
|
157
186
|
}
|
|
158
187
|
else {
|
|
159
188
|
console.log(`[useScoutRefresh] ${dataType} data unchanged, skipping store update`);
|
|
160
189
|
return false;
|
|
161
190
|
}
|
|
162
|
-
}, [dispatch, deepEqual, findHerdModulesDifferences]);
|
|
191
|
+
}, [dispatch, deepEqual, findHerdModulesDifferences, sortHerdModulesById]);
|
|
163
192
|
// Helper function to handle IndexedDB errors - memoized for stability
|
|
164
193
|
const handleIndexedDbError = useCallback(async (error, operation, retryFn) => {
|
|
165
194
|
if (error instanceof Error &&
|