Repository navigation
diagram: convert drawing components to function components - #722
Merged
Merged
Conversation
Convert the twelve PureComponent classes under drawing/ (everything but Canvas) to memo'd function components. None of them held real state: Sparkline's hand-rolled recache()/cachedSeries instance-field cache becomes a useMemo (now correctly keyed on width/height too, not just series identity), Label's transient pointer-gesture fields become refs (deliberately not state -- a drag must not re-render the label), and EditableLabel's constructor-created Slate editor becomes a useState lazy initializer with the same init-once-per-mount semantics. Handlers passed to memo'd children (Label, Arrowhead) are wrapped in useCallback so React.memo actually holds; handlers attached only to DOM elements stay as plain closures. Connector's static methods move to module-level functions (isStraightLine, intersectElementStraight, connectorBounds), matching how the rest of the file's geometry already lives; tests now import them directly. Canvas stays a class for now -- its hooks migration is sequenced after the canvas-interaction.ts state migration (gated on e2e gesture tests) to avoid migrating it twice. The SVG parity test (byte-identical Rust-vs-TS rendering) plus the existing geometry suites are the regression net; render output is unchanged. docs/dev/typescript.md now prefers function components, replacing the stale class-components-by-default guidance.
|
Reviewed the PR. The class-to-function-component conversion looks correct and behavior-preserving:
No findings. Overall correctness: correct. |
This was referenced Jun 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts the twelve
React.PureComponentclasses undersrc/diagram/drawing/(everything except Canvas) to memo'd function components, continuing the front-end cleanup after #721. The intent is zero behavior change; the byte-identical Rust-vs-TS SVG parity test (tests/svg-rendering.test.ts) plus the existing geometry suites are the regression net.Highlights:
useCallbacksoReact.memoactually holds during drags; handlers attached only to DOM elements stay plain closures.recache()/cachedSeriesinstance-field cache becomes auseMemo(now correctly keyed on width/height too, fixing a latent staleness bug).pointerId/inMove) become refs — deliberately not state, so a drag never re-renders the label.useStatelazy initializer; Canvas mounts it per edit session, so init-once-per-mount semantics are preserved.isStraightLine,intersectElementStraight,connectorBounds), matching how the rest of the file's geometry already lives; tests import them directly.Canvas stays a class on purpose: its hooks migration is sequenced after the
canvas-interaction.tsstate migration (gated on e2e gesture tests, tech-debt #65) to avoid migrating it twice.Test plan
@simlin/diagram: 72 suites / 1023 tests green, including the five-model byte-identical SVG parity test that exercises every converted component throughrenderToString.