decompme / decomp.me

Collaborative decompilation and reverse engineering website

Home Page:https://decomp.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] usePreset() makes API call when scratch.preset is undefined

mkst opened this issue · comments

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:

  1. Go to any Scratch with a preset
  2. Click on Options
  3. Change the Compiler (e.g from ido5.3 to ido7.1, anything to result in a Custom preset)
  4. 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

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
}