-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test page for page forwarding #806
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 50 additions & 0 deletions
50
packages/react-server-test-pages/pages/navigation/forward.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {ReactServerAgent} from "react-server"; | ||
|
||
export default class ForwardPage { | ||
handleRoute() { | ||
const request = this.getRequest(); | ||
let params = request.getQuery(); | ||
if (params) { | ||
params = params.value; | ||
} else { | ||
params = 0; | ||
} | ||
|
||
//fetch some data | ||
this.data = ReactServerAgent.get('/data/delay?ms=1000&val='+params); | ||
|
||
return this.data.then((res) => { | ||
//then depending on said data, forward to one of two pages, and pass along the data we pre-fetched | ||
if (res.body % 2 === 0) { | ||
if (typeof window !== 'undefined') { //would be nice if this is `process.env.isServer` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you change this comment to be a |
||
return require.ensure(["./forwardEven"], () => { | ||
return { | ||
page: require("./forwardEven").default, | ||
}; | ||
}); | ||
} else { | ||
return { | ||
page: require("./forwardEven").default, | ||
}; | ||
} | ||
} else { | ||
if (typeof window !== 'undefined') { //would be nice if this is `process.env.isServer` | ||
return require.ensure(["./forwardOdd"], () => { | ||
return { | ||
page: require("./forwardOdd").default, | ||
}; | ||
}); | ||
} else { | ||
return { | ||
page: require("./forwardOdd").default, | ||
}; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
getElements() { | ||
return <div>boop</div>; | ||
} | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
packages/react-server-test-pages/pages/navigation/forwardEven.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {ReactServerAgent, RootElement} from "react-server"; | ||
|
||
const Even = ({body}) => <div className="even">Hey look I'm even because I am {body}</div>; | ||
|
||
export default class ForwardEvenPage { | ||
handleRoute() { | ||
const request = this.getRequest(); | ||
let params = request.getQuery(); | ||
if (params) params = params.value; | ||
else params = 0; | ||
|
||
//fetch some data (should be from cache) | ||
this.data = ReactServerAgent.get('/data/delay?ms=1000&val='+params); | ||
|
||
return {code: 200}; | ||
} | ||
|
||
getElements() { | ||
return [ | ||
<RootElement when={this.data}><Even /></RootElement>, | ||
]; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/react-server-test-pages/pages/navigation/forwardOdd.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {ReactServerAgent, RootElement} from "react-server"; | ||
|
||
const Odd = ({body}) => <div className="odd">Hey look I'm odd because I am {body}</div>; | ||
|
||
export default class ForwardOddPage { | ||
handleRoute() { | ||
const request = this.getRequest(); | ||
let params = request.getQuery(); | ||
if (params) params = params.value; | ||
else params = 0; | ||
|
||
//fetch some data (should be from cache) | ||
this.data = ReactServerAgent.get('/data/delay?ms=1000&val='+params); | ||
|
||
return {code: 200}; | ||
} | ||
|
||
getElements() { | ||
return [ | ||
<RootElement when={this.data}><Odd /></RootElement>, | ||
]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor this section a bit to limit code reuse? Something like this should work: