-
Notifications
You must be signed in to change notification settings - Fork 67
Redirect for preview mode #10
Comments
Hey @nikshenoy, I've been digging into this issue and there are two parts to the answer:
Sorry about that :| If you want, I'd be happy to help brainstorm alternative approaches to your situation! — Finn |
@calavera from Netlify just responded to an issue I filed with Netlify regarding
Perhaps that means they will also look into adding support for setting multiple cookies on the same function response. If not, we could think about a workaround. For example: Before the response is sent out, we could check for the presence of the two NextJS cookies and, if they exist, encode both into a single cookie called Let me know if this is something that you're interested in. I would love to hear more about your use case, as well, to make sure I'm not missing anything. |
Hey @FinnWoelm, thanks so much for the quick (and thorough response). The multiValueHeaders fix sounds good. I think that will solve the problem (especially if Netlify fixes it, which is unclear given how long the original issue was open). I guess you're correct that we can call Next.js's cookie setter, re-encode those cookies, and then decode them on the next-on-netlify side of that function. I'm willing to give that a shot as a workaround. Is the best way to have a generic header for this, like: Set-Cookie-Compressed so it doesn't conflict with the standard one? Then your code can just check that, decode it and add it to the normal cookies? |
Hey @nikshenoy, I just released You'll need to make some changes to your # netlify.toml
[build]
command = "npm run build"
functions = "out_functions"
publish = "out_publish"
[dev]
functions = "out_functions"
publish = "out_publish"
framework = "#static" And you will want to adjust your # .gitignore
# Files generated by next-on-netlify command
/out_publish/
/out_functions/
/404.html Regarding the cookies work-around: I would actually implement this completely within Before I do that, I want to make sure this would actually be helpful for your use case, though. For example, it's not possible to do cookie-based redirects with Netlify (at the moment; see this thread for ongoing work). So if you have certain paths pre-rendered as HTML, your redirects will still point to the pre-rendered pages, even if preview mode is turned on. Preview mode will only affect pages that are SSR-ed, so any pages with Does that make sense? What do you think? Does that cover your use case? |
If you can implement it within the library, that sounds like a good solution. I see what you mean with regards to pages that are static rendered. I have two comments:
|
Hey @nikshenoy, That sounds like a good use case! I'll try to turn it around this weekend :) Regarding the use of I'll keep you posted on the cookie encoding/decoding! |
Hey @nikshenoy, I've got very exciting news: From what I can tell, Netlify just implemented support for I'm trying to find out right now if the support for Anyway, this is super exciting 🔥 and I'll let you know as soon as I hear something from Netlify! Happy Sunday, |
That sounds great. And you're right about the magic of cookies for preview mode. I keep forgetting that it keeps that mode on as you're navigating. Thanks for the update! |
Hi @FinnWoelm Any news about adding multiValueHeaders ? Anything I can help with? |
Hey @scopsy, thanks for following up on this! Good news: I actually finished writing the code yesterday 😁 I just did not have time to push and release. Doing that right now; give me ~15 minutes :) |
You are awesome! 😍 |
- Add support for [NextJS Preview Mode]( https://nextjs.org/docs/advanced-features/preview-mode) ([#10](#10)) Note: NextJS Preview Mode does not work on pages that are pre-rendered (pages with `getStaticProps`). Netlify currently does not support cookie-based redirects, which are needed for supporting preview mode on pre-rendered pages. Preview mode works correctly on any server-side-rendered pages (pages with `getInitialProps` or `getServerSideProps`). - Use `multiValueHeaders` in Netlify Functions for incoming requests and for outgoing responses. This offers many benefits over plain `headers`, such as setting multiple cookies within one response.
Alright, we are live!! 🎉 😊 Let me know if you run into any issues :) PS: @scopsy, I saw your issue regarding redirects! I will look into it this weekend and see what we can do 🙃 |
Previous issue appears to be fixed now: netlify#10
The Next.js samples for preview mode involve doing a redirection from an api route. The code is something like:
I can do this from
next run
, but if I try this on Netlify it seems to strip the location header on the 307 redirect. Is this something to do with thecompat
call or am I doing something wrong?The text was updated successfully, but these errors were encountered: