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

3 replies
Last updated: Jan 28, 2026
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:

  1. Order matters: If you want the preview to be the default view (the one that shows first), list it first in the views array. This ensures when documents open from search, they show your custom preview first.

  2. Plugin-level configuration: Ensure defaultDocumentNode is at the plugin level in structureTool(), not nested within specific structure items.

  3. Don't override in structure: If you're defining specific document nodes within your structure configuration for the same document type, those will take precedence over defaultDocumentNode. Make sure you're not inadvertently overriding it.

  4. Check for the view tabs: The tabs (Display, Editor) should appear for documents opened from search just as they do from navigation. If they're missing entirely, there might be a configuration conflict.

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

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.

Was this answer helpful?