Skip to content

Commit 462d193

Browse files
author
Richard
committed
fix: Resolve double-click bug in custom region selection
The useEffect was conflicting with manual state changes, causing users to need to click 'Custom region...' twice before the input field would appear. Fixed by only running the initialization effect on component mount rather than on every region change.
1 parent aede5ea commit 462d193

File tree

1 file changed

+12
-7
lines changed
  • webview-ui/src/components/settings/providers

1 file changed

+12
-7
lines changed

webview-ui/src/components/settings/providers/Bedrock.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,25 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
1919
const { t } = useAppTranslation()
2020
const [awsEndpointSelected, setAwsEndpointSelected] = useState(!!apiConfiguration?.awsBedrockEndpointEnabled)
2121
const [isCustomRegion, setIsCustomRegion] = useState(
22-
apiConfiguration?.awsRegion && !BEDROCK_REGIONS.some(region => region.value === apiConfiguration.awsRegion)
22+
apiConfiguration?.awsRegion && !BEDROCK_REGIONS.some((region) => region.value === apiConfiguration.awsRegion),
2323
)
2424

2525
// Update the endpoint enabled state when the configuration changes
2626
useEffect(() => {
2727
setAwsEndpointSelected(!!apiConfiguration?.awsBedrockEndpointEnabled)
2828
}, [apiConfiguration?.awsBedrockEndpointEnabled])
2929

30-
// Update custom region state when the configuration changes
30+
// Initialize custom region state on component mount
3131
useEffect(() => {
32-
const hasCustomRegion = apiConfiguration?.awsRegion &&
33-
!BEDROCK_REGIONS.some((region: { value: string; label: string }) => region.value === apiConfiguration.awsRegion && region.value !== "custom")
34-
setIsCustomRegion(!!hasCustomRegion)
35-
}, [apiConfiguration?.awsRegion])
32+
if (apiConfiguration?.awsRegion) {
33+
const isStandardRegion = BEDROCK_REGIONS.some(
34+
(region: { value: string; label: string }) =>
35+
region.value === apiConfiguration.awsRegion && region.value !== "custom",
36+
)
37+
setIsCustomRegion(!isStandardRegion)
38+
}
39+
// eslint-disable-next-line react-hooks/exhaustive-deps
40+
}, []) // Only run on mount - deliberately ignoring apiConfiguration dependency to avoid conflicts
3641

3742
const handleInputChange = useCallback(
3843
<K extends keyof ProviderSettings, E>(
@@ -98,7 +103,7 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
98103
<div>
99104
<label className="block font-medium mb-1">{t("settings:providers.awsRegion")}</label>
100105
<Select
101-
value={isCustomRegion ? "custom" : (apiConfiguration?.awsRegion || "")}
106+
value={isCustomRegion ? "custom" : apiConfiguration?.awsRegion || ""}
102107
onValueChange={(value) => {
103108
if (value === "custom") {
104109
setIsCustomRegion(true)

0 commit comments

Comments
 (0)