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
Bug: Throws an error on particular sites: TypeError: Cannot use 'in' operator to search for 'animation' in undefined
#26777
Comments
TypeError: Cannot use 'in' operator to search for 'animation' in undefined
Can you do this check yourself before injecting React? I'm not sure I understand why it's reasonable to expect React to run in an environment where it has no access to inline styles (since it would also try to set them later when rendering actual elements). I might be misunderstanding CSP though — I don't have any knowledge in that area. Can you explain more? |
This scenario is a bit complicated because of the browser extensions involved, but I'll do my best to explain it. Imagine that if I want to develop a browser extension that allows users to take screenshots of web pages, I need to inject JavaScript code (called Content scripts for browser extensions) into the target web page, and the content script will contain React, which I use to build the user interface (pickboxes, buttons, etc.) As I explained earlier, the React DOM gets the You can run I guess this is because the site uses a very strict CSP:
Although the CSP rules on this site prohibit the execution of code, the content script is very specific and it still works fine in this case, as well as setting inline styles properly. However, this site's CSP causes the value of In other words, React should work fine in this scenario, but now it throws an error. I also found that although |
To summarise: The React DOM's existing way of getting a |
This isn't because of CSP. It's because the document is SVG rather than HTML. You can see that document.documentElement.namespaceURI is |
I have been getting the same error for almost a year on my Chrome extension.
|
React version: 18.2.0
I have developed a browser extension where I inject React into the website to build the interface. Recently, I have received feedback from users that my application is reporting an error on this website (https://user-images.githubusercontent.com/16556693/236126882-007c76ae-f976-49d9-940e-12252707f740.svg):
I then discovered that this error was caused by React.
This site uses a strict CSP to restrict external code, resulting in the value of the following code in React becoming
undefined
:https://github.com/facebook/react/blob/v18.2.0/packages/react-dom/src/events/getVendorPrefixedEventName.js#L51
After this, the code here uses the
in
operator forstyle
, causing this error:https://github.com/facebook/react/blob/v18.2.0/packages/react-dom/src/events/getVendorPrefixedEventName.js#L85
Steps To Reproduce
document.createElement('div').style
in consoleLink to code example:
The current behavior
The value of
style = document.createElement('div').style
isundefined
, causing React to report this error later in thestyleProp in style
code.The expected behavior
Do not report errors
The text was updated successfully, but these errors were encountered: