---
title: "content.update()"
description: "Store an already-parsed file into the manifest and cache."
canonical_url: "https://content.comark.dev/reference/content/update"
---
# content.update()

> Store an already-parsed file into the manifest and cache.

## `content.update(file)`

Stores an **already-parsed** file into the manifest and cache without re-reading the source, then emits the `file:upsert` hook. Used for surgical updates such as forwarding an HMR event or applying a webhook patch.

The file carries its own identity in `meta.key`, so no source name is passed. Its `meta.hash` is always recomputed from `data` and `nodes`, so the stored index entry and body agree even when you patch a file you read earlier and its meta still carries the hash of the old text.

**Parameters:**

- `file`: a [`ContentFile`](https://content.comark.dev/reference/types/content#contentfiletdata-tmeta) to insert or replace.

**Returns:** `Promise<void>`

## The input is trusted

A file reaching `update()` has been parsed already — by the instance's own [watcher](https://content.comark.dev/reference/content/watch), by a producing instance whose HMR event or [snapshot](https://content.comark.dev/sources/snapshot) carried it, or by a [hub](https://content.comark.dev/advanced/hub) sibling. Its `file:parsed` transforms ran then. Running them again would transform twice, which for a non-idempotent transform (a markdown field, a title suffix) corrupts the data.

So `update()` stores the file as-is, whether or not the instance also has a raw source:

```ts [hmr.ts]
import.meta.hot.on('comark:update', async ({ file }) => {
  await content.update(file) // already parsed by the producing instance
})
```

::note
Whether the instance owns a raw source is not the signal. A [`withSnapshot()`](https://content.comark.dev/sources/snapshot#withsnapshot) instance has one, and still receives pre-parsed files from HMR and webhooks. The caller knows which kind of file it holds; the instance cannot.
::

## Files you built yourself

A `ContentFile` you assembled by hand — a manual write, a CMS webhook carrying frontmatter you shaped yourself — has not been through the pipeline. Use [`ingest()`](https://content.comark.dev/reference/content/ingest) for it: same storage, with `file:parsed` run once first.


## Sitemap

See the full [sitemap](https://content.comark.dev/sitemap.md) for all pages.
