React: `priorFocusedElem.focus()` throws in IE11

Created on 8 May 2018  路  12Comments  路  Source: facebook/react

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
We have an onClick handler on an SVG element. The handler sets a state property that causes the element to be hidden (via CSS). This makes IE11 throw on this line:
https://github.com/facebook/react/blob/52eb59dda2eb0d9afe3a18aacd6142c1d2f7ee25/packages/react-dom/src/client/ReactInputSelection.js#L72

It seems that #11800 removed a try/catch protection for this.

I am working around the problem by stubbing focus like this:

if (typeof SVGElement.prototype.focus === 'undefined') { SVGElement.prototype.focus = function () {}; }

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Worked in 16.2.2

DOM Regression

All 12 comments

Can you put together a reproduction demonstrating the issue?

In the meantime please feel free to send a PR adding try-catch with an explanation comment

I hava a same problem.

React 16.4

@ThaddeusJiang That doesn't help us in any way. It will help us if you provide a reproducing case. Thanks.

Can somebody with IE11 figure out if:

  • SVGs don't have focus() in IE11
  • If their focus() call throws on hidden elements
  • Something else?

Sorry, I forgot about this because my workaround solved it for me. I will make a PR and try to figure out if it applies to other classes as well

Thanks!

@gaearon

when user drags a Element, 'focus' is not supported Exception be thrown

Environment

  • IE11
  • React 16.4

step 1
step 2
step 3

OK. Somebody want to send a PR that reverts https://github.com/facebook/react/pull/11800?

Yes, I do.

Fixed in React 16.4.1.

Was this page helpful?
0 / 5 - 0 ratings