vue3-tree-vue icon indicating copy to clipboard operation
vue3-tree-vue copied to clipboard

Drop unexpected content to the device tree

Open SciManJD opened this issue 1 month ago • 1 comments

Hi, I suddenly found that if I drop something unexpected to the tree it causes an exception:

main.js:50 SyntaxError: Unexpected token ':', ":::::Posit"... is not valid JSON at JSON.parse () at Proxy.onDropNode (:8890/static/js/webpack:/aipex-5/node_modules/vue3-tree-vue/dist/vue3-tree-vue.esm.js:274:32) at fn (:8890/static/js/webpack:/aipex-5/node_modules/vue3-tree-vue/dist/vue3-tree-vue.esm.js:459:44) at fn (:8890/static/js/webpack:/aipex-5/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js:1737:12) at callWithErrorHandling (:8890/static/js/webpack:/aipex-5/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:199:19) at callWithAsyncErrorHandling (:8890/static/js/webpack:/aipex-5/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:206:17) at HTMLDivElement.r (:8890/static/js/webpack:/aipex-5/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js:730:5)

In my case I caught a card, created with another component and I dropped it to tree. First I thought that I can solve this by the callback dropValidаtor, but the exception happens before it. How can I protect the device tree from dropping invalid data?

SciManJD avatar Nov 10 '25 16:11 SciManJD

Please share a minimum example to reproduce.

geekhybrid avatar Nov 10 '25 17:11 geekhybrid

My application is too complex. But the easiest way to get the problem is just to drag some texts from a text editor and drop it anywhere in the tree. This should cause the mentioned exception. The component will try to parse this text, but because it is not according to the rules of the JSON-format, it will generate this exception.

SciManJD avatar Nov 11 '25 06:11 SciManJD

That's not a supported feature. We only support dragging nodes within the tree, not arbitrary objects.

geekhybrid avatar Nov 11 '25 08:11 geekhybrid

Ok, but isn't there any possibility to catch an event that comes earlier that the call of the function onDropNode, to check the data and reject it with my own code?

SciManJD avatar Nov 11 '25 11:11 SciManJD

It may not be straightforward. Does this exception cause your application to crash ? I suppose the user should not be trying interesting things like that on an app if it doesn't support it.

geekhybrid avatar Nov 11 '25 16:11 geekhybrid

My application doesn't crash. I just see the exception in the console and this annoys me. But I found a solution. I caught the error in errorCaptured hook and by returning false, the error doesn't occur in the console anymore. We can close this issue.

SciManJD avatar Nov 12 '25 06:11 SciManJD