> For the complete Lynkow documentation index in agent-friendly format, see [llms.txt](/llms.txt).

# Visual Editor

**Published**: 2026-11-30
**Category**: Advanced

> Let editors click a heading on your live site and change it from the Lynkow dashboard. The dashboard opens your site in an iframe, and `@lynkow/next` connects the two through `postMessage`.

> **Reference** - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
> 
> - SDK: [Lynkow SDK](/sdk)

## Prerequisites

- A Next.js App Router site using `lynkow` and `@lynkow/next` ([Add Lynkow to an Existing Project](/sdk/getting-started/existing-project)).
- A page or global block in Lynkow whose fields you render ([Pages & Site Configuration](/sdk/features/pages-site-config)).
- Your site served over HTTPS, also in development.

## Step 1: Let the dashboard frame your site

The dashboard runs on `https://app.lynkow.com` and loads your page with a `lynkow-preview` query parameter. On those requests your site must send `Content-Security-Policy: frame-ancestors 'self' https://app.lynkow.com` and no `X-Frame-Options` header.

If your `proxy.ts` uses `createLynkowProxy()` ([Multi-language](/sdk/features/i18n)), it already does this. Otherwise, use the preview helper:

```typescript
// proxy.ts
import { lynkowPreviewMiddleware } from '@lynkow/next/proxy'

export default lynkowPreviewMiddleware()

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)'],
}
```

To keep a proxy you already have, wrap it: `export default withLynkowPreview(yourProxy)`. Your own `Content-Security-Policy` is kept. On a preview request its `frame-ancestors` is replaced to allow the dashboard and `X-Frame-Options` is removed. On other requests your `frame-ancestors` stays, or `frame-ancestors 'self'` is added when you set none.

Without a proxy, set the header in `next.config.ts` and import the origin rather than typing it:

```typescript
// next.config.ts
import type { NextConfig } from 'next'
import { DEFAULT_CMS_ORIGIN } from 'lynkow/visual-editor'

const nextConfig: NextConfig = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [{ key: 'Content-Security-Policy', value: `frame-ancestors 'self' ${DEFAULT_CMS_ORIGIN}` }],
      },
    ]
  },
}

export default nextConfig
```

Also remove any `X-Frame-Options` header your host or reverse proxy adds: some browsers let it override `frame-ancestors`.

## Step 2: Mount the provider

```tsx
// app/layout.tsx
import type { ReactNode } from 'react'
import { LynkowVisualEditor } from '@lynkow/next/client'

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        <LynkowVisualEditor>{children}</LynkowVisualEditor>
      </body>
    </html>
  )
}
```

The provider adds no element. It starts only when the page is inside an iframe and its URL carries `lynkow-preview`. Otherwise it registers no listener and scans nothing. Once started, it scans the page, sends the dashboard a `lynkow:handshake` message listing the blocks and fields it found, and accepts messages from `https://app.lynkow.com` only.

Pass no props. `cmsOrigin` exists only to develop against a dashboard other than production. If you set it, pass the same value to `lynkowPreviewMiddleware({ cmsOrigin })` or `withLynkowPreview(yourProxy, { cmsOrigin })`. An empty string disables the editor and logs `[Lynkow] cmsOrigin was passed as an empty value. Omit it to use the default.`

## Step 3: Mark the editable fields

Wrap the markup of a block in `<EditableBlock>` and each field in `<Editable>`. Both render from Server Components:

```tsx
// app/page.tsx
import { EditableBlock, Editable } from '@lynkow/next/client'
import { lynkow } from '@/lib/lynkow'

export default async function HomePage() {
  const page = await lynkow.pages.getBySlug('home')
  const { title, intro } = page.data as { title: string; intro: string }

  return (
    <EditableBlock slug="home" as="main">
      <Editable field="title" label="Title" as="h1">{title}</Editable>
      <Editable field="intro" label="Introduction" type="richtext" as="div" html={intro} />
    </EditableBlock>
  )
}
```

