I have difficulties getting the share link feature to work. As far as we can remember, it used to work for a while. As this is a ongoing live site, we constantly upgrading the system and are using Nuxt.js "^2.15.3" and the corresponding @nuxtjs/prismic package "^1.3.2" right now.
If i open up the generated share link in inkognito browser tab (Chrome 96) it seams like the cookie "io.prismic.previewSession" is set with the correct prismic repro as a domain and a share id as a value. This looks ok so far. If i do a curl -L on the preview link, i see the page that should set this cookie and redirect to the previewing page like so:
function setCookie(name, value, days) {
var d = new Date;
d.setTime(d.getTime() + 24 * 60 * 60 * 1000 * days);
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString() + ";SameSite=None" + ";Secure";
}
setCookie("io.prismic.previewSession", " [ID HIDDEN ]", 1);
window.location = "http://localhost:3000/berlin";
I'm kind of curious how this should otherwise work with e.g. a static build.
Please let me know, how i can further debug this issue and get it to work, since our client is relying on this workflow. I'm happy to provide you the prismic repro and access to the nuxt project on demand via DM.
You need to make sure your client's machine has the localhost server running to see a http://localhost:3000/preview URL. Otherwise, it’s going to throw an error. Local host servers are meant for testing the site in a local environment.
We tried and reproduced the issue with a Nuxt site deployed to Netlify using “@nuxtjs/prismic”: “^1.3.2" and “nuxt”: “^2.15.3". We were able to run the shareable link without any issues with the latest version of Chrome. I recommend you suggest that your team update their versions of Chrome to be able to use these links
The tested Chrome version was the most recent Chrome 96 (Release date 2021-11-15)
As i pointed out, the page that is reached when navigating to a share link redirects to window.location = "http://localhost:3000/berlin"; as /berlin is the page that should be previewed.
So /preview is not called when the user navigated to the share link. As i would assume, this cannot work. How would the @nuxt/prismic package know, how to fetch the preview?
This is out of my control. Could you please explain how to proceed, and check if this might be a migration issue on prismic repository side?
Would be happy to provide repository name via DM.
Thank you for your effort
Florian
Shared previews redirect to the previewed page because they already know its location which is retrieved upon shared preview link creation (when clicking the "share preview" button on the toolbar)
The sole reason "regular" previews are redirecting first to /preview is because Prismic's doesn't know yet the location of the previewed page (which /preview is responsible for computing)
So basically the whole flow looks like this:
You create a preview session on Prismic
You're redirected to /preview
/preview gets the document ID and token (which is actually a ref) through query parameters which allow the previewed page's location to be computed
Once the previewed page's location is computed, you're redirected to it
Once on the previewed page, the toolbar kicks in
The toolbar performs a ping pong to Prismic, actually retrieving the preview session and setting it in the browser's cookies
Because the preview session is then set inside the browser's cookies, @prismicio/client is then able to query previewed (unpublished) content
Regular preview is working
Then, if you want to share that preview, you open the toolbar
Then you click "share preview"
When you do so, your location and a screenshot of the page is sent to prismic.io
prismic.io creates the shared preview using that information
Once created it sends you back the shared preview link which is now available for you to copy and share
When another user clicks the shared preview link you sent them, they are redirected to prismic.io
prismic.io sets the cookie through the snippet the user found with curl -L
prismic.io then redirects the user to the location it had registered
Once on the location, the toolbar kick's in again
It does its ping pong again with Prismic, retrieving the preview session and setting it in the browser's cookie
And then @prismicio/client is able to query previewed (unpublished) content from the shared preview
So for your issue, we're not sure what's going on. Have you made any attempts to change the @nuxtjs/prismic standard behaviour?
Can create a minimal reproduction and share it with us?
Hello team. We close the threads after a week with no new activity. If this happens and you want to continue the conversation, you can easily flag it to reopen it and add a new comment.
Thanks.