Skip to content

Commit

Permalink
fix: fix race condition with docs voting feature (#256)
Browse files Browse the repository at this point in the history
This fixes a race condition that could occasionally cause the page to
show an error if the rendering of the page completed before the request
to the voting backend API completed. This fixes this race condition by
providing stubbed / initial values in the voting context instead of
`undefined`.

The error that was occasionally reproducible": 
<img width="948" alt="image"
src="https://github.com/user-attachments/assets/1ba87db6-2aad-4879-b153-2d8dd6f3743a">
  • Loading branch information
skylarmb authored Sep 27, 2024
1 parent 43c4ac2 commit 2d3f769
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion website/context/VotingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ interface VotingContextProps {
getVoteCount: (feature: string) => number;
}

const VotingContext = createContext<VotingContextProps | undefined>(undefined);
const VotingContext = createContext<VotingContextProps>({
localStorageVotes: [],
features: [],
upvote: async () => {},
downvote: async () => {},
getVoteStatus: () => "none",
isUpvoted: () => false,
isDownvoted: () => false,
getVoteCount: () => 0,
});

const doApiRequest = async (
method: "GET" | "POST",
Expand Down

0 comments on commit 2d3f769

Please sign in to comment.