Skip to content

fix(runtime): the content's id is the same on every load of a package - #131

Merged
alekswebnet merged 1 commit into
mainfrom
fix/stable-content-id
Nov 4, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
fix/stable-content-id

Conversation

@alekswebnet

Copy link
Copy Markdown
Contributor

Closes #127.

Interactive Book reopened on its first chapter after every leave, in every resume mode and in the SCORM zip, while its answers came back. It keeps its chapter under the content's id, in its saved state and in the page's address (urlFragments, h5pbookid), and takes it back only when the id matches. The boot script gave the content a random id on every load, as h5p-standalone did, so it never matched.

The change

contentIdOf in the runtime's boot script: the content's id is now a number made from the package's id, the first twelve of its hex digits. Nothing changes in the player or the worker: the boot configuration has always carried the package id.

  • The same on every load, as a site's row number is, and tied to what the learner's state is kept under: the package id is the URL and its validator, or the picked file's name, size and date.
  • A number, as every site gives one. Cornell Notes keeps a copy of its notes in localStorage under the id and reads it back only when typeof id === 'number'; Course Presentation accepts a string or a number. No other library in the pack tests or parses the id.
  • Twelve digits: the core reads the id back through jQuery's .data(), which turns a string of digits into a number, and a double holds twelve hex digits exactly; the full 32 would not.

One consequence: two players of one book on one page share the address's chapter and turn pages together, as two copies of one content do on an H5P site.

Checked

  • resume.test.ts: the id is the package id's number on two loads of one package, the core's cid- key names it, and another package gets another. It fails on the old boot script, which gave xga807z.
  • The corpus's 12-chapter Interactive Book (1.15.1) in the plain player with resume="device", on a site written from this branch: read to chapter 5, then a reload with the book's hash in the address, and a fresh address with only the saved state. Both reopened on chapter 5; before, chapter 1.
  • The same book as a SCORM zip from this branch in Moodle 4.5, "SCORM 1.2 standard mode" on: read to the last chapter, left, launched again. entry was resume and the book showed chapter 12 of 12; before, chapter 1.

Release

A runtime patch, 1.0.1: the player's peer range already takes it. Embed should require it in its next release, so every SCORM zip it writes carries the fix.

🤖 Generated with Claude Code

The boot script gave the content a random id on every load, as
h5p-standalone did. Interactive Book keeps its chapter under that id, in
its saved state and in the page's address, and takes it back only when the
id matches, so a book always reopened on its first chapter, in any resume
mode and in the SCORM zip. A site gives each content its row's number, the
same every time; the id is now a number made from the package's id, twelve
of its hex digits, which a double holds exactly through jQuery's .data().
Cornell Notes, which reads the copy of its notes it keeps by the id only
for a number, finds it again too.

Closes #127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the stable content ID change intended to support saved chapter restoration.

No open issues 🎉

What changed in this PR

Fixes #127 by giving each package a stable numeric content ID, allowing Interactive Book to restore its saved chapter across loads, including in SCORM packages.

Changes:

  • Derives the content ID from the first twelve hexadecimal digits of the package ID instead of generating it randomly.
  • Adds browser coverage for numeric IDs, stability across reloads, and distinct IDs for different packages.
  • Updates resume documentation and design notes to describe chapter restoration and shared IDs.
File Description
packages/​runtime/​src/​frame-boot.ts Derives a stable numeric content ID from the package ID.
packages/​player/​tests/​browser/​resume.test.ts Tests ID stability, numeric values, and integration keys.
docs/​resume.md Includes chapters among the positions content can save.
AGENTS.md Documents the ID invariant, its consequences, and the chapter-resume fix.

Review effort: Balanced

@alekswebnet
alekswebnet merged commit d692b2e into main Nov 4, 2026
10 checks passed
@alekswebnet
alekswebnet deleted the fix/stable-content-id branch November 6, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive Book never returns to its chapter: the frame's content id is random per load

2 participants