Skip to content

Commit

Permalink
Maybe hacky fix for double load bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 10, 2024
1 parent 3638473 commit 03e1936
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/DoomCanvas/DoomCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { HydraMultiplayerClient } from "../../utils/HydraMultiplayer/client.js";
import cx from "classnames";
import { NETWORK_ID } from "../../constants.js";

let alreadyFetched: NewGameResponse | undefined = undefined;

const DoomCanvas: React.FC = () => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const {
Expand All @@ -33,7 +35,7 @@ const DoomCanvas: React.FC = () => {
const [isLoading, setIsLoading] = useState(true);
const mutationKey = useMemo(
() => ["fetchGameData", address, code, type],
[address, code, type],
["fetchGameData", address, code, type],
);

const {
Expand All @@ -48,8 +50,14 @@ const DoomCanvas: React.FC = () => {
}
const url =
type === EGameType.HOST ? newGame(address!) : addPlayer(address!, code);
const response = await fetch(url);
return response.json();
if (!!alreadyFetched) {
return alreadyFetched;
} else {
console.log("fetching", mutationKey);
const response = await fetch(url);
alreadyFetched = await response.json();
return alreadyFetched as any;
}
},
});

Expand Down

0 comments on commit 03e1936

Please sign in to comment.