Added fix for Infinite loop when changing value of new navigation item's field value
fixed: https://linear.app/tryghost/issue/ENG-1351/🐛-infinite-loop-when-changing-value-of-new-navigation-items-field
This commit is contained in:
parent
3e4b8d825d
commit
3c19d952b1
@ -1,5 +1,6 @@
|
||||
import {arrayMove} from '@dnd-kit/sortable';
|
||||
import {useEffect, useState} from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
export type SortableIndexedList<Item> = {
|
||||
items: Array<{ item: Item; id: string }>;
|
||||
@ -32,7 +33,7 @@ const useSortableIndexedList = <Item extends unknown>({items, setItems, blank, c
|
||||
allItems.push(newItem);
|
||||
}
|
||||
|
||||
if (JSON.stringify(allItems) !== JSON.stringify(items)) {
|
||||
if (!_.isEqual(JSON.parse(JSON.stringify(allItems)), JSON.parse(JSON.stringify(items)))) {
|
||||
setItems(allItems);
|
||||
}
|
||||
}, [editableItems, newItem, items, setItems, canAddNewItem]);
|
||||
|
@ -31,7 +31,7 @@ const useNavigationEditor = ({items, setItems}: {
|
||||
const list = useSortableIndexedList<Omit<EditableItem, 'id'>>({
|
||||
items: items.map(item => ({...item, errors: {}})),
|
||||
setItems: newItems => setItems(newItems.map(({url, label}) => ({url, label}))),
|
||||
blank: {label: '', url: '/', errors: {}},
|
||||
blank: {url: '/',label: '', errors: {}},
|
||||
canAddNewItem: hasNewItem
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user