-
Notifications
You must be signed in to change notification settings - Fork 34
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
ISR does not work in in presentation mode #998
Comments
@LKosters have you figured out a way to get presentation mode working? I have my site hosted on Vercel and I have not been able to get Sanity to connect. I get the same error messages. I tried setting |
@lwaldner I cannot get it to work either, for now I just turn of ISR but I would rather have it on for performance. |
I can confirm this issue. The presentation mode seems to break as soon as you add any, even just a single, As a temporary solution I deploy a |
@LKosters @marco-land I'm getting this error without any route rules, would you guys mind sharing how you set this up? |
My export default defineNuxtConfig({
// ...
ssr: true,
sanity: {
projectId: process.env.NUXT_SANITY_PROJECT_ID,
dataset: process.env.NUXT_SANITY_DATASET,
useCdn: false,
apiVersion: process.env.NUXT_SANITY_API_VERSION || "2024-03-15",
visualEditing: {
studioUrl: process.env.NUXT_SANITY_STUDIO_URL || "http://localhost:3333",
token: process.env.NUXT_SANITY_TOKEN,
stega: true,
},
},
}) my export default defineNuxtConfig({
// ...
ssr: true,
sanity: {
projectId: process.env.NUXT_SANITY_PROJECT_ID,
dataset: process.env.NUXT_SANITY_DATASET,
useCdn: false,
apiVersion: process.env.NUXT_SANITY_API_VERSION || "2024-03-15",
},
nitro: {
prerender: {
crawlLinks: true,
},
},
routeRules: {
"/**": { prerender: true },
},
}) my export default defineConfig({
// ...
plugins: [
// ...
presentationTool({
previewUrl: {
// make sure that the origin is the the `preview` branch URL
origin: process.env.SANITY_STUDIO_PREVIEW_URL || 'http://localhost:3000',
previewMode: {
enable: '/preview/enable',
disable: '/preview/disable',
},
},
}),
]
}); I hope this helps, in this case I was using |
I've done some testing of this today. I'm unable to replicate any "Unable to connect to visual editing" issues when ISR is enabled, everything does work as expected for me with one major caveat: Currently there is no cache separation for routes dependent on if they are rendered in preview or non-preview mode. As far as I'm aware this means that preview pages do get cached when using ISR, and those cached pages are potentially served/leaked to users who do not have preview mode enabled. I'm not aware of a method to set cache keys to differentiate preview rendered pages, so for now I'd recommend @marco-land's approach until we can work this one out. Thanks for raising and for your patience. |
I tested this out. Unfortunately @marco-land's approach does not work in all cases. For instance, Vercel (one of the bigger platforms) automatically adds a password protection on the non-production branches. I also noticed that end users have trouble understanding the different URL's and that keeping two branches with the same code base (but different configuration) is possible, but far from ideal (it requires more complex pipelines to ensure that code pushed to a I think this issue has a big impact on possible integrations of Sanity with Nuxt: all possible work-arounds are not working in a real case scenario. One must make a decision between:
All in all, there is no optimal, developer friendly way to use Sanity with preview mode with Nuxt. Would be great to get some guidance here from @rdunk (sanity) or @danielroe (nuxt), on how to get this in. I am more than OK with spending time to also help to get this working, but would be great to see/discuss what the integration method/starting point of this should be. @danielroe any suggestions? |
Version
module: 1.10.1
nuxt: 3.9.3
Nuxt configuration
routeRules: { "/**": { isr: 3600, cors: true, }, "/preview/**": { isr: false, cors: true, }, },
Additional information
An alternative idea would be to turn off the ISR feature, however this would lead to a degraded page performance.
Checklist
Steps to reproduce
Clone nuxt sanity repo with the movie example, set ISR to 3600 (other values will also work), build it to a live environment (I use Vercel to host my live envoirment) and use that url in presentation mode from studio.
What is expected?
I can edit my file in presentation mode while ISR is turned on.
What is actually happening?
I get the following error in presentation mode:
"Unable to connect, check the browser console for more information."
Error in browser console:
"Unable to connect to visual editing. Make sure you've setup '@sanity/visual-editing' correctly"
The text was updated successfully, but these errors were encountered: