Skip to content

After a version bump within the same major, every other load restores the old offline copy (slide() writes it back) #326

Open

Description

@cedricvogel-leo

Summary

After a course's version goes from 1.0.0 to 1.0.2 (same major), Chrome alternates on every reload: one load shows 1.0.2, the next restores the stored 1.0.0 copy (including its old imported templates/macros), the next shows 1.0.2 again, and so on. It doesn't settle, also with all other tabs closed. The course list on the start page consistently shows 1.0.2; the info pane in the course alternates, and so does the behaviour of the imported template.

Steps to reproduce

  1. Open a course with version: 1.0.0 on some slide, e.g. …/README.md#6.
  2. Change the course and set version: 1.0.1 (or 1.0.2).
  3. Reload the course tab several times and watch the version in the info pane (or anything that differs between the two versions, e.g. an updated imported template).

Expected: from the first reload on, 1.0.1 every time.
Actual: 1.0.1, 1.0.0, 1.0.1, 1.0.0, … (Chrome on macOS; our live course is at 1.0.2 now, so it only shows for browsers that had stored 1.0.0).

Evidence

Console snippet, run after each reload:

(async () => {
  const url = decodeURIComponent(location.search.slice(1))
  const open = (n) => new Promise((ok, ko) => { const r = indexedDB.open(n); r.onsuccess = () => ok(r.result); r.onerror = ko })
  const get = (db, s, k) => new Promise((ok) => { const r = db.transaction(s).objectStore(s).get(k); r.onsuccess = () => ok(r.result) })
  const idx = await open('Index'), db = await open(url)
  const c = await get(idx, 'courses', url), off = await get(db, 'offline', [0, 1])
  console.log('index says:', Object.entries(c.data).map(([k, v]) => k + ' → ' + v.version).join(', '),
              '| stored copy is:', off?.data?.definition?.version)
  idx.close(); db.close()
})()

Output, alternating:

index says: 0 → 0.1.0, 1 → 1.0.0 | stored copy is: 1.0.0     ← load that restored the old copy
index says: 0 → 0.1.0, 1 → 1.0.2 | stored copy is: 1.0.0     ← load that parsed 1.0.2 fresh

After the fresh 1.0.2 load, the index entry says 1.0.2, but the offline copy is still 1.0.0.

Cause (as far as I can trace it, development @ 64734fa)

  • The index entry and the offline copy are keyed by the major version only (Lia/Json/Encode.elm L63, Service/Database.elm L167 toJson → getMajor), so 1.0.0 and 1.0.2 share one slot.
  • On a load that parses fresh, index_store (liascript/service/Database.ts L132) calls connector.open() (L143) without awaiting it, then connector.storeToIndex() (L189) → storeIndex (connectors/Browser/database.ts L354) writes the new copy into offline (put({ id: 0, version: 1, data })).
  • At the same time slide() (connectors/Browser/database.ts L246) stores the current slide by reading the whole offline item, setting item.data.section_active and putting it back. If its get runs before storeIndex's put, its put writes the old 1.0.0 copy back over the new one.
  • Next load: load_readme (Update.elm L734) / inCache (Index/Update.elm L675) sees 1.0.2 in the index, so it restores the offline copy, which is 1.0.0. load_first_slide then stores that model again, so the index goes back to 1.0.0. The load after that parses fresh again, and the race repeats.
  • The first version in a slot is safe: slide() finds no item, throws, and writes nothing.

Suggested fix

Let slide() change only section_active instead of writing back the whole copy, e.g.

await this.db.offline
  .where({ id: 0, version: this.version })
  .modify((item) => { item.data.section_active = id })

Dexie runs modify in a read-write transaction on the current item, so it can no longer resurrect an older copy. (Alternatively, await the open and the storeIndex write before the first slide() call.)

Impact

Updates within a major version, including updated imported templates, only reach every other load for everyone who had opened the previous version. Learners' answers are not affected (separate tables). Our workaround is to delete the course from the start page, which removes its database.

Thanks for LiaScript!

Activity

  1. andre-dietrich commented on Nov 2, 2026

    @andre-dietrich
    Member

    Thanks for the bug report ... This shall be fixed according to your suggestions. Same as before ... I will update all other tools later ;-) ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions