GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Device

Show the last server answer at once, from the device, for the signed-in account. Then ask the server again.

src/main.ts
import { createApp } from 'vue'
import { openDevice } from 'vite-hub/device'
import App from './App.vue'

// Read the stored answers before the first render
await openDevice({ version: '1' })
createApp(App).mount('#app')
src/main.ts
PartWhat it does
Stored readsuseStoredData() shows the stored answer in the first render, then calls your loader. It has the shape of Nuxt useAsyncData(). useStoredFetch() does the same for a GET of JSON, and never stores an error answer.
NuxtThe ViteHub module opens the device, auto-imports the reads, and with ViteHub Auth, names the account and waits for the copies to go on sign-out.
One accountThe device holds the copies of the account that your session read names with its account option, or that you name with setDeviceAccount(). Another account, or a sign-out, deletes them in every tab.
No account, no diskThe device stores only the answers of loader calls that start after the page names an account, and the answer of the session read that names it. An app that names no account stores nothing.
CapsA copy older than maxAge (7 days by default) does not show. The device keeps at most 5 MB, and deletes the oldest copies first.
VersionsopenDevice({ version }) deletes the copies of another version, so a new build does not show data of an old shape.
FallbackIn a private window or sandboxed frame without IndexedDB, copies stay in memory.
InspectioninspectDevice() returns the account, the storage, and each copy with its key, time, and size.

A stored copy only changes what the screen shows first. The server still checks every request.