Skip to content

Editor changes bypass easy-peasy state management via direct mutation #300

@andeplane

Description

@andeplane

Problem

In src/containers/Edit.tsx, the onEditorChange callback mutates the file object directly:

const onEditorChange = useCallback(
  (newValue: string | undefined) => {
    if (!newValue) return;
    const file = simulation?.files.find(
      (file) => file.fileName === selectedFile?.fileName,
    );
    if (file) {
      file.content = newValue; // ← direct mutation
    }
  },
  [selectedFile?.fileName, simulation?.files],
);

This bypasses easy-peasy's immutability contract. While it may appear to work (because objects are references), it:

  • Does not trigger React re-renders for components observing simulation.files
  • Breaks time-travel debugging / state snapshots
  • Is inconsistent with the rest of the codebase which uses proper actions

Solution

Add an updateFileContent action to the simulation store and dispatch it from onEditorChange instead of mutating the file object directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions