# Shared Sections

> Keep one section, such as a header, footer or entry pop-up, in sync across many pages

Canonical URL: https://0.0.0.0:3005/guides/shared-sections

A **shared section** is one section source that is linked into many pages.
Edit it once, then sync it, and every linked page gets the same change.

Typical shared sections:

- The store header and footer
- An entry pop-up or announcement bar
- A shipping or guarantee strip that appears on every landing page

## How it works

A shared section stores three things:

| Field | Meaning |
|---|---|
| `section_id` | The section id it uses on every page, for example `header` |
| `source` | The source-format HTML for exactly that one section |
| `revision` | A counter. Every change to `source` adds one |

Each linked page records the revision it last received. When the shared
section moves ahead of a page, that page is **stale**.

Editing a shared section never touches pages by itself. Pages change only when
you **sync**:

```text
1. Create   turn a section on a page into a shared section (revision 1)
2. Update   edit its source or patch it (revision 2, linked pages go stale)
3. Sync     write the current revision into pages as new draft versions
4. Publish  publish each live page that you want to update
```

Sync always creates a new **draft** version. A page that is already live keeps
serving the old copy until you publish it.

## Shared sections in the MCP

Reads go through `lexsis_pages`. Writes go through `lexsis_drafts`, so they
are reversible and never publish.

| Router | Action | What it does |
|---|---|---|
| `lexsis_pages` | `shared_sections` | List shared sections (without source) |
| `lexsis_pages` | `shared_section` | Get one: source, revision and linked pages with `stale` flags |
| `lexsis_drafts` | `shared_section_create` | Share a section that already exists on a page |
| `lexsis_drafts` | `shared_section_update` | Replace the source or rename it |
| `lexsis_drafts` | `shared_section_patch` | Edit part of the source without resending it |
| `lexsis_drafts` | `shared_section_sync` | Write the current revision into pages |
| `lexsis_drafts` | `shared_section_detach` | Unlink one page; it keeps a local copy |

When a connection has several workspaces, pass `workspace_id`.

### Create

Build the section on one page first, then share it. The page must be
source-backed. The source page is linked at revision 1.

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "shared_section_create",
    "args": {
      "page_id": "<page with the section>",
      "section_id": "entry-popup",
      "name": "Entry pop-up"
    }
  }
}
```

### Add it to more pages

Pass `page_ids` to `shared_section_sync`. Pages that do not have the section
yet get it appended, or placed at `position: "first"`.

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "shared_section_sync",
    "args": {
      "shared_section_id": "<id>",
      "page_ids": ["<page A>", "<page B>"],
      "position": "last"
    }
  }
}
```

Pages that are already linked keep the section where it is.

### Edit

Use `shared_section_patch` for small changes. It accepts the same operations
as page edits:

- `update_island_props`: deep-merge into an island's props
- `remove_island_props`: remove prop paths
- `replace_text`: replace a snippet that occurs exactly once

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "shared_section_patch",
    "args": {
      "shared_section_id": "<id>",
      "expected_revision": 3,
      "changes": [
        { "operation": "replace_text", "old_str": "Free shipping over $50", "new_str": "Free shipping over $40" }
      ]
    }
  }
}
```

Use `shared_section_update` with a full `source` to rewrite it.

Both actions compile and validate the new source before saving. If it fails,
the revision is not saved and you get `validation_errors`. Pass
`expected_revision` to avoid overwriting someone else's edit; a mismatch
returns a revision conflict.

### Sync

Call `shared_section_sync` without `page_ids` to refresh every stale linked
page:

```json
{
  "name": "lexsis_drafts",
  "arguments": {
    "action": "shared_section_sync",
    "args": { "shared_section_id": "<id>" }
  }
}
```

The result lists each page as `synced` (with the new version and preview URL),
`skipped` or `failed`. Then verify the previews and publish the live pages with
`lexsis_live_ops` after approval.

### Detach

`shared_section_detach` unlinks one page. The page keeps its current copy of
the section as a normal local section, and future syncs skip it.

## Headers and footers on new pages

`lexsis_brand` page context returns the store's shared sections under
`shared_sections`, so an agent knows which header and footer exist before it
plans a page.

To include them in a new page, pass their ids to `lexsis_build` `commit` when
creating:

```json
{
  "name": "lexsis_build",
  "arguments": {
    "action": "commit",
    "args": {
      "create": { "slug": "summer-sale", "theme_id": "<theme>" },
      "shared_sections": ["<header id>", "<footer id>"],
      "files": { "sections/hero.html": "..." }
    }
  }
}
```

Each one is added as `sections/<section_id>.html` and linked at its current
revision, so no extra sync is needed. If `lexsis.json` does not place them, the
first goes at the top and the rest go at the bottom. You can pass up to 10.

`shared_sections` works only when creating a page. With the
[Lexsis CLI](/tools/build#lexsis-cli), use `lexsis new <dir> --shared id,id`.

## Rules and limits

- **Running experiments are protected.** Sync skips any page that is an arm in
  a running experiment, so a test is never changed mid-run.
- **Validate on the shared section, not the page.** Anchor links that point to
  ids on the host page are not checked when the shared section is saved.
- **Deleting a shared section** keeps every page's current copy. Only the link
  to future edits goes away.
- **Edit the shared section, not the page copy.** A local edit to a linked
  section is overwritten on the next sync. Detach the page first if it needs
  its own version.
- Sync handles up to 100 pages per call.
