-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getServerSideProps should support props value as Promise (#28607)
Previous to this change, getServerSideProps could only return plain objects for props, e.g.: ```javascript export async function getServerSideProps() { return { props: { text: 'some value', } } } ``` With this commit, the props object can also be a Promise, e.g. ```javascript export async function getServerSideProps() { return { props: (async function () { return { text: 'promise value', } })(), } } ``` For now, the framework simply waits for the results of the props Promise to resolve, but this small change sets the groundwork for later allowing props to be streamed (cc @devknoll). ## Feature - [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. -- *This is part of @devknoll's ongoing work to support streaming.* - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. *not sure if this applies here* - [ ] Errors have helpful link attached, see `contributing.md`
- Loading branch information
Showing
4 changed files
with
31 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
test/integration/getserversideprops/pages/promise/index.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,15 @@ | ||
export async function getServerSideProps() { | ||
return { | ||
props: (async function () { | ||
return { | ||
text: 'promise', | ||
} | ||
})(), | ||
} | ||
} | ||
|
||
export default ({ text }) => ( | ||
<> | ||
<div>hello {text}</div> | ||
</> | ||
) |
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