Persistence
When you modify@field properties, Idyllic automatically persists changes to durable storage. You don’t write database code, configure serialization, or explicitly save data. This guide explains what persists, when, and how to work with the system effectively.
What Persists Automatically
Everything marked with@field persists. After each action completes, Idyllic serializes field values to SQLite storage within the Durable Object. When the system wakes—whether seconds or days later—state restores exactly as you left it.
addTask stores durably. Close your browser, restart the server, return a week later—this.tasks contains everything you added. No explicit save call needed.
Stream fields persist their current value. When streaming completes, accumulated content saves. Clients connecting afterward see the final result.
What Does Not Persist
Properties without@field exist only in memory. They reset when the Durable Object hibernates or restarts.
When Persistence Happens
State writes to storage after each@action method completes successfully and when streams complete or fail. The write happens asynchronously—no blocking I/O in your action methods.
If an action throws before completing, state changes roll back. This transactional behavior keeps state consistent even when errors occur.
Serialization Requirements
State stores as JSON. All values must be JSON-serializable:| Type | Supported | Notes |
|---|---|---|
| Primitives | Yes | string, number, boolean, null |
| Plain objects | Yes | |
| Arrays | Yes | |
| Maps, Sets | Yes | Serialized/restored correctly |
| Dates | Yes | Serialized as ISO string |
| Functions | No | Cannot serialize |
| Class instances | No | Lose prototype chain |
Handling Schema Changes
As your application evolves, state shape may change. Handle migrations inonCreate():