Skip to content

Add a flush-state-on-demand message so hosts can safely unmount in-progress viewers #1440

Description

@dqnykamp

Motivation

Hosts embedding many activities want to unmount off-screen viewers to reclaim their ~180 MB (assignment-viewer windowed pagination; PreTeXt park-and-restore for long book pages). Remounting later with prior work intact already almost works — hosts receive serialized doc state via reportScoreAndStateCallback and can pass it back as initialState. The gap: state is only reported at core save events, so any student work since the last report is silently lost when the host tears the viewer down.

Proposed change

Add a host-initiated flush to the standalone viewer / doenetml-iframe protocol:

  1. A flushState request message: the viewer responds (once the core is idle) with the current serialized document state in the same shape as initialState, plus the current score payload.
  2. A documented guarantee that after the response, unmounting loses nothing.
  3. Optionally an explicit ready / stateSaved acknowledgment event stream so hosts can implement "safe to unmount" logic without polling.

The worker already has the serialization machinery (StatePersistence builds exactly this payload on every save), so this is mostly protocol plumbing through CoreWorker → standalone → iframe messages.

Enables

Related: #1436 (message-based prop updates), PR #880 rescope (initialization coordination).

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Fields

    Priority

    Medium

    Effort

    Medium

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions