sanity-io / sanity-plugin-iframe-pane

Display any URL in a View Pane, along with helpful buttons to copy the URL, display a mobile size, reload the iframe or open in a new tab
MIT License
47 stars 13 forks source link

Plugin no longer accepts doc url location #88

Closed rylanharper closed 1 year ago

rylanharper commented 1 year ago

Describe the bug

When upgrading to latest version of the plugin (v3.1.1), my doc url no longer respects the getPreviewUrl inputs (slug url). Here is my code:

import { Iframe } from 'sanity-plugin-iframe-pane'

// Show the correct URL based on the current document
function getPreviewUrl(doc) {
  return doc?.slug?.current
    ? `http://localhost:3000/projects/${doc.slug.current}`
    : `${window.location.host}`
}

// Import this into the deskTool() plugin
export const defaultDocumentNode = (S, {schemaType}) => {
  // Only show preview pane on `project` schema type documents
  switch (schemaType) {
    case `project`:
      return S.document().views([
        S.view.form(),
        S.view
          .component(Iframe)
          .title('Preview')
          .options({
            url: (doc) => getPreviewUrl(doc) + '?preview=true',
          })
          .title('Preview')
      ])
    default:
      return S.document().views([S.view.form()])
  }
}

This code returns the slug null3333?preview=true. When downgrading to v2.6.1, the slug is correctly rendered: http://localhost:3000/projects/my-project?preview=true.

The current solution is to downgrade plugin versions.

Expected behavior

The correct slug/url should display within the plugin config. Perhaps my code is incorrect? Seems odd since this is the same code structure I have used for the past year or more...

aleczratiu commented 1 year ago

The same issue is on my side as well.