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

Have an option of exposing __NEXT_DATA during static export. #5903

Closed
rtm619 opened this issue Dec 17, 2018 · 4 comments
Closed

Have an option of exposing __NEXT_DATA during static export. #5903

rtm619 opened this issue Dec 17, 2018 · 4 comments

Comments

@rtm619
Copy link

rtm619 commented Dec 17, 2018

Feature request

Is your feature request related to a problem? Please describe.

One of the main reasons of creating a static build is that the website won't hit any data APIs and will run as a static website. While this can be possible by just having anchor tags instead of links, the disadvantage here is the handling of component states using state management tools like Redux or Mobx. If there is a way to save the data of getInitialProps as JSON, it would be extremely useful to bypass the data API call and still maintain the component state as a SPA.

Describe the solution you'd like

During export, have an option of exposing the data received from getInitialProps. Then, the user can use this prop data in his/her own way inside the page components. If someone wants to keep the API calls in pages, they can ignore the exposed data. I noticed that we can get the props data from the render.js file inside the dist/server folder. If we can expose that data in next.config via a function during export, it'd be great!

Describe alternatives you've considered

As of now, I don't see any other alternatives on this.

I think this feature would really improve Next and give the users a flexibility of developing their apps.

@timneutkens
Copy link
Member

Based on your description you can already do this. You can use preval to inline JSON into getInitialProps: https://github.com/zeit/next.js/blob/canary/examples/with-babel-macros/pages/index.js#L4

@EnMod
Copy link

EnMod commented Apr 9, 2019

Based on your description you can already do this. You can use preval to inline JSON into getInitialProps: https://github.com/zeit/next.js/blob/canary/examples/with-babel-macros/pages/index.js#L4

Thanks for providing that link, it was very helpful in showing how preval works. However, given that it doesn't show anything for getInitialProps, what would your recommendation for implementing inlining be, @timneutkens ?

@tylermcrobert
Copy link

tylermcrobert commented Aug 23, 2019

@timneutkens Are you able to elaborate? @EnMod Have you found a solution using an example provided above?

@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 31, 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

No branches or pull requests

5 participants