DEV Community

Harshit Duggal
Harshit Duggal

Posted on

I built a local-first markdown editor. Here's what kept it fast on huge docs

Flow is a local-first markdown workspace that runs entirely in your browser. No account, no sign-up, no server holding your notes. You open it, write, and your docs stay in IndexedDB on your machine.

Live: https://markdown-editor.opalhq.fun/
Repo: https://github.com/duggal1/markdown-editor

I built it because I kept losing time to editors that asked for a login before I could type a heading, and because a lot of what I write is drafts I would rather not send anywhere. Local-first made that a property of the app instead of a line in a privacy policy.

Three engineering decisions did most of the work.

1. Virtualized preview, search in a web worker

Big docs are where most browser editors fall apart. The preview and the code pane are virtualized with TanStack Virtual, so only the rows in view are in the DOM. Updates are deferred and markdown is processed in chunks. Search and word count run in a web worker, so typing stays responsive while a large file is scanned. The editor is CodeMirror 6 with write, split and preview modes and GitHub-flavored markdown, not a homegrown engine. That saved me months.

2. Sandboxed HTML and SVG preview

Markdown allows raw HTML, which is a footgun. Inline HTML gets sanitized. A standalone HTML file renders in a sandboxed iframe with a strict content security policy. SVG preview has no script permissions. I can preview files you drop in without giving them a way to run code against the rest of the page.

3. The tiny ZIP writer behind /draw

/draw is a screenshot annotation mode. Coordinates are stored relative to the image, so annotations survive a resize. Export is JPEG, WebP, or a ZIP of everything. Instead of adding a zip library I wrote a dependency-free STORE zip writer and ran it in a worker. No compression, which is fine for screenshots, and it stayed small.

Saving is debounced IndexedDB writes with a bounded localStorage recovery copy for the case where a write dies mid-edit. PDF export is there too. The stack is React 19, TypeScript, Vite and CodeMirror 6. Built solo.

The honest tradeoff: local-first is not a backup. Your docs live in one browser's storage. Clear site data and they are gone. There is no sync and no versioned history yet. I would rather say that up front.

So, what is missing? If you open it with your largest markdown file, where does it break for you? What would you add first, and what would make you keep using an editor with no account?

Top comments (6)

Collapse
 
lycore profile image
Lycore Development •

Putting search and word count in a web worker is a nice win, since those are the first things to jank on a big file. One thing to watch with IndexedDB-only storage is that browsers can evict it under storage pressure unless you call navigator.storage.persist(), so it may be worth requesting that and offering a one-click export/backup for people with long-lived notes. For the sandboxed HTML preview, did you also drop allow-same-origin from the iframe sandbox so previewed scripts can't reach the editor's storage?

Collapse
 
harshitduggal profile image
Harshit Duggal •

persist() isn't requested yet, fair point. that's a real gap for long-lived notes, so it's going in along with a one-click export. on the sandbox: svg gets no script permissions and the html iframe runs under a strict csp, but i haven't confirmed allow-same-origin is off, so i'm going to check that and fix it if it isn't.

Collapse
 
wrobeltomasz profile image
Tomasz •

Hi Harshit, Is versioned history on the roadmap — snapshots in IndexedDB — or does the write-debounce design make that hard?

Collapse
 
harshitduggal profile image
Harshit Duggal •

not built yet, and the debounce doesn't get in the way, a snapshot is just another write. no date on it, it's the first thing i'd pick up if enough people say they want it.

Collapse
 
ibuildinpublic profile image
Ehsan •

Chunked markdown plus search in a worker is what I would have missed first. Have you measured how large a file gets before debounced IndexedDB writes start to hitch on their own?

Collapse
 
harshitduggal profile image
Harshit Duggal •

no numbers yet, and i'd rather say that than quote a size i haven't measured. the debounce means the write lands after typing stops, so a slow one shows up as a short pause instead of jank while typing. benchmarking writes on their own is on my list.