79504776

Date: 2025-03-12 20:30:50
Score: 5
Natty:
Report link

Now a new problem in this context: When i dropping folders onto the drop zone, the WebFrame is unloaded after a short period (usually after 1–3 seconds), resulting in a white window. I have global listeners for all drag events, and all of them call preventDefault.

Here are a few examples:

useEffect(() => {
  const preventDefaults = (e) => {
    e.preventDefault();
  };

  const dropzone = document.getElementById("select_folder_btn");

  ["dragenter", "dragstart", "dragend", "dragleave", "dragover", "drag", "drop"].forEach((eventName) => {
    dropzone.addEventListener(eventName, preventDefaults);
    window.addEventListener(eventName, preventDefaults);
  });
});

function handleDropAsync(event: React.DragEvent) {
  const droppedItemsPaths = window.electronAPI.getFilePaths(event.dataTransfer.files);
  console.log("droppedItems: ", droppedItemsPaths);

  Promise.all(
    droppedItemsPaths.map((path) =>
      window.electronAPI.isDirectory(path).then((isDir) => {
        return isDir ? Promise.resolve(path) : window.electronAPI.dirname(path);
      })
    )
  ).then((directories) => {
    directories = directories.filter((value, index, self) => self.indexOf(value) === index);

    if (directories.length > 0) window.electronAPI.invoke("start-analysis", directories);
  });
}

The following error is produced by Electron:

Error sending from webFrameMain: Error: Render frame was disposed before WebFrameMain could be accessed

Does anyone have an Electron/React solution to prevent the window from unloading when a drop event occurs?

Reasons:
  • RegEx Blacklisted phrase (3): Does anyone have an Electron
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: silvio_l