question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random error: TypeError: Cannot read properties of undefined (reading 'left')

See original GitHub issue

I am using interact.js in my Ionic + Vue project. I have screen where there is on circle on screen when it is dragged it is cloned into parent element. Code is shown below. This works most of the time in real browser (not 100%). But on my mobile I always get this weird error and I do not understand why. I tried to figure out why and where it is comming from but it is internal error from your code. I tracked bug down to this line of code :

interaction.start({ name: "drag" }, event.interactable, element);
   .on('move', dragOrClone); // this function that cases error is called on this line of global interact instance

    const dragOrClone = (event) => {
      const { currentTarget, interaction } = event;
      let element = currentTarget;

      if(
          interaction.pointerIsDown &&
          !interaction.interacting() &&
          currentTarget.style.transform === ""
      ) {
        element = currentTarget.cloneNode(true);

        element.style.position = "absolute";
        element.style.left = 0;
        element.style.top = 0;
        element.style.width = '24px';
        element.style.height = '24px';
        element.style.transform = 'translate(0px, 0px)';
        element.classList.remove('bg-yellow-800');
        element.classList.add('bg-yellow-600');

        // Adding object inside parent container element
        dropzone && dropzone.appendChild(element);

        position.x = 0;
        position.y = 0;

        // If we are moving an already existing item, we need to make sure the position object has
        // the correct values before we start dragging it
      }else if(
          interaction.pointerIsDown &&
          !interaction.interacting()
      ) {
        updatePositionFromTransform(currentTarget);
      }

      // Start the drag event
      interaction.start({ name: "drag" }, event.interactable, element);
    };

Edit : Also this circle that is used for cloning others does not have transform value so if statement which cloned object can be true. But when I but transform on it I do not see this error but this then breaks my intention of cloning object.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
LobanovAndreycommented, Dec 1, 2022

Hi, @taye, faced the same problem. As a result of searching, I found that in: https://github.com/taye/interact.js/blob/9c280e4e6557ff3732678d1c387250a3801d6e05/packages/%40interactjs/utils/domUtils.ts#L212 should always returns Rect, but there may be a situation when it is not possible to get ClientRect in https://github.com/taye/interact.js/blob/9c280e4e6557ff3732678d1c387250a3801d6e05/packages/%40interactjs/utils/domUtils.ts#L213-L214 this is due to element.getClientRects()[0], A possible solution to this problem would be always returns Rect with zeros in:https://github.com/taye/interact.js/blob/9c280e4e6557ff3732678d1c387250a3801d6e05/packages/%40interactjs/utils/domUtils.ts#L217-L225 for example so:

if (clientRect == null) {
  return {
    left: 0,
    right: 0,
    top: 0,
    bottom: 0,
    width: 0,
    height: 0,
  };
}

return {
  left: clientRect.left,
  right: clientRect.right,
  top: clientRect.top,
  bottom: clientRect.bottom,
  width: clientRect.width || clientRect.right - clientRect.left,
  height: clientRect.height || clientRect.bottom - clientRect.top,
};
0reactions
tayecommented, Jun 10, 2022

Also, an unminified stacktrace would be useful

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interactjs : Random error: TypeError: Cannot read properties ...
I am using interact.js in my Ionic + Vue project. I have screen where there is on circle on screen when it is...
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError: Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an undefined...
Read more >
How to fix this " Uncaught TypeError: Cannot read properties ...
Uncaught TypeError: Cannot read properties of undefined (reading 'mData') ... This error may be due to an incorrectly formatted table.
Read more >
[Solved] Unstable error, cannot read properties of undefined
It works normally, but randomly throws an error. Uncaught TypeError: Cannot read properties of undefined (reading 'user_id') Looking at the ...
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
All this means is that you are trying to access a property of an object that is undefined. These usually happens when we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found