feat(pcb-viewer): add controlled viewState API, deprecate initialState, and ship full all-features controlled fixture#695
Conversation
…e, and ship full all-features controlled fixture
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds a controlled viewState / onViewStateChange API to PCBViewer to support external synchronization of layer + visibility toggles, while deprecating the previous initialState prop. This is supported by new mapping utilities and store synchronization logic, plus an end-to-end fixture demonstrating a fully controlled setup.
Changes:
- Introduces
PCBViewerViewState, mapping utilities, and newviewState/onViewStateChangeprops (with a dev warning for deprecatedinitialState). - Updates
ContextProviders+ global store to support syncing a controlled subset of viewer state to/from the Zustand store. - Adds a new controlled fixture and refactors the all-features fixture to export reusable circuit-json generation.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/PCBViewer.tsx | Adds the public controlled view state API and bridges it into internal store state. |
| src/components/ContextProviders.tsx | Implements two-way sync between controlled props and the Zustand store. |
| src/global-store.ts | Exposes a ControlledViewState subset type and helper, and tightens useGlobalStore runtime safety. |
| src/examples/all-features.fixture.tsx | Extracts getAllFeaturesCircuitJson() for reuse by other fixtures. |
| src/examples/2026/controlled-view-state.fixture.tsx | New fixture demonstrating a fully controlled PCBViewer view state. |
| README.md | Documents the new controlled props and deprecates initialState. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
seveibar
left a comment
There was a problem hiding this comment.
we're not deprecating initialState
didn't DOPE introduce a context control pattern?
also lots of nonsense in this PR like queueMicrotask etc.
…pdate ContextProviders to handle state setting more robustly
This pull request introduces a new controlled view state API for the
PCBViewercomponent, enabling external control and synchronization of viewer state such as layer selection and visibility toggles. The new approach deprecates the previousinitialStateprop in favor of a more robustviewState/onViewStateChangepattern, and includes utilities for mapping between internal and public state representations. Additionally, it provides a fixture example demonstrating the new controlled state usage and improves type safety and code clarity throughout the codebase.https://pcb-viewer-e9onzgtj6-tscircuit.vercel.app/?fixture=%7B%22path%22%3A%22src%2Fexamples%2F2026%2Fcontrolled-view-state.fixture.tsx%22%7D
Controlled View State API:
viewStateprop andonViewStateChangecallback toPCBViewer, allowing parent components to control and react to viewer state changes (layer, visibility toggles, etc.). The previousinitialStateprop is now deprecated, with a warning in development mode. (src/PCBViewer.tsx,README.md) [1] [2] [3] [4] [5]PCBViewerViewStateand internalControlledViewStaterepresentations, ensuring seamless synchronization between external and internal state. (src/PCBViewer.tsx,src/global-store.ts) [1] [2]Context and Store Synchronization:
ContextProvidersto support controlled state, synchronizing internal store state with externalcontrolledViewStateand propagating changes back viaonControlledViewStateChange. This ensures two-way binding between parent and viewer. (src/components/ContextProviders.tsx)Examples and Documentation:
ControlledViewStateFixture) to demonstrate usage of the controlled view state API, including UI controls for toggling view options and observing state synchronization. (src/examples/2026/controlled-view-state.fixture.tsx)src/examples/all-features.fixture.tsx) [1] [2]Type Safety and Code Quality:
src/PCBViewer.tsx,src/global-store.ts) [1] [2]These changes collectively modernize the
PCBViewerAPI, making it more flexible and easier to integrate with external state management in React applications.