-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Description
Bug report
For a static export, dynamic pages have an issue where the component is rendered, then re-mounted, getInitialProps called, and re-rendered. This causes a problem if getInitialProps attempts to do server side things (e.g. read from file system).
Describe the bug
next.config.js has an exported Path Map (e.g ...
{ '/weekly/1': { page: '/weekly/[id]', query: { id: 1 } },
'/weekly/2': { page: '/weekly/[id]', query: { id: 2 } },
'/schedule': { page: '/schedule' }
}
For the Dynamic Pages (e.g. /weekly/[id] ) the page is rendered fine but then the component is re-mounted and getInitialProps is called again. This behavior doe NOT exist for the static pages (e.g /schedule)
To Reproduce
- build a simple nextjs app using a static page (like /schedule above) and a dynamic page (like weekly/[id].js above)
- inside next.config.js export a path map for the pages
- add simple logging statements to both components inside the render/mount/getInitialProps
- npm run build; npm run export; cd dist; serve -p 3000
- browse the two pages
- see the console window
Expected behavior
the dynamic page component with the properly exported path map should behave the same as the simple component w.r.t getInitialProps NOT being called in the client.
Also, these pages are NOT navigated via Link component.
Screenshots
console of the dynamic component being served on a single request

System information
- Next.js: [9.1.6]