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

TypeError: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element'. in monitorResize #239

Open
Vadorequest opened this issue Jan 13, 2021 · 1 comment

Comments

@Vadorequest
Copy link

The following error happens when hovering an element.

See video: https://youtu.be/-aLHvTHvp7Q

TypeError: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element'.
    at ft (util.js:58)
    at Align.js:110
    at Oi (react-dom.production.min.js:262)
    at KqkS.t.unstable_runWithPriority (scheduler.production.min.js:18)
    at jl (react-dom.production.min.js:122)
    at Ti (react-dom.production.min.js:261)
    at pi (react-dom.production.min.js:243)
    at react-dom.production.min.js:123
    at KqkS.t.unstable_runWithPriority (scheduler.production.min.js:18)
    at jl (react-dom.production.min.js:122)
    at Hl (react-dom.production.min.js:123)
    at $l (react-dom.production.min.js:122)
    at De (react-dom.production.min.js:292)
    at react-dom.production.min.js:50
    at zr (react-dom.production.min.js:105)
    at Zt (react-dom.production.min.js:75)
    at Jt (react-dom.production.min.js:74)
    at KqkS.t.unstable_runWithPriority (scheduler.production.min.js:18)
    at Gt (react-dom.production.min.js:73)
    at HTMLDivElement.o (helpers.js:72)

Unminified code monitorResize:

export function monitorResize(element, callback) {
    var prevWidth = null;
    var prevHeight = null;

    function onResize(_ref) {
        var _ref2 = _slicedToArray(_ref, 1)
          , target = _ref2[0].target;

        if (!document.documentElement.contains(target))
            return;

        var _target$getBoundingCl = target.getBoundingClientRect()
          , width = _target$getBoundingCl.width
          , height = _target$getBoundingCl.height;

        var fixedWidth = Math.floor(width);
        var fixedHeight = Math.floor(height);

        if (prevWidth !== fixedWidth || prevHeight !== fixedHeight) {
            // https://webkit.org/blog/9997/resizeobserver-in-webkit/
            Promise.resolve().then(function() {
                callback({
                    width: fixedWidth,
                    height: fixedHeight
                });
            });
        }

        prevWidth = fixedWidth;
        prevHeight = fixedHeight;
    }

    var resizeObserver = new ResizeObserver(onResize);

    if (element) {
        resizeObserver.observe(element); // CRASHES HERE
    }

    return function() {
        resizeObserver.disconnect();
    }
    ;
}
@Vadorequest
Copy link
Author

Vadorequest commented Jan 13, 2021

This can be reproduced when using <Fragment> as child of rc-tooltip. Or maybe it's because the first element inside the Fragment isn't an actual element.

return (
  <Tooltip ...>
    <Fragment>
      {prefix}
      <a
        ...
      >
        {children}
      </a>
      {suffix}
    </Fragment>
  </Tooltip>
  );

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

1 participant