API reference › @evolu/web › createEvoluDeps
function createEvoluDeps(
deps?: Partial<ConsoleDep> &
Partial<ReloadAppDep> &
Partial<SharedWorkerUnsupportedDep> &
Partial<RequestPersistentStorageDep>,
): EvoluDeps;
Defined in: packages/web/src/local-first/Evolu.ts:117
Creates Evolu dependencies for the web platform.
Checks storage once when the deps are created. If it is available, the tab
starts its stored worker as soon as that check resolves, without waiting for
an instance. It then reloads for new builds until it closes, which also ends
any EvoluConfig.memoryOnly instances. It reloads at once if the user
is not in the tab, otherwise once they leave it. See Builds in the Shared
module of @evolu/common. A tab whose database refuses to start with
UnsupportedDbVersionError reloads once for each stored version, even
while the user is in it, because the server may now serve a build that
supports the database. The error is reported when the reloaded build refuses
it too, or when the tab has no session storage. A tab whose stored worker was
relaunched without its state, as WebKit does when the process hosting it
ends, also reloads at once. Closing another tab can trigger that Safari
relaunch and end this tab's memory instances when storage is available.
If storage is refused, the tab never starts the stored worker, and build
coordination never reloads it. The syncState store includes only the memory
databases of instances these dependencies created. The evoluError store
includes only errors from the workers of memory instances these dependencies
created. The back-forward cache reload described below and
Evolu.deleteDatabase's default reload, without
EvoluConfig.onDatabaseDeleted, still apply.
When the page enters the browser's back-forward cache, as Safari does on every navigation away, this tab ends its part as if it closed: it stops the database workers it hosts, so another tab takes over stored databases, and ends this tab's Evolu instances. Memory databases end with their instances. The tab reloads if the user comes back to it.
Where the browser offers no persistent storage, as in Safari's Private
Browsing or a Firefox private window, the database is kept in memory, and
Evolu.devicePersistence resolves to NotPersisted, so the app can
tell the user. Each memory instance has its own database and workers in its
own tab. When storage is refused, closing another tab leaves it intact.
Explicit memory instances in a tab with storage also end when Evolu reloads
that tab for a waiting build, a stored worker relaunch, or a database
refusal. Data that exists only locally, or has not synced yet, is lost when
the instance ends, including when its tab closes, reloads, or enters the
back-forward cache. A memory instance exchanges changes with every other
instance, stored instances of the same owner included, only through relays,
so not offline. Each opens its own relay sockets, even beside a stored
instance of the same owner.
After the first local mutation of a database the browser stores, this tab
asks the browser once with navigator.storage.persist() not to delete the
site's data when disk space runs low. Chrome and Safari decide silently, and
Firefox asks the user, so every tab asks until the user allows it. A custom
RequestPersistentStorageDep.requestPersistentStorage replaces the
request, for example with constVoid to never ask. See Will my data stay on
the
device?.
A custom ReloadApp replaces the default page reload, for example to save state first. It should end by reloading the page, because the other build waits until this tab reloads or closes, and a page restored from the back-forward cache cannot work until it reloads.
It installs the polyfills Evolu needs, such as DisposableStack, which
Safari lacks, so apps don't have to call installPolyfills first.