@spider-analyzer/timeline 5.0.3 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-analyzer/timeline",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "React graphical component to display metric over time with a time selection feature.",
5
5
  "author": "Thibaut Raballand <spider.analyzer@gmail.com> (https://spider-analyzer.io)",
6
6
  "license": "MIT",
package/src/TimeLine.tsx CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  useCallback,
4
4
  useEffect,
5
5
  useImperativeHandle,
6
+ useMemo,
6
7
  useRef,
7
8
  useState,
8
9
  } from 'react';
@@ -887,27 +888,66 @@ const TimeLine = forwardRef<TimeLineHandle, any>(function TimeLineWrapper(props,
887
888
  else if (ret) apply(ret);
888
889
  }, [props.onLoadDefaultDomain, props.onDomainChange, zone]);
889
890
 
890
- // Build the moment-typed props the inner expects. Apply the same
891
- // defaults the inner destructures locally so that ref-path accesses
892
- // (propsRef.current.xAxis.spaceBetweenTicks etc.) never trip on an
893
- // undefined consumer prop.
891
+ // Normalize incoming props into moment-typed values the inner expects.
892
+ // MEMOIZE on the raw consumer reference so that a parent re-render
893
+ // with an unchanged `histo` (etc.) doesn't hand the inner a fresh
894
+ // object otherwise the inner's `histo !== prev` effect fires every
895
+ // render → setState → re-render → infinite loop (observed in
896
+ // Network-View: x-axis never stabilizes, loader never clears).
897
+ const timeSpanMoments = useMemo(
898
+ () => (props.timeSpan ? timeSpanToMoments(props.timeSpan, zone) : undefined),
899
+ [props.timeSpan, zone],
900
+ );
901
+ const maxDomainMoments = useMemo(
902
+ () => (props.maxDomain ? domainToMoments(props.maxDomain, zone) : undefined),
903
+ [props.maxDomain, zone],
904
+ );
905
+ const histoMoments = useMemo(
906
+ () => (props.histo?.items
907
+ ? { ...props.histo, items: props.histo.items.map((it: any) => ({ ...it, time: toMoment(it.time, zone) })) }
908
+ : props.histo),
909
+ [props.histo, zone],
910
+ );
911
+ const qualityMoments = useMemo(
912
+ () => (props.quality?.items
913
+ ? { ...props.quality, items: props.quality.items.map((it: any) => ({ ...it, time: toMoment(it.time, zone) })) }
914
+ : props.quality),
915
+ [props.quality, zone],
916
+ );
917
+ const biggestVisibleDomainDur = useMemo(
918
+ () => (props.biggestVisibleDomain != null ? toDuration(props.biggestVisibleDomain) : undefined),
919
+ [props.biggestVisibleDomain],
920
+ );
921
+ const biggestTimeSpanDur = useMemo(
922
+ () => (props.biggestTimeSpan != null ? toDuration(props.biggestTimeSpan) : undefined),
923
+ [props.biggestTimeSpan],
924
+ );
925
+ const smallestResolutionDur = useMemo(
926
+ () => (props.smallestResolution != null ? toDuration(props.smallestResolution) : undefined),
927
+ [props.smallestResolution],
928
+ );
929
+ const xAxisMerged = useMemo(
930
+ () => ({ ...xAxisDefault, ...(props.xAxis ?? {}) }),
931
+ [props.xAxis],
932
+ );
933
+ const marginMerged = useMemo(
934
+ () => ({ ...marginDefault, ...(props.margin ?? {}) }),
935
+ [props.margin],
936
+ );
937
+
894
938
  const innerProps: any = {
895
939
  ...props,
896
- xAxis: { ...xAxisDefault, ...(props.xAxis ?? {}) },
940
+ xAxis: xAxisMerged,
897
941
  yAxis: props.yAxis ?? {},
898
- margin: { ...marginDefault, ...(props.margin ?? {}) },
942
+ margin: marginMerged,
899
943
  domains: stack,
900
- timeSpan: props.timeSpan ? timeSpanToMoments(props.timeSpan, zone) : undefined,
901
- maxDomain: props.maxDomain ? domainToMoments(props.maxDomain, zone) : undefined,
902
- histo: props.histo?.items
903
- ? { ...props.histo, items: props.histo.items.map((it: any) => ({ ...it, time: toMoment(it.time, zone) })) }
904
- : props.histo,
905
- quality: props.quality?.items
906
- ? { ...props.quality, items: props.quality.items.map((it: any) => ({ ...it, time: toMoment(it.time, zone) })) }
907
- : props.quality,
908
- biggestVisibleDomain: props.biggestVisibleDomain != null ? toDuration(props.biggestVisibleDomain) : undefined,
909
- biggestTimeSpan: props.biggestTimeSpan != null ? toDuration(props.biggestTimeSpan) : undefined,
910
- smallestResolution: props.smallestResolution != null ? toDuration(props.smallestResolution) : undefined,
944
+ timeSpan: timeSpanMoments,
945
+ maxDomain: maxDomainMoments,
946
+ histo: histoMoments,
947
+ quality: qualityMoments,
948
+ biggestVisibleDomain: biggestVisibleDomainDur,
949
+ biggestTimeSpan: biggestTimeSpanDur,
950
+ smallestResolution: smallestResolutionDur,
911
951
  onUpdateDomains: handleUpdateDomains,
912
952
  onLoadDefaultDomain: handleLoadDefault,
913
953
  // onLoadHisto: object shape + Date instants