aws-amplify / aws-amplify/amplify-hosting

Next.js dynamic routes under a rewrite fail to regenerate via ISR

Open
#2,542 2 comments 0 reactions 0 assignees View on GitHub
bug ssr
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-console/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-console/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-console/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### App Id

dgpf8z9zdyr4o

### Region

ca-central-1

### Amplify Console feature

Build settings

### Describe the bug

Next.js [dynamic routes](https://nextjs.org/docs/routing/dynamic-routes) that are accessed via a [rewrite](https://nextjs.org/docs/api-reference/next.config.js/rewrites) fail to trigger ISR regeneration. In my app I have multiple dynamic routes that aren't accessed via a rewrite and they trigger ISR successfully. I also have non-dynamic routes that are not accessed via a rewrite and they also trigger ISR normally. Only dynamic routes that are accessed by a rewrite fail to trigger ISR, so content stays stale on those routes until a new build is ran.

### Expected behavior

Dynamic routes should trigger ISR if accessed via a rewrite. This has been tested to work properly locally.

### Reproduction steps

1. Create a Next.js app
2. Add a dynamic route (e.g. /test/[id].js) with getStaticPaths/getStaticProps calls configured for ISR
3. Add a rewrite (e.g. /rewrite/:id -> /test/:id)
4. Try to trigger ISR on the dynamic route

### Build Settings

```yaml
version: 1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- nvm use
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction using the dynamic route /test/[id].js, getStaticPaths/getStaticProps configured for ISR, and the rewrite in next.config.js. Compare regeneration through the rewrite with direct access to the dynamic route; done means rewritten routes regenerate without requiring a new build.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
cloud, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.