bruderstein/react-render-hook

type error `Cannot delete property '__REACT_DEVTOOLS_GLOBAL_HOOK__`

Closed this issue · 4 comments

I am using a simple proof of concept react app to test out this hook.
I don't know if I am doing something wrong, but therequire('react-render-hook') is throwing an error on page load even without calling any methods in the api.
I made sure to import this hook before react.

error

app.js:86Uncaught TypeError: Cannot delete property '__REACT_DEVTOOLS_GLOBAL_HOOK__' of #<Window>

it is because of this piece of code in src\globalHook.js

if (typeof global.__REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined') {
    delete global.__REACT_DEVTOOLS_GLOBAL_HOOK__;
}

Can you please point me in the right direction ?

Where are you running the code? It looks like you're running in a browser with the devtools running - that's not supported, and almost certainly won't work.

When devtools adds the __REACT_DEVTOOLS_GLOBAL_HOOK__ it adds it as a undeleteable property - when react-render-hook adds it, it adds it as a normal property, so it can always delete it.

This is meant to be run in an emulated DOM environment (e.g. jsdom or possibly phantomJS).

If you're running in an emulated DOM, we might need to do some debugging to see where the property is coming from.

Makes sense. I am doing it on browser, so not emulated. :-(
Basically, I am trying to access the full React-dom tree json to visualize our App structure.
Good to know that it doesn't work if react devtools extension is running.
Appreciate the swift response.

thanks for coming back. This situation will improve drastically when @gaearon's PR facebook/react#6549 lands in a released version. Then we'll be able to do all this stuff without the devtools hack.

I'm running into this issue as well when attempting to run tests in the browser instead of the command-line while using expect-react-shallow which ultimately depends on this package. It looks like @gaearon's PR mentioned above is in 15.1, so maybe this can be addressed now?