From 934f3885b2811fa379ffaa0d685b42ee88571298 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Wed, 11 Nov 2026 14:03:18 +0300 Subject: [PATCH 1/3] fix (new-timeline): Fix new timeline crashing on missing categories --- .changeset/tidy-lines-render.md | 5 +++++ .../src/embeddable/new-time-line/index.jsx | 20 +++++++++++++++---- .../src/embeddable/new-time-line/timeline.jsx | 5 ++++- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 .changeset/tidy-lines-render.md diff --git a/.changeset/tidy-lines-render.md b/.changeset/tidy-lines-render.md new file mode 100644 index 00000000..3aa36777 --- /dev/null +++ b/.changeset/tidy-lines-render.md @@ -0,0 +1,5 @@ +--- +"@devgateway/dvz-ui-react": patch +--- + +Fix new timeline crashing on missing categories and re-drawing on every render by memoizing the parsed config diff --git a/packages/dvz-ui/src/embeddable/new-time-line/index.jsx b/packages/dvz-ui/src/embeddable/new-time-line/index.jsx index 8b10c8a4..966de1ba 100644 --- a/packages/dvz-ui/src/embeddable/new-time-line/index.jsx +++ b/packages/dvz-ui/src/embeddable/new-time-line/index.jsx @@ -1,6 +1,6 @@ import {PostConsumer, PostProvider} from "@devgateway/wp-react-lib"; import PostIntro from "../connected-templates/PostIntro"; -import React, {useState} from "react"; +import React, {useMemo, useState} from "react"; import {Container} from "semantic-ui-react"; import {CarouselProvider, Slide, Slider} from "pure-react-carousel"; import TimeLine from "./timeline"; @@ -54,11 +54,23 @@ const Component = (props) => { } return decodeURIComponent(value) } - + const parse = (value) => { - return JSON.parse(decode(value)) + if (value === undefined || value === null || value === "") { + return [] + } + const decoded = decode(value) + try { + return JSON.parse(decoded) + } catch (e) { + return decoded.split(",").map(v => v.trim()).filter(Boolean) + } } + // keep the same object between renders so the timeline's effect (which + // depends on `config`) only re-runs when the config actually changes + const parsedConfig = useMemo(() => JSON.parse(decodeURIComponent(config)), [config]) + const timeProps = { marginLeft, marginTop, @@ -68,7 +80,7 @@ const Component = (props) => { height: 150, position, lineColor: decode(lineColor), - config: JSON.parse(decodeURIComponent(config)), + config: parsedConfig, fontSize, titleWidth, subtitleWidth diff --git a/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx b/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx index 43a1bcbd..37bd7a87 100644 --- a/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx +++ b/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx @@ -107,6 +107,8 @@ const TimeLine = ({ /*making svg take available width*/ const svgElement = d3.select(ref.current) svgElement.attr("width", svgWidth).attr("height", svgHeight) + /* redraw from scratch when settings or posts change */ + svgElement.selectAll("*").remove() const onclick=(i)=>{ @@ -273,7 +275,8 @@ const TimeLine = ({ - }, []) + }, [config, position, lineWidth, lineColor, height, marginLeft, marginTop, marginRight, + marginBottom, fontSize, titleWidth, subtitleWidth, posts]) From e968bf6b61a5ce0f7c080debe0578d2b4e349f6b Mon Sep 17 00:00:00 2001 From: Timothy Mugo Gachengo <55899373+timothy-mugo@users.noreply.github.com> Date: Wed, 11 Nov 2026 14:27:17 +0300 Subject: [PATCH 2/3] Change return value for undefined input to undefined Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- packages/dvz-ui/src/embeddable/new-time-line/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dvz-ui/src/embeddable/new-time-line/index.jsx b/packages/dvz-ui/src/embeddable/new-time-line/index.jsx index 966de1ba..83e65399 100644 --- a/packages/dvz-ui/src/embeddable/new-time-line/index.jsx +++ b/packages/dvz-ui/src/embeddable/new-time-line/index.jsx @@ -57,7 +57,7 @@ const Component = (props) => { const parse = (value) => { if (value === undefined || value === null || value === "") { - return [] + return undefined } const decoded = decode(value) try { From 469afb8244626107ed2d5d8230506eebb0f37602 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Gachengo <55899373+timothy-mugo@users.noreply.github.com> Date: Wed, 11 Nov 2026 14:27:35 +0300 Subject: [PATCH 3/3] Update dependency array in useEffect hook Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx b/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx index 37bd7a87..e8f1cded 100644 --- a/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx +++ b/packages/dvz-ui/src/embeddable/new-time-line/timeline.jsx @@ -276,7 +276,7 @@ const TimeLine = ({ }, [config, position, lineWidth, lineColor, height, marginLeft, marginTop, marginRight, - marginBottom, fontSize, titleWidth, subtitleWidth, posts]) + marginBottom, fontSize, titleWidth, subtitleWidth, posts, currentSlide])