Skip to content

diagram: Snapshotter modelErrors appends use non-functional setState (clobber-prone, currently dead code) #728

Closed

Description

@bpowers

Summary

In src/diagram/Editor.tsx, the snapshot-image onload/onerror handlers append to modelErrors using a non-functional read of state instead of the functional updater form:

setState({ modelErrors: [...latest.current.state.modelErrors, err] })

(around lines 2216 / 2227 in the function-component conversion; this was this.state.modelErrors in the old class at the pre-conversion HEAD, lines 2056 / 2067). The conversion kept these two appends byte-for-byte faithful to the pre-conversion class behavior.

This read-then-write pattern is clobber-prone under concurrent appends: a concurrent controller onError append in flight could be lost, because the snapshot handler captures a stale modelErrors snapshot rather than reading the latest committed state inside the updater.

Why it matters

  • Correctness (latent): concurrent appends to modelErrors from the snapshot path and the controller onError path can race and drop an error entry.
  • Consistency: the other append sites in the same file (onError, appendModelError, handleCloseSnackbar) already use the concurrent-safe functional updater form. These two are the outliers.

Currently dead code

This is not a current bug: the Snapshotter UI is commented out in the Editor render ({/*<Snapshotter .../>*/}), so the snapshot onload/onerror path is unreachable today. Tracking it so it isn't silently re-enabled in a broken state.

Component(s) affected

  • src/diagram -- Editor.tsx (snapshot-image onload/onerror handlers)

Recommended resolution

When/if the Snapshotter snapshot UI is re-enabled, convert these two appends to the functional updater form to match the other concurrent-safe append sites:

setState((prev) => ({ modelErrors: [...prev.modelErrors, err] }))

How discovered

Flagged by the adversarial reviewer during the Editor.tsx class-to-function-component conversion (branch functional-components-migration). Non-blocking tech debt deferred from that review.

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