Skip to content

Commit

Permalink
add delay by 1 microtick (#4005)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 16, 2023
1 parent 8fe5401 commit bcf365b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ options.event = e => {
*/
function afterEvent(eventType, target) {
if (target.value != null) {
target.value = target._prevValue;
Promise.resolve().then(() => (target.value = target._prevValue));
}
if (eventType === 'change' && target.checked != null) {
target.checked = target._prevValue;
Promise.resolve().then(() => (target.checked = target._prevValue));
}
}

Expand Down
4 changes: 3 additions & 1 deletion compat/test/browser/controlledInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('preact/compat controlled inputs', () => {
render(<Input />, scratch);

scratch.firstChild.value = 'A';
fireEvent(scratch.firstChild, 'change');
await fireEvent(scratch.firstChild, 'change');
expect(calls).to.deep.equal(['A']);
expect(scratch.firstChild.value).to.equal('A');

Expand Down Expand Up @@ -208,6 +208,8 @@ describe('preact/compat controlled inputs', () => {

scratch.firstChild.checked = false;
await fireEvent(scratch.firstChild, 'change');
// Have to wait for the microtick
await new Promise(res => setTimeout(res));
expect(calls).to.deep.equal([false]);
expect(scratch.firstChild.checked).to.equal(true);
});
Expand Down

0 comments on commit bcf365b

Please sign in to comment.