Skip to content

Static Exported Dynamic Page is re-mounted (getInitialProps called twice) #9902

@mikeh2

Description

@mikeh2

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

  1. build a simple nextjs app using a static page (like /schedule above) and a dynamic page (like weekly/[id].js above)
  2. inside next.config.js export a path map for the pages
  3. add simple logging statements to both components inside the render/mount/getInitialProps
  4. npm run build; npm run export; cd dist; serve -p 3000
  5. browse the two pages
  6. 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
Screen Shot 2020-01-01 at 8 06 21 PM

System information

  • Next.js: [9.1.6]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions