# Upgrading from 0.1.0 to 0.2.0

0.2.0 changes some defaults and some stored or wire shapes of 0.1.0 (the `main` of `75e5f14`, which was not
tagged). Deploy the Elixir and the JavaScript sides together, and read this list before you do. Items marked
*(after 0.1.0)* concern features added after 0.1.0 that changed again before 0.2.0: they matter only to code
that followed the untagged `main`. [CHANGELOG.md](../CHANGELOG.md) also lists what was added.

**Deploying.** The server now sends entry operations (`ops` in `live_slice:patch`, from `put_entries/5` and
the others) and binary columns of types `:int16` and `:uint16`. A tab still running the previous bundle when the
new server is up does not apply `ops` (the patch is dropped without an error) and its column decoder throws
`unknown column type 8` (or `9`) for such a chunk, which the chunk loader reports as a failed chunk. The
server cannot fall back to whole keys, since it does not hold the client's value of a key. Keep the
`phx-track-static` attribute that Phoenix's root layout puts on the script and stylesheet tags: a tab whose
bundle is older than the server's reloads when it reconnects after the deploy, before any patch reaches it.
Only send the new operations or column types once the new bundle is deployed, if a tab may stay connected
across a deploy without `phx-track-static`.

**Changed return values.**

- `LiveSlice.CRDT.delete/2` returns `{:ok, generation}` instead of `:ok`, as `delete/3` already did (see
  [Deleting a document](collaborative-keys.md#deleting-a-document)). Migration: match `{:ok, _generation}` where code matched `:ok`
  (`{:ok, _generation} = LiveSlice.CRDT.delete(MyApp.CRDT, name)`, or that pattern in a `case`). The errors are
  unchanged.

**Changed defaults.**

- *(after 0.1.0)* Connection state: a store with no bridge mounted and none expected on the page is
  `"detached"` instead of `"connecting"` (see [Connection state](tabs-and-connection.md#connection-state)): a page without the
  store's bridge, after the last bridge's element was removed, or after a live navigation to a page without
  one. `"connecting"` now means a bridge is expected. `store.connection`, the `connectionKeys` status key and
  `onConnection` follow. Nothing restores the old value; an interface that showed `"connecting"` for such pages
  reads `"detached"` as `"connecting"` (`status === "detached" ? "connecting" : status`).
- Failed pushes: a server action that got no reply after `maxAttempts` pushes is kept as failed (`keepFailed`
  is true by default) instead of rolled back with `"push_failed"`: it stays applied and pending, and holds back
  the later calls that may concern its record, until `retry(id)` or `discard(id)` (see
  [Failed pushes](persistence.md#failed-pushes)). Without an `onFailed` listener this is reported once with `console.warn`.
  `keepFailed: false` restores the old behaviour exactly; a tab still running 0.1.0 (which always rolled such
  a call back) rejects a call another tab kept as failed when its queue reaches it.
- Service worker: a precache file that is not a script, stylesheet or WebAssembly no longer fails the install;
  it is skipped and reported (`essential` restores the old rule). The manifest of `LiveSlice.ServiceWorker`
  leaves out digested names that `:only` does not serve, and logs them; `only: []` (or `only_matching: []`)
  now lists everything, as `Plug.Static` serves everything with it.
- Offline mount: a hook present in the page and not mounted offline is reported with `console.warn`, once per
  name (never LiveView's own `Phoenix.` hooks); `exclude` silences one.
- Collaborative keys: local changes are batched (`batchMs`, 50 ms); the status can be `"waiting"`; the status
  key has `unsent`; mirrored keys are pushed before each `sync1`.
- Persisted keys are shared live between tabs (`persist.share`, true; `false` or a list of keys to share).
- *(after 0.1.0)* The bridge sends queued calls again after settlements and retries, and `retry()` sends at
  once after a push that timed out.
- *(after 0.1.0)* `If-None-Match` goes only to URLs of the page's origin;
  `createLiveSliceHook({ conditional })` opts other origins in. A 304 to a request without it is an error.
- `LiveSlice.CRDT`'s `:rate_limit` is one window per key and LiveView, whatever document the key syncs (a
  `sync1` to another document no longer starts a fresh window), and background deliveries count in it, a
  `deliver1` included.
- *(after 0.1.0)* Coalesced patches: those a `handle_action/4` makes go out before its reply; `invalidate/4`
  sends the held patches of its store first; a patch made with a LiveComponent's socket is pushed at once. The
  first patch after a quiet time is no longer pushed alone in the middle of its callback: it goes out at the end
  of the callback with every patch of the store that callback makes (see
  [Coalescing patches](patch-and-invalidate.md#coalescing-patches)), so a callback that navigates calls `flush_patches/2` first for
  those too, and a held key keeps the key (atom or string) the patch gave instead of turning into a string.

**Errors that used to pass.**

- *(after 0.1.0)* `patch/4` and the entry functions raise `ArgumentError` for an unknown option.
- *(after 0.1.0)* A connected LiveView that renders a bridge sending the actions of a `LiveSlice.Actions`
  module it does not attach raises `ArgumentError` at its first render.
- *(after 0.1.0)* `send_json/3` raises for a `:version` that is not a non-empty string, an integer, a
  `DateTime`, `NaiveDateTime` or `Date`, and for data that is a function of another arity than zero.

**Stored and wire shapes.**

- The persisted record of a store has `seq` and `stamps` (per key), now counted from the current time in
  milliseconds rather than from 1, and `epoch` once the record was cleared. `removeStore(name, {clearPersisted:
  true})` replaces the record by `{cleared: id}` instead of deleting it; a tab of the previous version reads that
  marker as an invalid record, removes it and writes its own state again, as it would after a delete.
- Tabs also post `{type: "attempted", id, attempts}` for each push of the sending tab; older tabs ignore it.
- *(after 0.1.0)* Install reports in `live_slice:meta` carry `rank` (the install order) and `offlinePage` is
  null when the offline page was not kept. A reset (`unregisterServiceWorker({clearCaches: true})`) deletes the
  reports.
- *(after 0.1.0)* `send_json/3` tags of versions with a comma, a quote, a space or non-ASCII characters are
  hashed (`W/"h<hash>"`); the tags of other versions are unchanged (`W/"v<version>"`). Weak comparison and `*`
  are honoured.
- *(after 0.1.0)* The persistent chunk cache keys an entry with a per-chunk version by the version's type too:
  such entries cached before are fetched again once.

**Additions**: every listener event about a call (`onPending`, `onQueued`, `onFailed`, `onRetry`, `onConflict`,
`onRejected`, `onSettled`) and the context of an `onConflict` resolver carry `at`, the time the call was made, as
`pending()` does (see [Offline promises and the time of a call](persistence.md#offline-promises-and-the-time-of-a-call)), so a
test that compares whole events sees one more field. `onReset` of a collaborative key also gets `carried`,
`carriedValue` and `notCarried` (`false`, `null` and `"off"` unless `carryOver` is set). A document storage's `load` and `setGeneration`
resolve with `carry` too, `setGeneration` passes `decide` what is stored as a second argument, and its change
may hold `carry` and `append` (see `crdt_storage.js`); custom storages that do not know them keep working.
*(after 0.1.0)* The binding settles stored updates each time the server acknowledges changes, not only once
none is left, so after a reload `unsent` and `unsentSince` leave out what was acknowledged before (see Unsent
changes). Opt-in:
`carryOver` of a collaborative key and of `deliverUnsentDocuments` (see
[Carrying unsent changes over](collaborative-keys.md#carrying-unsent-changes-over)), `coalesce: [keep: keys]`,
`createLiveSliceHook({ conditional })`, `persist.share` as a list, `dropUnsentDocument`, `onLoad` and `loaded` of a
collaborative key, `openTab()` and `storage` of `createFakeTabs()` in `live_slice/testing`, and
`LiveSlice.CRDT.delete(doc_name, opts)` on the default server.
*(after 0.1.0)* `LiveSlice.CRDT.MemoryPersistence.save/4` is there again for persistences that wrap it.
