Unverified Commit f7ac942e authored by Maedah Batool's avatar Maedah Batool Committed by GitHub

Add note about NEXT_DATA hydration (#37480)

Missing documentation around `NEXT_DATA` hydration when using `getServerSideProps()`. This PR warn users that the result of `getServerSideProps()/getStaticProps` is also available on the client-side due to React Hydration so they should not use any sensitive information in the props.



## Bug

- [x] Related issues linked using [fixes number](https://github.com/vercel/documentation/issues/418)
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent b3000594
...@@ -68,6 +68,8 @@ For the initial page load, `getInitialProps` will run on the server only. `getIn ...@@ -68,6 +68,8 @@ For the initial page load, `getInitialProps` will run on the server only. `getIn
- `getInitialProps` can **not** be used in children components, only in the default export of every page - `getInitialProps` can **not** be used in children components, only in the default export of every page
- If you are using server-side only modules inside `getInitialProps`, make sure to [import them properly](https://arunoda.me/blog/ssr-and-server-only-modules), otherwise it'll slow down your app - If you are using server-side only modules inside `getInitialProps`, make sure to [import them properly](https://arunoda.me/blog/ssr-and-server-only-modules), otherwise it'll slow down your app
> Note that irrespective of rendering type, any `props` will be passed to the page component and can be viewed on the client-side in the initial HTML. This is to allow the page to be [hydrated](https://reactjs.org/docs/react-dom.html#hydrate) correctly. Make sure that you don't pass any sensitive information that shouldn't be available on the client in `props`.
## TypeScript ## TypeScript
If you're using TypeScript, you can use the `NextPage` type for function components: If you're using TypeScript, you can use the `NextPage` type for function components:
......
...@@ -14,6 +14,8 @@ export async function getServerSideProps(context) { ...@@ -14,6 +14,8 @@ export async function getServerSideProps(context) {
} }
``` ```
> Note that irrespective of rendering type, any `props` will be passed to the page component and can be viewed on the client-side in the initial HTML. This is to allow the page to be [hydrated](https://reactjs.org/docs/react-dom.html#hydrate) correctly. Make sure that you don't pass any sensitive information that shouldn't be available on the client in `props`.
## When does getServerSideProps run ## When does getServerSideProps run
`getServerSideProps` only runs on server-side and never runs on the browser. If a page uses `getServerSideProps`, then: `getServerSideProps` only runs on server-side and never runs on the browser. If a page uses `getServerSideProps`, then:
......
...@@ -14,6 +14,8 @@ export async function getStaticProps(context) { ...@@ -14,6 +14,8 @@ export async function getStaticProps(context) {
} }
``` ```
> Note that irrespective of rendering type, any `props` will be passed to the page component and can be viewed on the client-side in the initial HTML. This is to allow the page to be [hydrated](https://reactjs.org/docs/react-dom.html#hydrate) correctly. Make sure that you don't pass any sensitive information that shouldn't be available on the client in `props`.
## When should I use getStaticProps? ## When should I use getStaticProps?
You should use `getStaticProps` if: You should use `getStaticProps` if:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment