question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requestAnimationFrame polyfill breaks server-side rendering

See original GitHub issue

This code causes an exception when running on server side.


if (typeof window !== "undefined") {
  win = window;
} else if (typeof self !== "undefined") {
  win = self;
} else {
  win = undefined;
}

// requestAnimationFrame() shim by Paul Irish
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
var request = win.requestanimationframe || win.webkitrequestanimationframe || win.mozrequestanimationframe || win.orequestanimationframe || win.msrequestanimationframe || function (callback) {
  return win.settimeout(callback, 1000 / 60);
};
var request = win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.oRequestAnimationFrame || win.msRequestAnimationFrame || function (callback) {
[1]                  ^
[1] 
[1] TypeError: Cannot read property 'requestAnimationFrame' of undefined
[1]     at Object.<anonymous> (/home/codejunkienick/upwork/imdadmin/node_modules/react-virtualized/dist/commonjs/utils/animationFrame.js:21:18)
[1]     at Module._compile (module.js:573:30)
[1]     at Module._extensions..js (module.js:584:10)
[1]     at Object.require.extensions.(anonymous function) [as .js] (/home/codejunkienick/upwork/imdadmin/node_modules/babel-register/lib/node.js:152:7)
[1]     at Module.load (module.js:507:32)
[1]     at tryModuleLoad (module.js:470:12)
[1]     at Function.Module._load (module.js:462:3)
[1]     at Module.require (module.js:517:17)
[1]     at require (internal/module.js:11:18)
[1]     at Object.<anonymous> (/home/codejunkienick/upwork/imdadmin/node_modules/react-virtualized/dist/commonjs/utils/requestAnimationTimeout.js:8:23)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
prempiyushcommented, Sep 18, 2017

I was about to open an issue for the very same thing. This seems to be introduced when Grid has started to depend on requestAnimationFrame in v9.10.0. Rolling back reac-virtualized to v9.9.0 fixed it for me.

Here is stack-trace for the error…

TypeError: Cannot read property 'requestAnimationFrame' of undefined
    at Object.<anonymous> (/Users/prempiyush/work/code/profiling-ui-demo/node_modules/react-virtualized/dist/commonjs/utils/animationFrame.js:21:18)
    at Module._compile (module.js:409:26)
    at Module._extensions..js (module.js:416:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/prempiyush/work/code/profiling-ui-demo/node_modules/babel-register/lib/node.js:134:7)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/prempiyush/work/code/profiling-ui-demo/node_modules/react-virtualized/dist/commonjs/utils/requestAnimationTimeout.js:8:23)
    at Module._compile (module.js:409:26)
    at Module._extensions..js (module.js:416:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/prempiyush/work/code/profiling-ui-demo/node_modules/babel-register/lib/node.js:134:7)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)```
0reactions
bvaughncommented, Sep 18, 2017

Glad to hear! Again, apologies for the regression.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`requestAnimationFrame` polyfill error in Jest tests
Got this error after upgrading to React when I ran my Jest unit tests: React depends on requestAnimationFrame. Make sure that you load...
Read more >
Error Boundaries - React
Server side rendering ; Errors thrown in the error boundary itself (rather than its children). A class component becomes an error boundary if...
Read more >
Bookmarks - A Lazy Sequence
Tradeoffs in server side and client side rendering ... His blog post breaks down how he wrote it, and how he used core.async...
Read more >
(Now More Than Ever) You Might Not Need jQuery - CSS-Tricks
This simple script tag can polyfill just about anything. If you haven't heard about this polyfill service from the Financial Times you can...
Read more >
A Detailed Explanation of JavaScript Game Loops and Timing
We'll cover a polyfill for node.js/io.js and lesser browsers later on. ... speculate that rendering earlier in the requestAnimationFrame ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found