The following Image Optimization cloud providers are included:
The following Image Optimization cloud providers are included:
- Default: Works automatically with `next dev`, `next start`, or a custom server
- Default: Works automatically with `next dev`, `next start`, or a custom server
-[Vercel](https://vercel.com): Works automatically when you deploy on Vercel, no configuration necessary. [Learn more](https://vercel.com/docs/next.js/image-optimization)
-[Vercel](https://vercel.com): Works automatically when you deploy on Vercel, no configuration necessary. [Learn more](https://vercel.com/docs/concepts/image-optimization)
@@ -19,7 +19,7 @@ The big advantage of ISR is having the flexibility to choose which pages are gen
...
@@ -19,7 +19,7 @@ The big advantage of ISR is having the flexibility to choose which pages are gen
## Using ISR to fetch data from a blog
## Using ISR to fetch data from a blog
To use ISR add the `revalidate` prop to `getStaticProps`:
To use ISR, add the `revalidate` prop to `getStaticProps`:
```jsx
```jsx
functionBlog({posts}){
functionBlog({posts}){
...
@@ -76,12 +76,42 @@ When a request is made to a page that was pre-rendered at build time, it will in
...
@@ -76,12 +76,42 @@ When a request is made to a page that was pre-rendered at build time, it will in
- Any requests to the page after the initial request and before 10 seconds are also cached and instantaneous.
- Any requests to the page after the initial request and before 10 seconds are also cached and instantaneous.
- After the 10-second window, the next request will still show the cached (stale) page
- After the 10-second window, the next request will still show the cached (stale) page
- Next.js triggers a regeneration of the page in the background.
- Next.js triggers a regeneration of the page in the background.
- Once the page has been successfully generated, Next.js will invalidate the cache and show the updated page. If the background regeneration fails, the old page would still be unaltered.
- Once the page generates successfully, Next.js will invalidate the cache and show the updated page. If the background regeneration fails, the old page would still be unaltered.
When a request is made to a path that hasn’t been generated, Next.js will server-render the page on the first request. Future requests will serve the static file from the cache.
When a request is made to a path that hasn’t been generated, Next.js will server-render the page on the first request. Future requests will serve the static file from the cache. ISR on Vercel [persists the cache globally and handles rollbacks](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration).
[Incremental Static Regeneration](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration) covers how to persist the cache globally and handle rollbacks.
[Incremental Static Regeneration](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration) covers how to persist the cache globally and handle rollbacks.
## Error Handling and Revalidation
If there is an error inside `getStaticProps` when handling background regeneration, or you manually throw an error, the last successfully generated page will continue to show. On the next subsequent request, Next.js will retry calling `getStaticProps`.
```jsx
exportasyncfunctiongetStaticProps(){
// If this request throws an uncaught error, Next.js will
// not invalidate the currently shown page and
// retry getStaticProps on the next request.
constres=awaitfetch('https://.../posts')
constposts=awaitres.json()
if(!res.ok){
// If there is a server error, you might want to
// throw an error instead of returning so that the cache is not updated
// until the next successful request.
thrownewError(`Failed to fetch posts, received status ${res.status}`)
}
// If the request was successful, return the posts
// and revalidate every 10 seconds.
return{
props:{
posts,
},
revalidate:10,
}
}
```
## Examples
## Examples
-[**E-commerce Demo**](https://nextjs.org/commerce) – Next.js Commerce is an all-in-one starter kit for high-performance e-commerce sites.
-[**E-commerce Demo**](https://nextjs.org/commerce) – Next.js Commerce is an all-in-one starter kit for high-performance e-commerce sites.
@@ -8,7 +8,9 @@ SWC requires a binary be downloaded that is compatible specific to your system.
...
@@ -8,7 +8,9 @@ SWC requires a binary be downloaded that is compatible specific to your system.
#### Possible Ways to Fix It
#### Possible Ways to Fix It
You might need to allow optional packages to be installed by your package manager (remove `--no-optional` flag) for the package to download correctly.
When on an M1 Mac and switching from a Node.js version without M1 support e.g. v14 to a version with e.g. v16, you may need a different swc dependency which can require re-installing `node_modules` (`npm i --force` or `yarn install --force`).
Alternatively, you might need to allow optional packages to be installed by your package manager (remove `--no-optional` flag) for the package to download correctly.
If SWC continues to fail to load you can opt-out by disabling `swcMinify` in your `next.config.js` or by adding a `.babelrc` to your project with the following content:
If SWC continues to fail to load you can opt-out by disabling `swcMinify` in your `next.config.js` or by adding a `.babelrc` to your project with the following content:
thrownewTypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
thrownewTypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");