slidevjs/slidev · error · Error

[Slidev] VDrag Element ${id} is not found in the markdown so

Error message

[Slidev] VDrag Element ${id} is not found in the markdown source

What it means

Thrown after Slidev attempted to substitute a v-drag element's position in the markdown but the regex found no matching <v-drag...> tag or v-drag attribute at the expected [startLine, endLine, idx] location. The stored source indices no longer align with the actual file content.

Source

Thrown at packages/client/composables/useDragElements.ts:97

              const posMatch = attrs.match(RE_POS_ATTR)
              if (!posMatch)
                return `<${tag}${ensureSuffix(' ', attrs)}pos="${posStr}"${selfClose}>`
              const start = posMatch.index
              const end = start + posMatch[0].length
              return `<${tag}${attrs.slice(0, start)}pos="${posStr}"${attrs.slice(end)}${selfClose}>`
            }
            return full
          })
        : section.replace(/(?<![</\w])v-drag(?:=".*?")?/gi, (full, index) => {
            if (index === idx) {
              replaced = true
              return `v-drag="${posStr}"`
            }
            return full
          })

      if (!replaced)
        throw new Error(`[Slidev] VDrag Element ${id} is not found in the markdown source`)

      lines.splice(
        startLine,
        endLine - startLine,
        section,
      )

      const newContent = lines.join('\n')
      if (info.value.content === newContent)
        return
      newPatch = {
        content: newContent,
      }
      info.value = {
        ...info.value,
        content: newContent,
      }
    }

View on GitHub (pinned to 0d798ace58)

Solutions

  1. Restart the dev server so source ranges are recomputed
  2. Switch the element to frontmatter storage with an id prop to avoid markdown rewriting
  3. Avoid editing the slide's v-drag block in your editor while dragging in the presenter

Example fix

// before
<v-drag pos="0,0,100,50" />
// after
<v-drag id="stable" />
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling the updater, sanity-check that the source range still contains a v-drag occurrence
const [s, e, idx] = markdownSource
const section = info.value.content.split('\n').slice(s, e).join('\n')
const occurrences = section.match(/<v-?[a-z-]*drag\w*|[?'']?v-drag/gi) ?? []
if (occurrences.length <= idx) throw new Error('stale source range; restart dev server')

Try / catch

try {
  updater(id, posStr, type, markdownSource)
} catch (e) {
  if (/not found in the markdown source/.test(String(e))) {
    // switch this element to frontmatter storage to avoid stale-index failures
    console.warn('Falling back to frontmatter drag storage for', id)
  } else throw e
}

Prevention

When it happens

Trigger: The markdown was edited (line shifts, element removed/renamed) while the presenter is open; HMR left stale source indices; the v-drag was moved into a different line range; or the element idx exceeds the number of v-drag occurrences in the section.

Common situations: Manually editing slides.md during a live session, copy-pasting v-drag blocks, or stale state after failed HMR.

Related errors


AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12). Data as JSON: /api/errors/95933e2b73a35617. Report an issue: GitHub.