Skip to content

Enable undo/redo based on track in revisit stimuli #659

Description

@JackWilb

Will require track changes (e.g., 2 provenance graphs) to track node visitations.
Will require updates to replay.


Specification

Added after specification review.

Summary

Make undo, redo, and other visits to existing Trrack nodes replay correctly by making reVISit responsible for creating and observing Trrack instances through its public stimulus APIs. Study code will continue to define its state and domain-specific actions, while reVISit captures the initial state and every current-node transition automatically.

The managed API closes the gap left by graph snapshots alone: a graph describes state structure, but not the chronological order in which participants revisit existing nodes.

Decisions

  • Provide a managed useRevisitTrrack(...) hook or equivalent factory for React stimuli and Revisit.createTrrack(...) for website/iframe stimuli.
  • reVISit owns Trrack instance creation, transition observation, provenance persistence integration, hydration integration, and listener cleanup. Study code owns the state definition, registry, and domain-specific actions.
  • Cover React stimuli, HTML/website stimuli using revisit-communicate.js, and reVISit's built-in response components. Svelte and other iframe frameworks use the website API.
  • Preserve the existing manual setAnswer({ provenanceGraph }) and Revisit.postProvenance(...) APIs for backward compatibility, but mark them with @deprecated so they can be removed in a future compatibility-breaking release.
  • Mark legacy graph-only replay paths with @deprecated where applicable. Retain them until an explicit removal/version-support decision is made so historical sessions remain readable.
  • Preserve the standard Trrack graph and add one compact chronological traversal sequence containing the visited node ID and transition timestamp. Do not store a second full provenance graph.
  • Record the initial current node and every subsequent current-node change, including apply, undo, redo, direct traversal, import/hydration selection, and branching after undo. Repeated reports of the same current node do not create traversal events.
  • Timestamp transitions in the managed listener when currentChange fires. Preserve that timestamp through transport; use store-ingestion time only as a fallback for manual integrations without a source timestamp.
  • Keep answer updates separate from provenance updates. The managed Trrack API reports provenance automatically, while studies use the existing answer API when their reactive answer changes.
  • Existing stored sessions without traversal history continue through the deprecated graph-based replay fallback. Do not attempt to reconstruct historical undo/redo timing.
  • PR Fix Trrack undo/redo replay #1305 is a prerequisite and should merge first. The implementation of this issue is the follow-up refactor that builds on Fix Trrack undo/redo replay #1305's traversal data model and replay compatibility work, then removes or replaces its temporary store-ingestion capture path with managed lifecycle capture.

Acceptance Criteria

  • React stimuli can create Trrack through a reVISit-provided hook or factory.
  • Website/iframe stimuli can create Trrack through Revisit.createTrrack.
  • The managed APIs subscribe before returning the instance and publish its initial state.
  • Apply, undo, redo, direct traversal, import/hydration selection, and branching after undo are captured automatically.
  • Study authors using the managed API do not call postProvenance, pass provenanceGraph to setAnswer, or register a provenance-reporting currentChange listener.
  • Traversal events contain the visited node ID and source transition timestamp.
  • Duplicate reports of an unchanged current node do not create traversal events.
  • Managed listeners are removed on React unmount, iframe navigation, or component disposal.
  • Participant replay follows chronological traversal history rather than graph creation order.
  • Existing provenance graphs without traversal history remain readable through the deprecated legacy fallback.
  • Existing manual provenance APIs remain functional and are marked @deprecated.
  • Applicable graph-only replay paths are marked @deprecated.
  • Official React, HTML, and Svelte Trrack examples use the managed API.
  • The temporary store-ingestion capture path introduced by Fix Trrack undo/redo replay #1305 is removed or reduced to the documented compatibility fallback.
  • Automated tests cover initial capture, apply, undo, redo, branching, direct traversal, cleanup, hydration, legacy data, and manual API compatibility.
  • No new dependency is introduced.

Out of Scope

  • Automatically discovering or monkeypatching privately created Trrack instances.
  • Migrating arbitrary external studies without source changes.
  • Moving study-specific action definitions into reVISit.
  • Reconstructing traversal timing for historical data.
  • Replacing Trrack's graph format.
  • Redesigning the provenance visualization beyond what chronological replay requires.
  • Removing deprecated APIs or historical replay compatibility in this issue.

Implementation Notes

  • Subscribe to currentChange before exposing the managed instance to study code so no transition can occur before observation begins.
  • The managed listener should emit the graph plus its traversal event through the existing React or iframe transport boundary.
  • The central store may retain ingestion-time event creation only as a compatibility fallback for deprecated manual integrations that omit a traversal event.
  • Disposal must be idempotent and prevent listeners from surviving task navigation or remounts.
  • Deprecation comments should identify the managed replacement API and the intended compatibility behavior.

Testing Notes

  • Add focused unit coverage for the managed React lifecycle, website bridge lifecycle, traversal serialization, source timestamps, deduplication, and disposal.
  • Cover a sequence such as root -> add -> add -> undo -> redo -> undo -> branch and assert exact chronological replay.
  • Test imported or hydrated graphs and confirm that initialization is captured once.
  • Test historical graph-only data and deprecated manual reporting paths.
  • Update official Trrack demo interaction coverage to verify that provenance is captured without explicit study reporting code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SpecifiedIssue has enough detail to implement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    In progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions