Raft Design System

Products · Raft Chat

Opening an Artifact fast

How Raft Chat gets an Artifact ready while its card is on screen — when a card counts as seen, what a preload does and never does, and how the open that follows uses it — one rule for every client that preloads.

An Artifact opens faster when Raft starts on it before the person taps: while its card is on screen, Raft Chat warms the viewer's code, looks up the content domain and fetches the Artifact's read-only details. A preload stores no content on the device and never runs the Artifact's page, so it can't show a stale version, can't mark anything read and can't bypass a permission check. The rule is the same for every client that preloads; this page holds what it does, when it does it and what it must never do. The page itself, once open, is in Artifact page.

artin asked for it (2026-11-28, #proj-mobile:8518431c); Remy measured where an open spends its time and built it (slock #17384, #17387, #17386, #17389), with Tenny's limits on caching and tickets (#proj-workspace:12d31691). Measured on staging, a warm open of an HTML page went from 2.49s to 0.94s and of a Markdown document from 2.42s to 0.85s; a PDF that the Worker had already served came back in 19ms instead of 595ms.

Structure

What happens, in order:

  1. The card is seen: an Artifact card reaches the middle line of the screen (When a card counts as seen).
  2. The preload: the viewer and sandbox code, the content domain's DNS and the read-only details (What a preload does).
  3. The open: the person taps the card, and the viewer uses what the preload fetched while the real open runs (Opening).

Behind them, the content Worker keeps a short-lived cache of what it has already checked, which makes opens faster, preloaded or not: the sandbox's door and the open share one permission check, and content the Worker has already served comes from its cache (The Worker's cache).

Rules

When a card counts as seen

  • Count a card as seen when it reaches the middle line of the screen, with no time on screen required, so a fast fling past it counts too (artin, sindresorhus, 2026-11-28, #proj-mobile:8518431c). A card at the middle is the one the person is reading or about to read; the limit of 2 and the cancelling below keep a fling from preloading too much.
  • Run at most 2 preloads at a time. A fling can pass many cards, and 2 keeps the network free for what the person is looking at.
  • Cancel a queued preload that hasn't started when its card leaves the screen, so that flinging through a long conversation doesn't build a queue of Artifacts the person has already scrolled past.
  • Don't preload while the device asks to save data (the system's data saver or Low Data Mode, as the browser reports it). A preload is a guess, and a person who asked to save data hasn't agreed to spend it on guesses.

What a preload does

  • Warm the viewer's and the sandbox's code, so that the code the viewer needs is loaded before the tap.
  • Resolve the content domain (DNS), so that the sandbox's first connection doesn't start with a lookup.
  • Fetch the Artifact's read-only details, GET /api/artifacts/:id/details. It does the same permission check as a real open, so a preload returns nothing to someone who can't open the Artifact; it signs no ticket; and it has a limit per person (300 a minute), so a client that preloads too eagerly is stopped at the server.
  • Store no content on the device: no file, no page and no copy of a version. Because nothing is kept, there is no size limit per Artifact or per network, and no step that updates a stored copy when a new version comes out. Raft Chat first planned a local cache with size limits per network, a refresh of the cache on each new version and an "updated to vN" notice (#proj-mobile:8518431c); Remy's measurements showed that the time goes to the details, the sandbox's connection and its handshake, not to downloading the file, and a stored copy of an HTML page can't open without going through the sandbox anyway.

What a preload never does

  • Never preload through the open request, GET /api/artifacts/:id. Opening moves the person's read position and clears their unread marks and mentions; a preload through it would mark an Artifact read that the person only scrolled past, and an @mention they never saw would disappear.
  • Never count a preload as an open, in the read position or in the Artifact's open counts: the person hasn't opened it.
  • Never run an Artifact's page in the background. An HTML page is code its author wrote, and Raft runs it only in the sandbox, only once the person opens it.
  • Never sign a ticket for a preload. A ticket opens the content once, within 60 seconds, and only the real open asks for one, so a preloaded Artifact is no easier to reach than any other.

Opening

  • Show a text file, a CSV file or an image at once from the preloaded details, and make the real open request at the same time. These kinds draw from the details alone, and the real open still moves the read position and brings the latest version: when it returns a newer version than the preloaded details, the viewer replaces what it drew with it (useArtifactViewer, Remy, 2026-11-28, #proj-mobile:#442).
  • Open an HTML page, a Markdown document or a PDF with the real open request, which returns the latest version and a new one-time ticket. They run in the sandbox, and only a ticket lets the sandbox in.
  • Don't show an "updated to vN" notice on opening. Every open asks the server for the latest version, so the person always sees it: there is no stored copy that could be older. A version published while the page is open follows The talk bar.
  • Open an Artifact that wasn't preloaded the same way, through the real open request. A preload only makes an open faster, and nothing depends on it.

The Worker's cache

  • Cache on the content Worker only after the permission check has passed, in an internal cache of the Worker's own. Never send public cache headers that let a CDN serve the content by its URL, which would hand it to anyone with the link, even after the person has lost access (Tenny, #proj-workspace:12d31691).
  • Cache only manifests, which don't change, and files of 2 MiB or less, and keep them an hour at most, so that a deleted Artifact doesn't stay at the edge (Tenny, #proj-workspace:12d31691).
  • Keep the answer to a permission check for 30 seconds at most, and treat an error as a denial. Signing out, removing someone and revoking access take effect within that time (Tenny, #proj-workspace:12d31691).
  • Keep tickets one-time. Reusing one permission check for the sandbox's door and the open that follows, for the same person within those 30 seconds, merges two reads; it doesn't let a ticket open anything twice, and a door ticket still can't open the content (Tenny, #proj-workspace:12d31691).

In the native app

  • The apps open every Artifact in a signed-in WebView of the web viewer, so they get the Worker's cache and the viewer's code from it, and the opening rules above hold there.
  • The apps keep the WebViews of the few Artifacts opened last alive, so that opening one of them again doesn't reload it, and always keep one more idle WebView per server ready on the viewer, also after Artifacts have been opened: when the slots are full, the one seen longest ago makes room for it, and once it is used another one is started. The viewer's and the sandbox's code are therefore loaded in the app before the tap, without a preload (sindresorhus, 2026-11-28, #proj-mobile:#442, #proj-mobile:#441).
  • Measured on staging on an Android phone (Reef, 2026-11-28, #proj-mobile:#441) with that rule in place (botiverse/mobile #6074), the first screen of an image, a PDF, a Markdown document or an HTML page opened fresh shows in 254–273ms, and of one whose WebView was kept alive in 220–254ms. Each fresh open took the warmed WebView 2–7ms after the tap and never reloaded it. Before the fix, fresh opens took 603–843ms, because the app stopped warming an idle WebView once it kept any Artifact alive.
  • The apps' message cards are drawn natively, not by the web page, so they don't trigger a preload (sindresorhus, 2026-11-28, #proj-workspace:12d31691).
  • The apps don't add a preload of their own from their cards, and the viewer offers no entry for an app to start one. A fresh open is already about as fast as one whose WebView was kept alive, and the read-only details would save about 250ms at most, only for images and text files, which draw from the details alone (sindresorhus, 2026-11-28, #proj-workspace:12d31691).