Skip to content

Commit

Permalink
fix(web): handle wrong local storage value
Browse files Browse the repository at this point in the history
Improves local storage commits loading logic by adding a check if map can be created from
parsed value.
  • Loading branch information
LordTermor committed Aug 1, 2024
1 parent 0730d70 commit 65d18fd
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions web/src/routes/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ const useLocalStoredCommits = () => {
}
return value;
};

const commitsState = useCommits(() =>
localStorage.getItem("commits")
? new Map(
JSON.parse(localStorage.getItem("commits") || "", reviver)
)
: new Map()
);

const commitsState = useCommits(() => {
const storedCommits = localStorage.getItem("commits");
if (!storedCommits) {
return new Map();
}
try {
return new Map(JSON.parse(storedCommits, reviver)) || new Map();
} catch (error) {
console.error("Error parsing commits from localStorage:", error);
return new Map();
}
});
const { commits } = commitsState;

useEffect(() => {
Expand Down

0 comments on commit 65d18fd

Please sign in to comment.