-
Notifications
You must be signed in to change notification settings - Fork 0
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
IBX-2803: Fix drag and drop after React update #18
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?
@@ -31,7 +31,7 @@ public function dragAndDrop(string $from, string $hover, string $to): void | |||
throw new RuntimeException('drag-mock library has to be added to the page in order to use this method. Refer to README in BehatBundle for more information.'); | |||
} | |||
|
|||
$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
$to
statement (equal to:document.querySelector('#page-builder-preview').contentDocument.querySelector('.droppable-placeholder')
).delay
function does not delaydrop
call and evaluation of$to
. Because of this we needsetTimeout
to both calldrop
and let browser engine evaluate$to
with a delay. We needdragMockTmp
to pass dragMock reference tosetTimeout
. Block statement was added so thatdragMockTmp
won'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 beforedragOver
so that whenhandleZoneDragOver
is being called the state of the component is already updated. -
Finally,
delay(50)
was added afterdragOver
, because otherwisedrop
would not be fired by dragMock (probably there is a bug in the library).
JIRA: https://issues.ibexa.co/browse/IBX-2803