My problem
I am creating an isomorphic application in React that first renders the component on the server side, and then uses the React browser side intelligent re-rendering.
I came across a situation where the DOM may no longer synchronize with the state of the React component before React can first display the browser side. This can happen when the user is on a slow internet connection and the react.js file takes some time to download (which is also the reason that I am creating an isomorphic application)
Example
Here is an example that I put together to show this: http://jsfiddle.net/jesstelford/z4o44esb
- Run this example
- Togle checkbox
- Click "Render React"
- The current state of React is displayed in the console.
- Note that it is still set to {done: false}, which is incorrect
var TodoItem = React.createClass({
Possible (half) solution
I found one possible solution using React refs : http://jsfiddle.net/jesstelford/z4o44esb/2
var TodoItem = React.createClass({
The disadvantages of this approach are:
- status is synchronized after the DOM is displayed
- Requires additional code external to the component itself for synchronization on first rendering
My question
When pre-rendering the React Component server, there is some way to synchronize the state of the DOM with this React component before it displays the browser side, since the DOM was processed by the user before React loaded on the browser side
Thanks!
reactjs isomorphic-javascript
Jess telford
source share