trotl-table 1.0.52 → 1.0.53
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/Table.cjs.js +18 -3
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +18 -3
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/Table.cjs.js
CHANGED
|
@@ -9739,8 +9739,15 @@ function TableInner({
|
|
|
9739
9739
|
const [localData, setLocalData] = React.useState(data);
|
|
9740
9740
|
React.useEffect(() => setLocalData(data), [data]);
|
|
9741
9741
|
|
|
9742
|
-
//
|
|
9742
|
+
// Track the last applied initialSelectedRows to detect changes and prevent loops
|
|
9743
|
+
const lastSyncedRef = React.useRef(null);
|
|
9744
|
+
|
|
9745
|
+
// Sync only when initialSelectedRows prop itself changes (from parent), not on every data update
|
|
9743
9746
|
React.useEffect(() => {
|
|
9747
|
+
// Skip if this is the same as the last time we synced (prevents feedback loops)
|
|
9748
|
+
const isSame = lastSyncedRef.current && lastSyncedRef.current.length === resolvedInitialSelectedRows.length && lastSyncedRef.current.every(id => resolvedInitialSelectedRows.includes(id));
|
|
9749
|
+
if (isSame) return;
|
|
9750
|
+
|
|
9744
9751
|
// Validate: only apply IDs that exist in current data
|
|
9745
9752
|
const allRowIds = new Set();
|
|
9746
9753
|
const collectRowIds = rowsData => {
|
|
@@ -9757,8 +9764,16 @@ function TableInner({
|
|
|
9757
9764
|
|
|
9758
9765
|
// Filter to only valid IDs (handles async data loads + parent updates)
|
|
9759
9766
|
const validIds = resolvedInitialSelectedRows.filter(id => allRowIds.has(id) || allRowIds.size === 0);
|
|
9760
|
-
|
|
9761
|
-
|
|
9767
|
+
|
|
9768
|
+
// Only update if different from current
|
|
9769
|
+
setSelectedRows(prev => {
|
|
9770
|
+
if (prev.length === validIds.length && prev.every(id => validIds.includes(id))) {
|
|
9771
|
+
return prev; // No change, prevent re-render
|
|
9772
|
+
}
|
|
9773
|
+
return validIds;
|
|
9774
|
+
});
|
|
9775
|
+
lastSyncedRef.current = resolvedInitialSelectedRows;
|
|
9776
|
+
}, [resolvedInitialSelectedRows]);
|
|
9762
9777
|
|
|
9763
9778
|
// Option to read search param from URL
|
|
9764
9779
|
const [searchTerm, setSearchTerm] = React.useState(extraSearchTerm);
|