Skip to content

Conversation

@tischsoic
Copy link
Contributor

@tomaszszopinski tomaszszopinski requested a review from micszo May 17, 2022 13:25
Copy link
Contributor

@micszo micszo left a 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);
Copy link
Contributor Author

@tischsoic tischsoic May 17, 2022

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.

  1. 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 delay drop call and evaluation of $to. Because of this we need setTimeout to both call drop and let browser engine evaluate $to with a delay. We need dragMockTmp to pass dragMock reference to setTimeout. Block statement was added so that dragMockTmp won't pollute the global namespace.

  2. 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 thus delay(50) was added before dragOver so that when handleZoneDragOver is being called the state of the component is already updated.

  3. Finally, delay(50) was added after dragOver, because otherwise drop would not be fired by dragMock (probably there is a bug in the library).

@dew326 dew326 merged commit 09a0bfc into main May 19, 2022
@dew326 dew326 deleted the IBX-2803-update-react branch May 19, 2022 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants