Unable to use preview mode on optimized production build.
Answered
Netherland Dwarf posted this in #help-forum
Netherland DwarfOP
I have a WordPress instance utilizing GQL plugins to expose an API for a corresponding Next.js app to consume.
I've followed the documentation on how to set that up and it works in dev mode. However, when I run a build and test that, the
Is there something I need to configure in order to maintain the preview mode behavior once built?
I've followed the documentation on how to set that up and it works in dev mode. However, when I run a build and test that, the
preview
flag and previewData
no longer come through. Is there something I need to configure in order to maintain the preview mode behavior once built?
Answered by Netherland Dwarf
It looks like the core of the issue I was finding was more of an intended behavior. That, if you run an optimized build, you will need to serve your requests over a secured connection (https) in order for the preview cookie/data to be set.
I ran through a lot of clean up items and couldn't find any other explanation despite my testing over https in the first place. So.. I guess that's the solution.
I ran through a lot of clean up items and couldn't find any other explanation despite my testing over https in the first place. So.. I guess that's the solution.
3 Replies
Netherland DwarfOP
Just an update on this. I've started a next.js app from scratch on next.js 14. Wrote a simple test to see if preview mode works in the optimized build, and it does.
This leads me to believe Next.js 12.0.7 (which I didn't think to bring up initially) has this as a bug.
Having difficulty upgrading packages... I'd like to avoid a full on migration to 14 but it's starting to sound like that'll be the next step for me.
Any suggestions appreciated.
This leads me to believe Next.js 12.0.7 (which I didn't think to bring up initially) has this as a bug.
Having difficulty upgrading packages... I'd like to avoid a full on migration to 14 but it's starting to sound like that'll be the next step for me.
Any suggestions appreciated.
Netherland DwarfOP
Well, good news and bad news.
Good news: I've successfully updated to Next14. It was a bit tedious, but overall fairly smooth. Speed improvements are nice!
Bad news: The preview mode issue is still in place. Which nullifies the hypothesis that it was a bug in Next 12. This is a codebase I inherited, so it's not clear how to fix it but at least I know it's likely something the original developer did.
Will update when I find a solution.
Good news: I've successfully updated to Next14. It was a bit tedious, but overall fairly smooth. Speed improvements are nice!
Bad news: The preview mode issue is still in place. Which nullifies the hypothesis that it was a bug in Next 12. This is a codebase I inherited, so it's not clear how to fix it but at least I know it's likely something the original developer did.
Will update when I find a solution.
Netherland DwarfOP
It looks like the core of the issue I was finding was more of an intended behavior. That, if you run an optimized build, you will need to serve your requests over a secured connection (https) in order for the preview cookie/data to be set.
I ran through a lot of clean up items and couldn't find any other explanation despite my testing over https in the first place. So.. I guess that's the solution.
I ran through a lot of clean up items and couldn't find any other explanation despite my testing over https in the first place. So.. I guess that's the solution.
Answer