Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions web/src/main/javascript/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from "react";
import { useEffect, useRef, useState } from "react";
import OncoTree, { OncoTreeNode, ToolbarAction } from "@oncokb/oncotree";
import ToolbarItem from "../../components/Toolbar/ToolbarItem";

Expand All @@ -17,21 +17,22 @@ export default function Home({
}: IHomeProps) {
const treeContainerRef = useRef<HTMLDivElement>(null);
const dataRef = useRef<typeof oncoTreeData | undefined>();

const [isInitialized, setIsInitialized] = useState(false);
useEffect(() => {
const versionChanged = dataRef.current !== oncoTreeData;

if (treeContainerRef.current && versionChanged) {
if (treeContainerRef.current && versionChanged && !isInitialized) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will disable the version change functionality so we cannot add this condition.

What you are observing is not a bug. This is due to React's Strict Mode which runs each useEffect twice in development.

However, in production, you can observe a similar bug when you navigate directly to the website without the version URL param first. This is because it fetches the default version automatically, and then again when the version is set via URL param. This is definitely worth looking into. Appreciate the effort!

if (treeContainerRef.current.children.length > 0) {
treeContainerRef.current.innerHTML = "";
}

const oncoTree = new OncoTree(TREE_CONTAINER_ID, oncoTreeData);
onOncoTreeInit(oncoTree);
setIsInitialized(true);
}

dataRef.current = oncoTreeData;
}, [oncoTreeData, onOncoTreeInit]);
}, [oncoTreeData, onOncoTreeInit, isInitialized]);

return (
<>
Expand Down