Skip to content

Commit 5d2730b

Browse files
bennettdamsleerob
andauthored
docs: Mention middleware for getStaticProps (#33273)
Mention middleware to access the request for a page that uses `getStaticProps`, e.g. for authentication purposes. ## Documentation / Examples - [x] Make sure the linting passes by running `yarn lint` Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
1 parent 338307c commit 5d2730b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/basic-features/data-fetching/get-static-props.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ You should use `getStaticProps` if:
2323
- The data can be publicly cached (not user-specific)
2424
- The page must be pre-rendered (for SEO) and be very fast — `getStaticProps` generates `HTML` and `JSON` files, both of which can be cached by a CDN for performance
2525

26-
Because `getStaticProps` runs at build time, it does **not** receive data that’s only available during request time, such as query parameters or `HTTP` headers, as it generates static `HTML`. When combined with [Incremental Static Regeneration](/docs/basic-features/data-fetching/incremental-static-regeneration.md) however, it will run in the background while the stale page is being revalidated, and the fresh page served to the browser.
26+
When combined with [Incremental Static Regeneration](/docs/basic-features/data-fetching/incremental-static-regeneration.md), `getStaticProps` will run in the background while the stale page is being revalidated, and the fresh page served to the browser.
27+
28+
Because `getStaticProps` runs at build time, it does **not** have access to the incoming request (such as query parameters or `HTTP` headers) as it generates static `HTML`. If you need access to the request for your page, consider using [Middleware](/docs/middleware.md) in addition to `getStaticProps`.
2729

2830
## Using getStaticProps to fetch data from a CMS
2931

@@ -76,7 +78,7 @@ Alternatively, if you are **not** using API routes to fetch data, then the [`fet
7678

7779
To verify what Next.js eliminates from the client-side bundle, you can use the [next-code-elimination tool](https://next-code-elimination.vercel.app/).
7880

79-
## Statically Generates both HTML and JSON
81+
## Statically generates both HTML and JSON
8082

8183
When a page with `getStaticProps` is pre-rendered at build time, in addition to the page HTML file, Next.js generates a JSON file holding the result of running `getStaticProps`.
8284

0 commit comments

Comments
 (0)