-
Notifications
You must be signed in to change notification settings - Fork 56
schematic view toggles #2469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
schematic view toggles #2469
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const [internalShowSchematicDebugGrid, setInternalShowSchematicDebugGrid] = | ||
| useState(showSchematicDebugGridProp) | ||
| const [internalShowSchematicPorts, setInternalShowSchematicPorts] = useState( | ||
| showSchematicPortsProp, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The internal state is initialized with prop values but never updates when props change. If showSchematicDebugGridProp or showSchematicPortsProp change from the parent while handlers are not provided, the component will continue using stale values.
To fix, add useEffect to sync internal state with prop changes:
useEffect(() => {
if (!onChangeShowSchematicDebugGrid) {
setInternalShowSchematicDebugGrid(showSchematicDebugGridProp)
}
}, [showSchematicDebugGridProp, onChangeShowSchematicDebugGrid])
useEffect(() => {
if (!onChangeShowSchematicPorts) {
setInternalShowSchematicPorts(showSchematicPortsProp)
}
}, [showSchematicPortsProp, onChangeShowSchematicPorts])This ensures props remain the source of truth even in uncontrolled mode.
| const [internalShowSchematicDebugGrid, setInternalShowSchematicDebugGrid] = | |
| useState(showSchematicDebugGridProp) | |
| const [internalShowSchematicPorts, setInternalShowSchematicPorts] = useState( | |
| showSchematicPortsProp, | |
| ) | |
| const [internalShowSchematicDebugGrid, setInternalShowSchematicDebugGrid] = | |
| useState(showSchematicDebugGridProp) | |
| const [internalShowSchematicPorts, setInternalShowSchematicPorts] = useState( | |
| showSchematicPortsProp, | |
| ) | |
| useEffect(() => { | |
| if (!onChangeShowSchematicDebugGrid) { | |
| setInternalShowSchematicDebugGrid(showSchematicDebugGridProp) | |
| } | |
| }, [showSchematicDebugGridProp, onChangeShowSchematicDebugGrid]) | |
| useEffect(() => { | |
| if (!onChangeShowSchematicPorts) { | |
| setInternalShowSchematicPorts(showSchematicPortsProp) | |
| } | |
| }, [showSchematicPortsProp, onChangeShowSchematicPorts]) |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
|
@Ayushjhawar8 this isn't working, can you look into it? we just need to get the view menu working so the user can toggle on schematic ports and stuff, there might be a keying issue or something idk https://schematic-viewer.vercel.app/?fixtureId=%7B%22path%22%3A%22examples%2Fexample17-schematic-ports.fixture.tsx%22%7D |
| solverEvents={solverEvents} | ||
| showSchematicDebugGrid={showSchematicDebugGrid} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChangeShowSchematicDebugGrid={setShowSchematicDebugGrid}
onChangeShowSchematicPorts={setShowSchematicPorts}
i think we need to add these here aswell as without them, CircuitJsonPreview would using its internal state instead of RunFrame 's state, which might be causing the View menu toggles to be disconnected from the SchematicViewer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@seveibar Please check |
|
nice |

No description provided.