drawdb icon indicating copy to clipboard operation
drawdb copied to clipboard

refactor: fix impure state updates in DiagramContext and extract useD…

Open MOHITKOURAV01 opened this issue 1 month ago • 1 comments

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:

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [x] 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.

MOHITKOURAV01 avatar Nov 25 '25 20:11 MOHITKOURAV01

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.

vercel[bot] avatar Nov 25 '25 20:11 vercel[bot]