AI • Science • Technology • Future

Side Projects

I Built a Local-First Markdown Editor: How It Stays Fast on Huge Docs

Image from the original article
Featured image: original publisher image. Via original publisher.

Harshit Duggal built a local-first markdown editor to solve a personal frustration: losing time to editors that require login before allowing basic writing. Source: dev.to.

What Is Flow?

Flow is a browser-based markdown editor that runs entirely in your device’s browser. No account, no sign-up, no server storage. Your documents stay in IndexedDB on your machine.

The editor is available at https://markdown-editor.opalhq.fun/ and its source code is open at https://github.com/duggal1/markdown-editor.

Why Local-First?

Duggal built Flow because he often writes drafts he doesn’t want to share. Many editors require login or account creation before allowing a user to type a heading. Local-first design turns privacy into a core feature—your notes exist only on your device.

As he notes, the tradeoff is clear: local-first is not a backup. If you clear browser data, your files are gone. There is no syncing, no version history, and no recovery from accidental deletion.

Key Engineering Decisions

  • Virtualized preview and search: The preview and code pane use TanStack Virtual to render only visible rows. Updates are deferred and processed in chunks. This prevents DOM bloat in large files.
  • Search and word count in a web worker: These operations run in a background thread. This keeps the editor responsive even when scanning large documents.
  • GitHub-flavored markdown: The editor uses CodeMirror 6, a well-tested library, rather than building a custom markdown engine. This saved months of development time.

Security in Preview Mode

Markdown supports raw HTML, which can be a security risk. Flow sanitizes inline HTML and renders standalone HTML files in a sandboxed iframe with a strict content security policy.

SVG previews are rendered without script permissions. This ensures that no code can run against the main editor interface, even when users drop in files with embedded SVGs.

Regarding the iframe sandbox, Duggal confirmed that the allow-same-origin directive was dropped. This prevents any scripts in the preview from accessing the editor’s storage or DOM, reinforcing the separation between preview content and editing context.

Image from the original article
original publisher image. Via original publisher. · Source

Annotation and Export Features

The /draw mode allows users to annotate screenshots. Coordinates are stored relative to the image, so annotations remain stable when the image is resized.

Export options include JPEG, WebP, or a ZIP file containing all content. Duggal wrote a lightweight, dependency-free ZIP writer and ran it in a web worker. No compression is used—this is sufficient for screenshots and keeps the tool small.

Writes to IndexedDB are debounced. A bounded copy of data is stored in localStorage to recover from interrupted saves. PDF export is also available.

Limitations and Open Questions

Flow has no sync or version history. Your documents are not backed up or shared. Clearing browser data deletes them entirely.

One concern with IndexedDB is that browsers may evict it under storage pressure. Duggal notes that calling navigator.storage.persist() may help, and offers a one-click export option as a potential solution for long-term users.

Users may still face challenges when opening very large markdown files. While the virtualization and web worker architecture help, performance can degrade if the file exceeds certain size thresholds. Duggal has not yet implemented a file size limit or a warning system for such cases.

What to Watch Next

As local-first tools grow, users may demand more robust backup and recovery features. The balance between privacy and data persistence will remain a key design challenge.

For readers interested in tools that never upload your files, see Browser Tools That Never Upload Your Files. For a similar self-contained app, explore Cobra Music Studio.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source