-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for out-of-order render client side (#948)
React Server assumes that it can render in-order client side since the data required to render each element will necessarily have arrived by the time it is reached. In order to support moving the JS for non-critical above-the-fold components into a secondary bundle, though, we would need support for out-of-order rendering in the browser.
- Loading branch information
Showing
3 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Component} from "react"; | ||
import {RootElement} from "react-server"; | ||
import Q from "q"; | ||
|
||
class TurnGreen extends Component { | ||
componentDidMount() { | ||
this.setState({color: "green"}); | ||
} | ||
render() { | ||
const {color} = this.state || {}; | ||
return <div style={{backgroundColor: color || "red"}}>{this.props.children}</div>; | ||
} | ||
} | ||
|
||
export default class RootOrderPage { | ||
handleRoute(next) { | ||
this.first = this.second = Q(); | ||
|
||
if (typeof window !== "undefined") { | ||
this.first = Q.delay(1000); | ||
} | ||
|
||
return next(); | ||
} | ||
getElements() { | ||
return [ | ||
<RootElement when={this.first}> | ||
<TurnGreen>This should turn green second</TurnGreen> | ||
</RootElement>, | ||
<RootElement when={this.second}> | ||
<TurnGreen>This should turn green first</TurnGreen> | ||
</RootElement>, | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters