forked from redfin/react-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This replaces the `getAboveTheFoldCount()` page method, which is awful: - It's separate from the elements themselves, so even remembering to update it can be a challenge. - If the number of root elements above the fold varies, then duplicative logic may be required to determine the count. - Middleware that inserts elements must remember to _increment_ it. - It has non-obvious behavior when root containers are used above the fold (redfin#144) This closes redfin#161 where @bartkusa proposed this _much_ nicer interface. This is a breaking change. The _default_ was previously to wake up the client controller after the _first_ element. With this change the client controller isn't bootstrapped until either `<TheFold />` is seen, or we're out of elements. So, if unspecified, the entire page is assumed to be above the fold.
- Loading branch information
Showing
10 changed files
with
83 additions
and
48 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
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
22 changes: 11 additions & 11 deletions
22
packages/react-server-test-pages/pages/root/aboveTheFold.js
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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import {ReactServerAgent, RootContainer, RootElement} from "react-server"; // eslint-disable-line | ||
|
||
// TODO: when we implement <TheFold/> (https://github.com/redfin/react-server/issues/161), | ||
// update this test page to use the new API | ||
import { | ||
ReactServerAgent, | ||
RootContainer, | ||
RootElement, | ||
TheFold, | ||
} from "react-server"; | ||
|
||
export default class RootWhenPage { | ||
handleRoute(next) { | ||
this.data = ReactServerAgent.get('/data/delay?ms=200'); | ||
this.data = ReactServerAgent.get('/data/delay?ms=200&big=10000') | ||
.then(res => res.body); | ||
return next(); | ||
} | ||
getElements() { | ||
return [ | ||
<RootContainer> | ||
<RootContainer when={this.data}> | ||
<div>One</div> | ||
</RootContainer>, | ||
<RootElement when={this.data}><div>Two</div></RootElement>, | ||
<RootContainer> | ||
<div>Three - there should be script tags starting from right after me b/c my getAboveTheFoldCount is 3!</div> | ||
<div>Three - there should be script tags starting from right after me.</div> | ||
<TheFold /> | ||
<RootElement when={this.data}><div>Four</div></RootElement> | ||
</RootContainer>, | ||
<div>Five</div>, | ||
] | ||
} | ||
|
||
getAboveTheFoldCount() { | ||
return 3; | ||
} | ||
} |
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
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,19 @@ | ||
import {Component} from "react"; | ||
|
||
export default class TheFold extends Component { | ||
render() { | ||
throw new Error("Something went wrong. Trying to render the fold..."); | ||
} | ||
} | ||
|
||
TheFold.defaultProps = { | ||
_isTheFold: true, | ||
} | ||
|
||
export function isTheFold(element) { | ||
return element && element.props && element.props._isTheFold; | ||
} | ||
|
||
export function markTheFold() { | ||
return {isTheFold:true}; | ||
} |
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