Skip to content

[Bug]: gadgets request fires with empty reduction on initial load (400) #126

Description

@wrigjl

Summary

On initial page load a gadget-map request fires before a reduction is chosen, sending an empty reduction query param, which the backend correctly rejects with 400.

Observed error

POST https://redux.isu.edu/api/redux/ProblemProvider/gadgets?reduction=  →  400

Response body from production:

{
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": { "reduction": ["The reduction field is required."] }
}

(With a valid reduction and instance the same endpoint returns 200, so this is purely the empty-param case.)

Root cause

In components/widgets/VisualizationLogic.js, the effect that builds the gadget map is guarded only by problemInstance && problemDatanot by chosenReductionType:

useEffect(() => {
  if (problemInstance && problemData) {              // <-- missing chosenReductionType
    setLoadingMap(true);
    processReductions(url, chosenReductionType, problemInstance)
      .then(/* ... */)
      .finally(() => setLoadingMap(false));
  }
}, [problemData, url, chosenReductionType, problemInstance]);

On boot, problemData / problemInstance populate before chosenReductionType, so processReductions(url, "", ...) runs and calls requestGadgetMap(url, "", ...)gadgets?reduction=.

Proposed fix

Add chosenReductionType to the guard so the request only fires once a reduction is selected:

if (chosenReductionType && problemInstance && problemData) {

The parallel effect a few lines down (the visualizationState.reductionOn block, also calling processReductions) has the same gap and should get the same guard.

Environment

Frontend (this repo) proxied to the production backend at https://redux.isu.edu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions