-
Notifications
You must be signed in to change notification settings - Fork 0
IBX-2803: Fix drag and drop after React update #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide a brief explanation? 🙂
Is the tmp const crucial?
| } | ||
|
|
||
| $movingScript = sprintf('dragMock.dragStart(%s).dragOver(%s).delay(100).drop(%s);', $from, $hover, $to); | ||
| $movingScript = sprintf('{ const dragMockTmp = dragMock.dragStart(%s).delay(50).dragOver(%s).delay(50); setTimeout(() => dragMockTmp.drop(%s), 100); }', $from, $hover, $to); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After updating React from v17 to v18 it seems that React started to do renders asynchronously (what was mentioned e.g. here), which means that after calling render function component is not rendered immediately but after some short period of time, hence some modifications have been applied here to make d&d work in Page Builder and Form Builder.
-
The first problem was that in PB placeholder is rendered with delay so we need to delay evaluation of
$tostatement (equal to:document.querySelector('#page-builder-preview').contentDocument.querySelector('.droppable-placeholder')).delayfunction does not delaydropcall and evaluation of$to. Because of this we needsetTimeoutto both calldropand let browser engine evaluate$towith a delay. We needdragMockTmpto pass dragMock reference tosetTimeout. Block statement was added so thatdragMockTmpwon't pollute the global namespace. -
In Form Builder, when drag is started the state is being updated (
handleDragStartSidebarField) and we need to give React time to apply this state change thusdelay(50)was added beforedragOverso that whenhandleZoneDragOveris being called the state of the component is already updated. -
Finally,
delay(50)was added afterdragOver, because otherwisedropwould not be fired by dragMock (probably there is a bug in the library).
JIRA: https://issues.ibexa.co/browse/IBX-2803