Skip to content

ts: stockFlowViewToJson has two divergent implementations (@simlin/core vs src/diagram/view-conversion.ts) #821

Closed

Description

@bpowers

Problem

stockFlowViewToJson (StockFlowView -> JsonView serialization) exists in two independent implementations, and callers within the same package use them inconsistently:

  • src/core/datamodel.ts:1366 -- the @simlin/core/datamodel implementation, used by:
    • src/core/datamodel.ts:1613 (model -> JSON serialization)
    • src/diagram/merge-live-view.ts:41
  • src/diagram/view-conversion.ts:138 -- a separate diagram-local implementation, used by:
    • src/diagram/Editor.tsx:743 and :1918
    • src/diagram/project-controller.ts:835

So within src/diagram alone, project-controller.ts and Editor.tsx serialize views with one implementation while merge-live-view.ts uses the other.

Why it matters

Two copies of the same view-serialization logic will drift. Any divergence means the JSON a live-view merge produces can differ from the JSON a patch/save produces for the same view -- a subtle correctness hazard in exactly the code paths that recent flow-editing bugs (#812, #817, #818) went through. It also doubles the maintenance and test surface for every view-element field change (see #811 for fields already being dropped on view edits).

Component

  • src/core/datamodel.ts
  • src/diagram/view-conversion.ts, src/diagram/Editor.tsx, src/diagram/project-controller.ts, src/diagram/merge-live-view.ts

Possible approach

Reconcile to a single implementation (most likely keep the @simlin/core one, since core is the shared data-model layer and diagram already depends on it), diff the two implementations first to understand any intentional differences, and add round-trip tests before deleting the duplicate.

Context

Identified during the June 2026 flow-editing audit. Same class of problem as #624 (two divergent canonicalize implementations), but a different function.

Activity

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