aws-amplify / aws-amplify/amplify-hosting

Statically generated dynamic pages in Nextjs are not served from cache

Open
#3,530 6 comments 0 reactions 1 assignee Claimed by @Jay2113 View on GitHub
bug compute investigating
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

### App Id

ds9myrwx73uix

### AWS Region

ap-southeast-2

### Amplify Hosting feature

Deployments, Frontend builds, SSR

### Describe the bug

I have a Nextjs v12.2 app deployed on Amplify with the `WEB_COMPUTE` platform. As part of this, I have some dynamic routes for which I am statically generating some paths using `getStaticPaths`.

In the Frontend build logs, these paths show up as successfully generated. However, when I try to access those paths, I get the fallback mode and it takes a while for the actual page data to come through. So basically these paths weren't really cached.

### Expected behavior

Paths that are statically generated at build time should be served from the Nextjs cache and I should get the rendered HTML on the first request instead of getting the fallback mode.

### Reproduction steps

Not sure how to describe reproduction, but here's how I get the bug:

- Make a dynamic path in the project, e.g. `pages/[...path].tsx`
- Add a `getStaticPaths` function and return some valid paths from it
- Build the application
- View the frontend build logs to note the paths that were statically generated
- Visit those paths

### Build Settings

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

I've checked the headers on a lot of pages including non-dynamic ones such as the homepage of my app, and it looks like none of these are hitting the nextjs cache either. I'm getting a constant `MISS` for the `x-nextjs-cache` header. The non-dynamic ones are instead coming from Cloudfront's cache.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.