- `slug` is the slug of the page or global block, exactly as in Lynkow. `as` sets the element, so no extra wrapper is added.
- `field` is the key in the block's schema. Pass the text as `children`, or a richtext value as `html`.
- `type` defaults to `'text'`, which the editor edits inline on the page. The other types (`richtext`, `url`, `image`, `number`, `date`, `select`, `boolean`) open the field in the dashboard panel.
- Outside the editor, each field renders the value you passed. Inside it, the field shows what the editor types, without a reload.

Rules the editor's scanner applies:

- A field is found only inside the element of its block. `<Editable>` without an `<EditableBlock>` ancestor logs an error in development.
- The page is scanned once, when the editor starts. A field not in the DOM then (an empty section you hide) can still be edited from the dashboard's field list.
- Only flat keys can be marked. Repeater rows (a list of links, a feature grid) stay editable from the dashboard. Do not mark their container: inline editing would flatten the list to text.
- A marked field that the block's schema does not declare is ignored.

### Raw attributes

`<Editable>` renders four `data-` attributes, which you can write yourself when a component does not fit, for an `<img>` for example:

| Attribute | On | Value |
| --- | --- | --- |
| `data-lynkow-block` | the block's element | the block slug |
| `data-lynkow-field` | a descendant of it | the field key |
| `data-lynkow-type` | the field | the field type, `text` when absent |
| `data-lynkow-label` | the field | the badge label, the key when absent |


## Step 4: Read live values with hooks

Hooks from `@lynkow/next/client` return the editor's live value inside the editor and your initial value everywhere else. Call them in a Client Component rendered inside the block:

```tsx
'use client'

import { useLynkowField } from '@lynkow/next/client'

export function Logo({ src }: { src: string }) {
  const url = useLynkowField('home', 'logo', src)
  return <img src={url} alt="" data-lynkow-field="logo" data-lynkow-type="image" data-lynkow-label="Logo" />
}
```

- `useLynkowField(blockSlug, fieldKey, initialValue)` returns one field.
- `useBlockData(blockSlug, initialData)` returns the whole block, with the editor's values merged over `initialData`. Use it for a repeater you render yourself.
- `useIsPreviewMode()` returns `true` inside the editor, for example to hide a cookie banner while editing.

## Step 5: Set the Preview URL

1. In the dashboard, go to **Settings > General > Branding**.
2. Set **Preview URL** to your site's address, for example `https://www.example.com`. It must use HTTPS. When it is empty, the dashboard uses `https://` plus the site's domain.
3. Open a page under **Pages** and click **Visual editor**.

The dashboard loads the Preview URL plus the page's path, with `?lynkow-preview=true`. In development, expose your dev server through an HTTPS tunnel such as `ngrok http 3000` and set its URL as the Preview URL: browsers block an `http://` page inside the HTTPS dashboard.

## Troubleshooting

When no handshake arrives within 5 seconds, the dashboard shows **Visual Editor SDK not detected**. Check, in order:

| Symptom | Cause and fix |
| --- | --- |
| Blank iframe, no error | The Preview URL uses `http://`. Use HTTPS or a tunnel. |
| Blank iframe, console shows `Refused to display ... frame-ancestors` | The CSP does not allow `https://app.lynkow.com`, or an `X-Frame-Options` header remains. Check with `curl -I "https://your-site.com/?lynkow-preview=true"`. |
| Page loads, no handshake | `<LynkowVisualEditor>` is not in the root layout, or `cmsOrigin` is set to anything other than the exact dashboard origin (no trailing slash, `https`). Remove the prop. |
| Overlay appears, nothing is editable | No `data-lynkow-field` inside a `data-lynkow-block`, or the block slug does not match Lynkow. In the iframe console: `document.querySelectorAll('[data-lynkow-block] [data-lynkow-field]').length`. |
| **Preview URL not configured** | Set **Preview URL**, or the site's domain, in **Settings > General > Branding**. |


To read the iframe's console in Chrome, right-click the iframe and choose **Inspect**.

## Next Steps

- [Draft Preview](/sdk/advanced/draft-preview) - render unpublished content on your site.
- [Pages & Site Configuration](/sdk/features/pages-site-config) - read pages and global blocks.