Preview content on site in Sanity not working

Viewed 309

I'm following the Sanity docs on how to add a content preview. After updating the sanity.json and adding a resolveProductionUrl.js file according to docs I should be able to see a menu item in context menu:

enter image description here

But it's not happening. Interestingly enough If I add a console log to a resolveProductionUrl.js I can see it on the browser console - meaning that this function is getting called.

This is what I see:

enter image description here

1 Answers

I ran into a similar issue while following along using Sanity's Preview content on site article.

There were three things I had to do after following their article in order to get it to work:

  1. I had do add this line in sanity.json under plugins add highlighting to the line:
  "plugins": [
    ...
    "@sanity/production-preview"
  ],

(I didn't add this line to my sanity.json file on the first attempt. The article did not highlight that line, so looks like its just provided as context since the parts entry is highlighted.)

  1. I also had to update resolveProductionUrl.js to use document._id instead of document.slug.current as slug is undefined for me and it was throwing errors in the console (and not showing the menu item).

  2. I had to completely stop the site and re-run sanity start to get it to be picked up locally.

Related