Tea preserves the state of your story in several overlapping ways: a moment-based history that supports forward and backward navigation, a temporary playthrough session stored in the browser that survives accidental refreshes, and configurable browser saves (both manual slots and automatic). Understanding how these systems interact prevents subtle bugs and data loss for your players.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pompom454/tea/llms.txt
Use this file to discover all available pages before exploring further.
Story History
The story history is a collection of moments. A new moment is created whenever passage navigation occurs — and only when passage navigation occurs. Each moment records the active passage name and the current values of all story variables (those accessed with the$ sigil).
If you save the story after reaching another passage,
$var is saved as 1. Clicking the link sets it to 2 in memory, but because no new moment has been created yet, a save at that point still records $var as 1. The next passage navigation creates the next moment and captures the updated value.Config.history.maxStates. As new moments are added, older ones that exceed the limit expire in age order. Expired moments are recorded in a separate expired collection and can no longer be navigated to directly — but all functions and macros that check for the existence of moments (such as visited()) search both active and expired moments, so they work correctly even when history is limited to a single moment.
Config options that affect history
| Setting | Purpose |
|---|---|
Config.history.maxStates | Maximum moments kept in the active history. Must be at least 1. As of ≥2.36.0, unlimited states are no longer allowed. |
Config.history.controls | Whether the UI bar history forward/backward buttons are shown. |
Config.history.disableDeltas | Disables delta encoding for history states. Required if you use classes with private fields in story variables. |
Playthrough Session
The playthrough session and autosaves are distinct systems that are occasionally confused.
Browser reloads Tea
If the reload is caused by a refresh, back/forward navigation, or the tab being unloaded — Tea restores the session.
Autosaves
Autosaves are ordinary browser saves that are created automatically. They can be configured to fire on every turn or only on specific turns. UseConfig.saves.maxAutoSaves to set how many autosave slots are available, and Config.saves.isAllowed to control when new autosaves are created. The default UI includes a Continue button that loads the latest save.
What Happens When a Save Is Loaded
When a save is loaded, the state it contains replaces the current state entirely. The previous state is not merged or combined — it is discarded completely. This applies whether the state comes from a manual slot save, an autosave, or the playthrough session.<<set $y to 1>> to StoryInit and reload the old save, $y will be undefined in the loaded state — it simply does not exist there.
Refreshing vs Restarting
Every time Tea starts — whether from a fresh load or a browser refresh — the following sequence always runs:- CSS, JavaScript, and Widget sections are processed.
init-tagged passages andStoryInitare processed.- Either the playthrough session is restored (if one exists), or the starting passage is rendered.
UI.restart(), Engine.restart()), the playthrough session is skipped and the starting passage is rendered directly.