mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
fix: optimize component sorting logic to ensure recalculation on changes. Fixes the bug on showing the component from one subcontainer to another
This commit is contained in:
parent
68fa104582
commit
d931b7ecc6
1 changed files with 12 additions and 4 deletions
|
|
@ -22,10 +22,10 @@ const useSortedComponents = (components, currentLayout, id, moduleId) => {
|
|||
const sortedComponents = useMemo(() => {
|
||||
const { triggerUpdate, shouldReorder } = reorderContainerChildren;
|
||||
|
||||
// If this container is not the target of the reorder, return cached order
|
||||
if (!shouldReorder) {
|
||||
return prevComponentsOrder.current;
|
||||
}
|
||||
// Always recalculate if components array has changed (new component added/removed)
|
||||
const componentsChanged =
|
||||
prevComponentsOrder.current.length !== components.length ||
|
||||
!components.every((comp) => prevComponentsOrder.current.includes(comp));
|
||||
|
||||
// If a forced update occurred for this container, recalculate order
|
||||
const isForcedUpdate = prevForceUpdateRef.current !== triggerUpdate;
|
||||
|
|
@ -33,6 +33,14 @@ const useSortedComponents = (components, currentLayout, id, moduleId) => {
|
|||
prevForceUpdateRef.current = triggerUpdate;
|
||||
}
|
||||
|
||||
// Skip recalculation only if:
|
||||
// 1. This container is not the target of reorder
|
||||
// 2. Components haven't changed
|
||||
// 3. No forced update occurred
|
||||
if (!shouldReorder && !componentsChanged && !isForcedUpdate) {
|
||||
return prevComponentsOrder.current;
|
||||
}
|
||||
|
||||
const currentPageComponents = getCurrentPageComponents();
|
||||
|
||||
const newComponentsOrder = [...components].sort((a, b) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue