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
Invariant Violation: Expected targetIds to be registered. #763
Comments
I also met this problem, it show me Expected sourceIds to be registered, is there any case could cause this happen? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Ignoring this wouldn't help so anyone? |
Hey there ! Doesn't explain much the source of the issue, but I hope it can help ! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I faced this issue when I've had EDIT |
Moved provider to the very top (even into the ReactDOM.render call), still getting the error after every hot reload and have to refresh the page. |
@d07RiV did you ever find a solution? I have multiple drop targets (some nested), and have DndProvider as the top level component, and I'm getting this error on every hot-reload still. |
Though clytras 's try, this issue hasn't been resolved. It seems |
if this error only shows on "hot-reload", problem might be resolved in production mode, still, error free should be guaranteed before deploy.. |
This should be reopened. Problem appears after a hot reload when performing a dnd action. |
Make sure your imports in the file where your DND provider is being used are ordered correctly. Ex: WRONG: RIGHT: Conclusion: |
Currently experiencing same problem but occurs only when I'm manually using |
still occurred and don't know why |
This worked for me thanks |
@dieguiviti @adarshmishra07 There is an ESLint rule about the correct import order that does exacly that, warn you about (or fix) the wrong import order. Externmal module imports should always be placed before parent/sibling/current directories imports. You can read about the rule here import/order: Enforce a convention in module import order. You should always use ESLint even not in auto/save mode, just to get some nice warnings/tips that will help resolve such issues. |
Unfortunately, the workaround does not work for the larger codebase I'm working on, no matter how far up the import chain I put the imports. I would love to see this issue re-opened because it seems like something that should work regardless of import ordering. |
Totally agree. I imported the react-dnd
Cannot go higher =) |
bump |
Just wanted to mention that I get this error with a stripped-down example from DnD itself, on a NextJS app. https://react-dnd.github.io/react-dnd/examples/sortable/simple |
I'm also having this issue with a fairly simple Next.js app. Dragging after a hot reload throws the error. |
Refresh the app/ run the app again probably this might help. For me this worked. |
This seems to be fixed in v14.0.4 🥳 |
are you sure?? |
Still experiencing this issue with v14.0.5. Using react-dnd in combination w/ SlateJS. Once an element is dragged, SlateJS is remounting the component. On this initial mount, the |
hello I am experiencing this issue too |
Same for me on Next.js project. |
For anybody experiencing this with NextJS's HMR, I found as a workaround to use automatic full page refresh instead of hot reload using the live-server package: the idea is to run live-server together with NextJS server and connect to live-server's Websocket from NextJS app:
if (process.env.NODE_ENV === 'development') {
if (typeof window !== 'undefined') {
new WebSocket('ws://127.0.0.1:8080/ws').onmessage = function(msg) {
if (msg.data === 'reload') window.location.reload()
}
console.log('Live reload enabled.')
}
}
The drawback is that you'll entirely opt-out of NextJS's HMR and run 2 servers. |
This is my current working solution with Next.js, not pretty, but works for local development: // file: .scripts/monkey-patch-dnd.js
// Temporary monkey patch
// Remove invariant check from dnd-core
// Prevent https://github.com/react-dnd/react-dnd/issues/763
const fs = require('fs')
const path = require('path')
const hoverPath = 'node_modules/dnd-core/dist/esm/actions/dragDrop/hover.mjs'
const filePath = path.resolve(process.cwd(), hoverPath)
if (!fs.existsSync(filePath)) process.exit(1)
const content = fs.readFileSync(filePath).toString()
const invariantLineContent = `invariant(target, 'Expected targetIds to be registered.');`
const updatedContent = content.replace(invariantLineContent, '')
fs.writeFileSync(filePath, updatedContent)
console.log('• MONKEY PATCHED DND \n') // file: package.json
{
"scripts": {
"postinstall": "node .scripts/monkey-patch-dnd.js"
},
} Note: |
If I'm following these discussions correctly, there two or three common scenarios for this error message:
|
* fix: "Invariant Violation: Expected targetIds to be registered." We've sporadically seen this error from customers. The call stack indicates that it's originating from HTML5BackendImpl's handleTopDragOver's requestAnimationFrame callback. I've been unable to reproduce it locally; however, if I simulate a slowdown by replacing `requestAnimationFrame(callback)` with `setTimeout(callback, 10000)`, I can fairly reliably reproduce this error. To fix it, I believe HTML5BackendImpl should consistently clear the hover animation whenever the drag operation is ended for any reason. I locally tested this fix in the v15.1.2 tag, and it appeared to work. Fixes #763, #3403 * chore: semver * fix: cancel any raf before creating a new one Co-authored-by: Chris Trevino <chtrevin@microsoft.com>
There's a latest fix to this problem and after updating the package, the error no longer appears. |
I 'm using it latest version, but error is appeared. I think, this appear only in StrictMode. |
None of the above resolved the issue for me, but this stack thread helped me out - had to do with race conditions for me. In case it's helpful, my solution: I'm working in React. Placed my custom
|
This issue could also appear if you are adding new DOM nodes during drag over elements, for example, based on
If you need to add special elements for a better UX I recommend having these elements already in the DOM for example with |
yes i also has this question |
Same here, anyone ? |
if you remove strict mode in index.js file . it will solve |
No Strict Mode on my website |
We ran into this issue before and traced it to a dragged item unmounting while being dragged. I'd double check that you don't have any complex state transitions while hovering that would cause something similar |
is have a solution? |
Hi there. We are getting this error (although the functionality is okay and works fine). Do you have any idea how it can happen? couldn't figure it out from the source code.
The text was updated successfully, but these errors were encountered: