Accessing window properties inside useEffect leads to "Invalid calling object" error in IE 11
See original GitHub issueHello,
I’ve noticed in two specific use cases that accessing window properties inside a useEffect leads to the error “Invalid calling object” in Internet Explorer 11.
I have not been able to isolate a minimum demo of the problem unfortunately.
First problem - window scroll
useEffect(() => { window.scroll(0, 0); }, [])
Second problem - Apollo client polling
useEffect(() => { startPolling(120000); return stopPolling; }, []);
https://github.com/apollographql/apollo-client/blob/6f579ea2cdf8c78acb004a4457a7a6764d64091e/packages/apollo-client/src/scheduler/scheduler.ts The start polling method internally uses setInterval.
In both cases, replacing the useEffect by lifecycles removes the error.
React version: 16.7.0-alpha.2
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Invalid hook call. Hooks can only be called inside of the body ...
I want to show some records in a table using React but I got this error: Invalid hook call ...
Read more >Invalid Hook Call Warning - React
You are probably here because you got the following error message: Hooks can only be called inside the body of a function component....
Read more >A Definitive Guide to Handling Errors in JavaScript - Kinsta
This error occurs when you try to invoke a method that doesn't exist in your script, or it does but can not be...
Read more >CHANGELOG.md - facebook/react - Sourcegraph
renderToString : Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <Suspense> boundary...
Read more >TypeScript errors and how to fix them
Alternatively, you can write your function implementation inside a source code file ( *.ts ). TS1192. error TS1192: Module ' json5 ' has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We are seeing the same issue. currently we will not be able to get a repro for a few weeks.
But i can confirm that the bug happens under these conditions:
Have
devtool: 'eval-source-map'
somewhere in a webpack buildOpen IE
Fair enough 🙂 If you do find a reduced case we’d appreciate sharing it.
All useEffect does is run the work a bit later, when the browser isn’t busy. It’s hard to guess which APIs don’t work in this case in IE or why.