Skip to content

Conversation

@MOHITKOURAV01
Copy link

@MOHITKOURAV01 MOHITKOURAV01 commented Nov 25, 2025

Title: Refactor DiagramContext and Workspace to fix state management bugs

Description:
This PR addresses issue #737 by refactoring DiagramContext and Workspace to improve state management and code maintainability.

Changes:

  1. Fixed Impure State Updates in DiagramContext:

    • Moved side effects (like setUndoStack) out of state setter callbacks (setTables, setRelationships) to prevent impure updates and potential double-invocations in Strict Mode.
    • Memoized the context value using useMemo to prevent unnecessary re-renders of consuming components.
  2. Extracted Logic to useDiagramIO Hook:

    • Created a new hook src/hooks/useDiagramIO.js to encapsulate the complex logic for loading, saving, and autosaving diagrams.
    • This separates data persistence concerns from the UI layout in Workspace.jsx.
  3. Refactored Workspace.jsx:

    • Simplified the component to focus primarily on layout and composition, delegating data management to useDiagramIO.

Fixes: #737

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (no functional changes, no api changes)

How Has This Been Tested?

  • Manual verification of diagram operations (add/remove tables, relationships).
  • Verified Undo/Redo functionality works correctly.
  • Verified Save/Load functionality works as expected.
@vercel
Copy link

vercel bot commented Nov 25, 2025

Someone is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant