[BUG] usePreset() makes API call when scratch.preset is undefined
mkst opened this issue · comments
Mark Street commented
Describe the bug
We shouldn't make an API call if the value of the preset id is undefined
. This results in an error in the client's console, as well as a warning in the server logs:
GET https://decomp.me/api/preset/undefined 404 (Not Found)
To Reproduce
Steps to reproduce the behavior:
- Go to any Scratch with a preset
- Click on Options
- Change the Compiler (e.g from ido5.3 to ido7.1, anything to result in a Custom preset)
- See error message in browser's dev console
Expected behavior
I don't expect the API call to be made when we know we have an invalid preset
Alex Bates commented
possible solution: https://discord.com/channels/897066363951128586/897075447534354462/1187046605006831636
export function usePreset(id: number | undefined): Preset | undefined {
const url = typeof id === "number" ? `/preset/${id}` : null
const { data } = useSWR(url, get, {
refreshInterval: 0,
onErrorRetry,
})
return data
}