drawdb
drawdb copied to clipboard
refactor: fix impure state updates in DiagramContext and extract useD…
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:
-
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
useMemoto prevent unnecessary re-renders of consuming components.
- Moved side effects (like setUndoStack) out of state setter callbacks (
-
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.
-
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.
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.