Skip to content

Commit

Permalink
fix: [GSW-1952] Add DOM existence check for scroll elements
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Nov 20, 2024
1 parent aa96d73 commit fe0ec2c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/web/src/views/pool/pool-detail/PoolDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ const PoolDetail: React.FC = () => {
return false;
}, [data?.incentiveType, positions]);

const isElementInDOM = (element: HTMLElement | null): boolean => {
return !!(element && document.body.contains(element));
};

const handleScroll = () => {
if (hash === "staking" && isStakable) {
const element = document.getElementById("staking");
if (element) {
if (element && isElementInDOM(element)) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
return;
Expand All @@ -65,12 +69,12 @@ const PoolDetail: React.FC = () => {
const position = positions.find(item => item.id.toString() === hash);
if (position) {
const element = document.getElementById(hash as string);
if (element) {
if (element && isElementInDOM(element)) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
} else {
const element = document.getElementById("liquidity-wrapper");
if (element) {
if (element && isElementInDOM(element)) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
}
Expand Down

0 comments on commit fe0ec2c

Please sign in to comment.