Issue with Static Building Dynamic Pages using Styled Components (maybe React portals) #13694
Unanswered
danboyle8637
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Bug report
I am trying to build my site statically, but not using next-export. I have four dynamic pages that query data from Sanity.
I have followed the Sanity example and I have console logged my data from getStaticPaths and getStaticProps during the build and all of the data shows up in the console...
...AFTER... Next trying to do Automatic Optimization of Pages.
When Next is doing Automatic Optimization of Pages, all of my dynamic pages's props are undefined.
I have used both getStaticPaths and getStaticProps and in development it works and when consoling data to the terminal... the data is there.
Yes my dynamic page props remain undefined.
I read in the documentation if you use getInitialProps in _document.tsx you have to make sure ctx.req is defined. Yet I also found an unanswered issue where Tim said that this does not matter.
Styled Components requires a custom _document.tsx with getInitialProps.
I think this is the problem.
Or maybe because my static site is using Portals but I am not using @jesstelford/react-portal-universal.
But I don't want my portals indexed so I'm not sure if that matters.
From everything I've looked into, their seems to be an issue with styled components and statically building sites.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Example Component My Blog Post Dynamic Component
My Custom Document File
Notice where I placed my portal according to the example in Next's repo. The example that does NOT use SSR
The Errors I Am Seeing at Build Time Both Locally And On Vercel
Expected behavior
I expect the dynamic pages to be built successfully since they are getting the necessary data.
When things build in development, everything works fine.
I have double checked to make sure all slugs I use match up with what is in getStaticPaths and what is actually used in the site.
System information
Additional context
I think that covers everything and I will try to rebuild a portion of my site in CodeSandBox if needed.
Beta Was this translation helpful? Give feedback.
All reactions