From 33740af5eed11fc773ee6e24fa5603ba7e4388c7 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 1 Nov 2021 16:19:17 -0700 Subject: [PATCH] Stop passing null value in SpeciesColorPicker This is a minor change to clear a console warning, and make intended behavior clearer! You're not supposed to pass `null` as a select value, because it's ambiguous about whether you're looking for the first option or to make this an "uncontrolled component". Here, I now provide a fallback value, which is an explicit string for the placeholder option. I made the string very explicit, to aid in debugging if it somehow leaks out from where it's supposed to be! (But I also added gating in the `onChange` event, just to be extra sure.) --- src/app/components/SpeciesColorPicker.js | 26 ++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/app/components/SpeciesColorPicker.js b/src/app/components/SpeciesColorPicker.js index 5746a03..0dd915f 100644 --- a/src/app/components/SpeciesColorPicker.js +++ b/src/app/components/SpeciesColorPicker.js @@ -89,6 +89,13 @@ function SpeciesColorPicker({ newColorId, }); + // Ignore switching to the placeholder option. It shouldn't generally be + // doable once real options exist, and it doesn't represent a valid or + // meaningful transition in the case where it could happen. + if (newColorId === "SpeciesColorPicker-color-loading-placeholder") { + return; + } + const species = allSpecies.find((s) => s.id === speciesId); const newColor = allColors.find((c) => c.id === newColorId); const validPoses = getValidPoses(valids, speciesId, newColorId); @@ -119,6 +126,13 @@ function SpeciesColorPicker({ colorId, }); + // Ignore switching to the placeholder option. It shouldn't generally be + // doable once real options exist, and it doesn't represent a valid or + // meaningful transition in the case where it could happen. + if (newSpeciesId === "SpeciesColorPicker-species-loading-placeholder") { + return; + } + const newSpecies = allSpecies.find((s) => s.id === newSpeciesId); if (!newSpecies) { // Trying to isolate Sentry issue IMPRESS-2020-1H, where an empty species @@ -177,7 +191,7 @@ function SpeciesColorPicker({ c.id === colorId) && ( - + ) } { @@ -214,7 +230,7 @@ function SpeciesColorPicker({ s.id === speciesId) && ( - + ) } {