Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mikeh2 opened this issue Jan 2, 2020 · 5 comments · Fixed by #9907
Closed

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

mikeh2 opened this issue Jan 2, 2020 · 5 comments · Fixed by #9907
Milestone

Comments

@mikeh2
Copy link

mikeh2 commented Jan 2, 2020

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]
@mikeh2
Copy link
Author

mikeh2 commented Jan 3, 2020

Thanks for the swift response. Is there an estimate with 9.2 will be available ?

@Timer
Copy link
Member

Timer commented Jan 3, 2020

I've released it on 9.1.8-canary.0 for you, which will become 9.2 in the next few days.

@mikeh2
Copy link
Author

mikeh2 commented Jan 3, 2020

Thanks. I can confirm that getInitialProps is no longer called. However, for dynamic pages (statically exported), the component is rendered, re-mounted and rendered again. A 'regular' page component is only rendered once. Is this an issue or just part of the life cycle of a dynamic page ?

@Timer
Copy link
Member

Timer commented Jan 3, 2020

It's just part of the life cycle right now, as the page is letting you know the router has provided any user-input if present.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants