Skip to content
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

Uncaught Invariant Violation: Cannot call hover while not dragging. error in Chrome 77.0 when using iframes #1534

Closed
nemesv opened this issue Sep 13, 2019 · 27 comments

Comments

@nemesv
Copy link

nemesv commented Sep 13, 2019

Update 2019-10-14

The bug was in Chrome and fixed in Chrome version: 77.0.3865.120

We are using react-dnd in an web application which is hosted inside another webapplication using a cross-origin iframe.

We have noticed that since the last Chrome upgrade all the drag-drop functionality stopped working. Our app is working fine in older Chrome versions and in other browsers.

We are not sure whether this is hitting an edge case in this library or the issue is with in Chrome 77.0

Reproduction

Go to http://react-dnd.github.io/react-dnd/examples/dustbin/single-target (or to any of the examples)

Steps to reproduce the behavior:

The "inline" example is working fine:
chrome-working

However running the same code in the JavaScript/TypeScript tabs, so in a cross-origin iframe (e.g. in the embedded codesandbox) the drop event is not fired:

chrome-not-working

Running the example is also not working in the CodeSandBox editor which also uses an inframe.

chrome-not-working-codesandbox

In both cases there is this error in the console:

browser.js:38 Uncaught Invariant Violation: Cannot call hover while not dragging.
    at invariant (https://hmq56.csb.app/node_modules/invariant/browser.js:38:15)
    at checkInvariants (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:45:29)
    at DragDropManagerImpl.hover (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:25:5)
    at Object.eval [as hover] (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/DragDropManagerImpl.js:132:38)
    at HTML5Backend.handleTopDrop (https://hmq56.csb.app/node_modules/react-dnd-html5-backend/dist/esm/HTML5Backend.js:418:21)

Expected behavior
No exceptions in the console, drop event is fired

Desktop (please complete the following information):

  • OS: Windows 10 (1903)
  • Browser Chrome
  • Version 77.0.3865.75 (Official Build) (64-bit)

Additional context
We did some investigation and we've observed that Chrome fires the dragEnd event prematurely in the case of the iframe which breaks the invariant checks.

@ssnolann
Copy link

Seeing the same issues in our app, we also have our DND code within an iframe and its completely broken for users with the newest chrome update.

Errors:
Screen Shot 2019-09-13 at 3 42 54 PM

@timmfin
Copy link

timmfin commented Sep 13, 2019

This is also affecting some of the drag and drop functionality in the various editor apps at HubSpot (that use react-dnd inside an iframe). Still digging into the extent of the problem.

And I have replicated the problem demonstrated by the codesandbox example in Chrome 77.0.3865.75 on Windows 10.

@timmfin
Copy link

timmfin commented Sep 13, 2019

I haven't had a chance to compare it with the latest HTML5 backend on react-dnd master, but we have deployed a temporary, hacky fix to our custom HTML5 backend:

image

Anecdotally, that setTimeout delay of the handleTopDragEndCapture event works 95%+ of the time. Because we have seen an occasional failure where the Invariant Violation error still happens, likely because the delay wasn't long enough. However, this at least has improved the situation for us, and we can look at a more robust hack if/when needed.

@adeelraza
Copy link

+1

@TheConfuZzledDude
Copy link

I get this same error in Vivaldi 2.8.1664.30 (Official Build) snapshot (64-bit) on every component, not just those in an iframe, whereas Chrome seems to work perfectly. I tried making the change that @timmfin suggested but it did nothing for me

@jkells
Copy link

jkells commented Sep 23, 2019

This error is pretty devastating for us. We have multiple apps that effectively broke completely as users updated Chrome.

@timmfin 's workaround is working for us, thanks!

@jkells
Copy link

jkells commented Sep 23, 2019

I've been playing around with this for a few hours tonight on the master branch. It's not throwing an exception anymore but I cannot drop any items. The setTimeout workaround seems to fix it.

It looks to me like we get a handleTopDragEndCapture followed by a handleDrop then a handleTopDrop

If we call endDrag() within handleTopDragEndCapture the drop events don't fire at all in an IFRAME. How odd.

@jkells
Copy link

jkells commented Sep 23, 2019

Interestingly when not in an IFRAME I only see the dragend events when a drag is cancelled not right before a successful drop. That seems to be the difference.

@jkells
Copy link

jkells commented Sep 23, 2019

Here we go, I think this is the issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1005747

@DonMcNamara
Copy link

Has anyone back ported the workaround to older versions of this library? Like 2.6.0 😅

@TheConfuZzledDude
Copy link

As a workaround, just for desktop use, I've been using https://github.com/zyzo/react-dnd-mouse-backend as an alternative to the HTML5 backend. It seems to work fine for me

@DonMcNamara
Copy link

Just FYI, I'm seeing this on Linux now as well.

@Cristy94
Copy link

As a workaround, just for desktop use, I've been using https://github.com/zyzo/react-dnd-mouse-backend as an alternative to the HTML5 backend. It seems to work fine for me

I also tried this fix, but the mouse backend is really buggy in FireFox.

@TheConfuZzledDude
Copy link

@Cristy94 It seems that he deleted the comment, but https://www.npmjs.com/package/@vvitto/html5-backend-chrome-dnd-fix was posted before. I haven't tested it, but it might work?

@vvitto
Copy link

vvitto commented Sep 30, 2019

@TheConfuZzledDude @Cristy94 it works for me, but you should check the version of your backend. It works fine on 2.5.4

@Cristy94
Copy link

@TheConfuZzledDude @Cristy94 it works for me, but you should check the version of your backend. It works fine on 2.5.4

What works? Mouse backend doesn't have version 2.5.4 https://github.com/zyzo/react-dnd-mouse-backend/releases and the html5 backend doesn't work on Windows 10 - Chrome 77 as mentioned in the original post.

@acroyear
Copy link

acroyear commented Oct 3, 2019

Has anyone back ported the workaround to older versions of this library? Like 2.6.0 😅

yes, we did some adaptation of the workaround to html5-backend 2.2.7 and it worked well enough to put into production.

@acroyear
Copy link

acroyear commented Oct 3, 2019

Just FYI, I'm seeing this on Linux now as well.

Chromium's bug acknowledged that Linux has the same, and it will be fixed with the Windows version. Latest state is M78 has it in the beta coming out in a few days, M79 and Canary have it already. They're still discussing patching M77.

@purpletastes
Copy link

我还没有机会将它与react-dnd master上的最新HTML5后端进行比较,但是我们已经对自定义HTML5后端部署了一个临时的,hacky的修复程序:

图片

有趣的是,事件的setTimeout延迟在handleTopDragEndCapture95%以上的时间内有效。因为我们看到偶尔的故障Invariant Violation仍然会发生错误,可能是因为延迟时间不够长。但是,这至少为我们改善了情况,如果需要的话,我们可以考虑采用更强大的技术。

这个问题现在仍然存在,我怎么样使用才能够解决呢,急急急!

@purpletastes
Copy link

我们在一个Web应用程序中使用react-dnd,该Web应用程序使用跨源iframe托管在另一个Web应用程序中。

我们已经注意到,自从上次Chrome升级以来,所有拖放功能均停止工作。我们的应用程序在较旧的Chrome版本和其他浏览器中均可正常运行。

我们不确定这是否在该库中处于领先地位,还是在Chrome 77.0中出现问题

再生产

转到http://react-dnd.github.io/react-dnd/examples/dustbin/single-target(或任何示例)

重现行为的步骤:

“内联”示例运行良好:
镀铬

但是,在JavaScript / TypeScript标签中运行相同的代码,因此在跨域iframe中(例如,在嵌入式codeandbox中),不会触发drop事件:

铬不工作

运行示例也无法在CodeSandBox编辑器中使用,后者也使用内置框架。

chrome-not-working-codesandbox

在这两种情况下,控制台中都会出现此错误:

browser.js:38 Uncaught Invariant Violation: Cannot call hover while not dragging.
    at invariant (https://hmq56.csb.app/node_modules/invariant/browser.js:38:15)
    at checkInvariants (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:45:29)
    at DragDropManagerImpl.hover (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:25:5)
    at Object.eval [as hover] (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/DragDropManagerImpl.js:132:38)
    at HTML5Backend.handleTopDrop (https://hmq56.csb.app/node_modules/react-dnd-html5-backend/dist/esm/HTML5Backend.js:418:21)

预期行为
控制台中无异常,引发了drop事件

桌面(请完成以下信息):

  • 作业系统:Windows 10(1903)
  • 浏览器Chrome
  • 版本77.0.3865.75(官方内部版本)(64位)

附加上下文
我们进行了一些调查,我们发现在iframe打破不变检查的情况下,Chrome会过早触发dragEnd事件。

我也希望能够尽快解决这个问题,chrome版本77出现这个问题

@purpletastes
Copy link

这也影响到HubSpot的各种编辑器应用程序(在iframe中使用react-dnd)的某些拖放功能。仍在深入研究问题的程度。

我已经复制了Windows 10的Chrome 77.0.3865.75中的codeandbox示例所演示的问题。

怎么解决的,麻烦回复一下,谢谢

@purpletastes
Copy link

This is also affecting some of the drag and drop functionality in the various editor apps at HubSpot (that use react-dnd inside an iframe). Still digging into the extent of the problem.

And I have replicated the problem demonstrated by the codesandbox example in Chrome 77.0.3865.75 on Windows

We are using react-dnd in an web application which is hosted inside another webapplication using a cross-origin iframe.

We have noticed that since the last Chrome upgrade all the drag-drop functionality stopped working. Our app is working fine in older Chrome versions and in other browsers.

We are not sure whether this is hitting an edge case in this library or the issue is with in Chrome 77.0

Reproduction

Go to http://react-dnd.github.io/react-dnd/examples/dustbin/single-target (or to any of the examples)

Steps to reproduce the behavior:

The "inline" example is working fine:
chrome-working

However running the same code in the JavaScript/TypeScript tabs, so in a cross-origin iframe (e.g. in the embedded codesandbox) the drop event is not fired:

chrome-not-working

Running the example is also not working in the CodeSandBox editor which also uses an inframe.

chrome-not-working-codesandbox

In both cases there is this error in the console:

browser.js:38 Uncaught Invariant Violation: Cannot call hover while not dragging.
    at invariant (https://hmq56.csb.app/node_modules/invariant/browser.js:38:15)
    at checkInvariants (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:45:29)
    at DragDropManagerImpl.hover (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:25:5)
    at Object.eval [as hover] (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/DragDropManagerImpl.js:132:38)
    at HTML5Backend.handleTopDrop (https://hmq56.csb.app/node_modules/react-dnd-html5-backend/dist/esm/HTML5Backend.js:418:21)

Expected behavior
No exceptions in the console, drop event is fired

Desktop (please complete the following information):

  • OS: Windows 10 (1903)
  • Browser Chrome
  • Version 77.0.3865.75 (Official Build) (64-bit)

Additional context
We did some investigation and we've observed that Chrome fires the dragEnd event prematurely in the case of the iframe which breaks the invariant checks.

请问这个问题解决了吗?

@acroyear
Copy link

acroyear commented Oct 9, 2019

The original Chrome bug fix has been merged to the upcoming M77 patch release. I can not say when it will actually come out, just that I've been following the chromium bug page on this closely.

@nemesv
Copy link
Author

nemesv commented Oct 14, 2019

The bug was in Chrome and fixed in Chrome version: 77.0.3865.120

@nemesv nemesv closed this as completed Oct 14, 2019
@Kadrian
Copy link

Kadrian commented Oct 25, 2019

Chrome 78 is out! I can confirm that the problem disappears in Chrome 78 :-)

@liweinan0423
Copy link

This is also affecting some of the drag and drop functionality in the various editor apps at HubSpot (that use react-dnd inside an iframe). Still digging into the extent of the problem.
And I have replicated the problem demonstrated by the codesandbox example in Chrome 77.0.3865.75 on Windows

We are using react-dnd in an web application which is hosted inside another webapplication using a cross-origin iframe.
We have noticed that since the last Chrome upgrade all the drag-drop functionality stopped working. Our app is working fine in older Chrome versions and in other browsers.
We are not sure whether this is hitting an edge case in this library or the issue is with in Chrome 77.0
Reproduction
Go to http://react-dnd.github.io/react-dnd/examples/dustbin/single-target (or to any of the examples)
Steps to reproduce the behavior:
The "inline" example is working fine:
chrome-working
However running the same code in the JavaScript/TypeScript tabs, so in a cross-origin iframe (e.g. in the embedded codesandbox) the drop event is not fired:
chrome-not-working
Running the example is also not working in the CodeSandBox editor which also uses an inframe.
chrome-not-working-codesandbox
In both cases there is this error in the console:

browser.js:38 Uncaught Invariant Violation: Cannot call hover while not dragging.
    at invariant (https://hmq56.csb.app/node_modules/invariant/browser.js:38:15)
    at checkInvariants (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:45:29)
    at DragDropManagerImpl.hover (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js:25:5)
    at Object.eval [as hover] (https://hmq56.csb.app/node_modules/dnd-core/dist/esm/DragDropManagerImpl.js:132:38)
    at HTML5Backend.handleTopDrop (https://hmq56.csb.app/node_modules/react-dnd-html5-backend/dist/esm/HTML5Backend.js:418:21)

Expected behavior
No exceptions in the console, drop event is fired
Desktop (please complete the following information):

  • OS: Windows 10 (1903)
  • Browser Chrome
  • Version 77.0.3865.75 (Official Build) (64-bit)

Additional context
We did some investigation and we've observed that Chrome fires the dragEnd event prematurely in the case of the iframe which breaks the invariant checks.

请问这个问题解决了吗?

你用中文提问是没人回答你的

@moyarich
Copy link

moyarich commented Mar 30, 2024

I recently encountered this error while working on my project. Upon investigation, I discovered that another component on the page was causing the drop event to fire unexpectedly.

The issue arose because I was using both "react-dropzone" and "react-dnd" on the same page. Whenever I attempted to drop a file onto a dropzone, the error occurred. It seemed that the drop event triggered by react-dropzone was propagating and being captured by "react-dnd".

To resolve this issue, I had to make a modification when calling the useDropzone hook from "react-dropzone". Specifically, I set noDragEventsBubbling to true:

    useDropzone({
        noDragEventsBubbling: true,
        ...props,
    })

This adjustment ensured that the drag events were handled appropriately, resolving the error.

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

No branches or pull requests