Skip to content

Commit

Permalink
feat: workaround isEdited race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac authored and smbea committed Sep 25, 2023
1 parent 52bd8dd commit 9f8373c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/components/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,29 @@ export default function Group(props) {

// set edited state depending on all entries
useEffect(() => {
const hasOneEditedEntry = entries.find(entry => {
const {
id,
isEdited
} = entry;
const scheduled = requestAnimationFrame(() => {
const hasOneEditedEntry = entries.find(entry => {
const {
id,
isEdited
} = entry;

const entryNode = domQuery(`[data-entry-id="${id}"]`);
const entryNode = domQuery(`[data-entry-id="${id}"]`);

if (!isFunction(isEdited) || !entryNode) {
return false;
}
if (!isFunction(isEdited) || !entryNode) {
return false;
}

const inputNode = domQuery('.bio-properties-panel-input', entryNode);

const inputNode = domQuery('.bio-properties-panel-input', entryNode);
return isEdited(inputNode);
});

return isEdited(inputNode);
setEdited(hasOneEditedEntry);
});

setEdited(hasOneEditedEntry);
}, [ entries ]);
return () => cancelAnimationFrame(scheduled);
}, [ entries, setEdited ]);

// set error state depending on all entries
const allErrors = useErrors();
Expand Down
5 changes: 5 additions & 0 deletions test/spec/components/Group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe('<Group>', function() {
container = TestContainer.get(this);
});

beforeEach(() => {
const requestAnimationFrameSpy = sinon.fake.returns(cb => cb());
global.window.requestAnimationFrame = requestAnimationFrameSpy();
});


it('should render', function() {

Expand Down

0 comments on commit 9f8373c

Please sign in to comment.