-
Notifications
You must be signed in to change notification settings - Fork 49.9k
Description
Using V8 as a backend with snapshots enabled. To optimize performance, it is beneficial to create snapshots to improve server side rendering performance. After creating snapshot with React.js + ReactServer.js, the resulting server side component rendering errors as follows:
Invariant Violation: Trying to release an instance into a pool of a different type.
The logic that is causing the error is the Math.random() function, which has issues with snapshots and V8. There are 5 areas where this function is used. At the moment, the biggest problem for server side rendering is the following location; however, the other 4 will also impact if code reached the Math.random() at runtime.
/**
* Size of the reactRoot ID space. We generate random numbers for React root
* IDs and if there's a collision the events and DOM update system will
* get confused. In the future we need a way to generate GUIDs but for
* now this will work on a smaller scale.
*/
var GLOBAL_MOUNT_POINT_MAX = Math.pow(2, 53);
var ServerReactRootIndex = {
createReactRootIndex: function () {
return Math.ceil(Math.random() * GLOBAL_MOUNT_POINT_MAX);
}
};Would it be possible to fix this such that server side heap snapshots can be generated without having to worry about issues with server Math.random()? Could some sort of algorithm that doesn't rely on Math.random() be used to generate the nodes, root indexes, etc.?
OS: Ubuntu 14.04 x64
V8: 5.0.104
React: 0.14.7