perf: remove fitContent() from reconciliation effect, call only on initial load
Move chart.timeScale().fitContent() out of the span annotation reconciliation effect (which ran on every annotation/selection change) into a dedicated effect guarded by a hasInitializedRef, so it fires only once when chart and series first become available. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
131d2912d5
commit
aa27fe93f6
2 changed files with 10 additions and 4 deletions
|
|
@ -74,6 +74,7 @@ export default function SpanAnnotationManager({
|
|||
const [editingSpan, setEditingSpan] = useState<SpanAnnotation | null>(null);
|
||||
const primitivesRef = useRef<Map<number, SpanRectanglePrimitive>>(new Map());
|
||||
const selectedSpanIdRef = useRef<number | null>(selectedSpanId);
|
||||
const hasInitializedRef = useRef(false);
|
||||
|
||||
// Keep selectedSpanIdRef in sync with prop
|
||||
useEffect(() => {
|
||||
|
|
@ -175,11 +176,16 @@ export default function SpanAnnotationManager({
|
|||
series.attachPrimitive(primitive);
|
||||
primitivesRef.current.set(span.id, primitive);
|
||||
});
|
||||
|
||||
// Request chart update
|
||||
chart.timeScale().fitContent();
|
||||
}, [spanAnnotations, selectedSpanId, series, chart, candles]);
|
||||
|
||||
// Fit chart content only on initial load when chart and series become available
|
||||
useEffect(() => {
|
||||
if (!chart || !series) return;
|
||||
if (hasInitializedRef.current) return;
|
||||
hasInitializedRef.current = true;
|
||||
chart.timeScale().fitContent();
|
||||
}, [chart, series]);
|
||||
|
||||
// Handle clicks on chart for span tool and span selection
|
||||
useEffect(() => {
|
||||
if (!chart || !series) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue