How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

How to show custom preview as default view when opening document from search results?

3 repliesLast updated: Nov 29, 2025

Hello you clever people. Got a bit of a conundrum here. I have created a custom preview component for my main doc type, and managed to have this preview show up as the default view, so when I select a word in the menu I see the nicely formatted preview, as in fig 1. However if I use the search bar and find a word (as illustrated in fig 2) and select it by clicking or hitting enter I get this different view showing the form, and with the links to the view options (Display, Editor) removed. How can I make the document show in the custom preview in this "searched result"-view?
AI Update

I understand your frustration! This is a known behavior in Sanity Studio where the global search and Structure tool navigation work somewhat independently. When you navigate through the Structure tool's menu, your custom defaultDocumentNode configuration is applied correctly, but when you use the global search, Studio can sometimes open documents in a default view that bypasses your custom configuration.

The Solution:

The good news is that your defaultDocumentNode configuration in the structureTool() plugin should apply to all document opens, including those from search results. Based on the Structure Builder documentation, here's how to ensure it works properly:

Make sure your defaultDocumentNode is configured at the plugin level in your sanity.config.ts:

// sanity.config.ts
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'

export default defineConfig({
  // ... other config
  plugins: [
    structureTool({
      defaultDocumentNode: (S, {schemaType}) => {
        // Apply your custom preview to your document type
        if (schemaType === 'word') { // or whatever your doc type is called
          return S.document().views([
            S.view.component(YourCustomPreview).title('Display'),
            S.view.form().title('Editor')
          ])
        }
        return S.document()
      },
      structure: (S) => {
        // your structure configuration
      }
    })
  ]
})

Key points to fix your issue:

The defaultDocumentNode at the plugin level should apply universally to all document opens, whether from the structure navigation or global search. If you're still experiencing issues after confirming this setup, it might be worth checking if there are any Studio version-specific quirks or reaching out to the Sanity community with your specific Studio version and configuration.

Show original thread
3 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions