1- import { HTMLAttributes , useState , useCallback } from "react"
1+ import { HTMLAttributes , useState , useCallback , useEffect , useId } from "react"
22import { useAppTranslation } from "@/i18n/TranslationContext"
33import { vscode } from "@/utils/vscode"
44import { VSCodeCheckbox , VSCodeLink , VSCodeButton } from "@vscode/webview-ui-toolkit/react"
@@ -66,6 +66,11 @@ export const TerminalSettings = ({
6666
6767 const [ inheritEnv , setInheritEnv ] = useState < boolean > ( true )
6868 const [ profileNames , setProfileNames ] = useState < string [ ] > ( [ ] )
69+ const [ isProfilesLoaded , setIsProfilesLoaded ] = useState ( false )
70+ const profileModeId = useId ( )
71+ const defaultProfileId = `${ profileModeId } -default`
72+ const overrideProfileId = `${ profileModeId } -override`
73+ const isProfileOverrideSelected = ! ! terminalProfile && ( ! isProfilesLoaded || profileNames . includes ( terminalProfile ) )
6974
7075 useMount ( ( ) => {
7176 vscode . postMessage ( { type : "getVSCodeSetting" , setting : "terminal.integrated.inheritEnv" } )
@@ -85,6 +90,7 @@ export const TerminalSettings = ({
8590 break
8691 case "terminalProfiles" :
8792 setProfileNames ( message . profiles ?? [ ] )
93+ setIsProfilesLoaded ( true )
8894 break
8995 default :
9096 break
@@ -93,6 +99,12 @@ export const TerminalSettings = ({
9399
94100 useEvent ( "message" , onMessage )
95101
102+ useEffect ( ( ) => {
103+ if ( isProfilesLoaded && terminalProfile && ! profileNames . includes ( terminalProfile ) ) {
104+ setCachedStateField ( "terminalProfile" , undefined )
105+ }
106+ } , [ isProfilesLoaded , profileNames , setCachedStateField , terminalProfile ] )
107+
96108 return (
97109 < div className = { cn ( "flex flex-col" , className ) } { ...props } >
98110 < SectionHeader > { t ( "settings:sections.terminal" ) } </ SectionHeader >
@@ -167,13 +179,13 @@ export const TerminalSettings = ({
167179 < div className = "flex items-center gap-2 mb-2" >
168180 < input
169181 type = "radio"
170- id = "terminal-profile-default"
171- name = "terminal-profile-mode"
172- checked = { ! terminalProfile }
182+ id = { defaultProfileId }
183+ name = { profileModeId }
184+ checked = { ! isProfileOverrideSelected }
173185 onChange = { ( ) => setCachedStateField ( "terminalProfile" , undefined ) }
174186 data-testid = "terminal-profile-default-radio"
175187 />
176- < label htmlFor = "terminal-profile-default" className = "cursor-pointer" >
188+ < label htmlFor = { defaultProfileId } className = "cursor-pointer" >
177189 { t ( "settings:terminal.profile.default" ) }
178190 </ label >
179191 < VSCodeButton
@@ -191,9 +203,9 @@ export const TerminalSettings = ({
191203 < div className = "flex items-center gap-2 mb-2" >
192204 < input
193205 type = "radio"
194- id = "terminal-profile-override"
195- name = "terminal-profile-mode"
196- checked = { ! ! terminalProfile }
206+ id = { overrideProfileId }
207+ name = { profileModeId }
208+ checked = { isProfileOverrideSelected }
197209 disabled = { profileNames . length === 0 }
198210 onChange = { ( ) => {
199211 if ( ! terminalProfile && profileNames . length > 0 ) {
@@ -203,7 +215,7 @@ export const TerminalSettings = ({
203215 data-testid = "terminal-profile-override-radio"
204216 />
205217 < label
206- htmlFor = "terminal-profile-override"
218+ htmlFor = { overrideProfileId }
207219 className = {
208220 profileNames . length === 0
209221 ? "cursor-not-allowed text-vscode-disabledForeground"
@@ -220,7 +232,7 @@ export const TerminalSettings = ({
220232 ) }
221233 </ div >
222234
223- { ! ! terminalProfile && profileNames . length > 0 && (
235+ { isProfileOverrideSelected && profileNames . length > 0 && (
224236 < Select
225237 value = { terminalProfile || DEFAULT_PROFILE_VALUE }
226238 data-testid = "terminal-profile-dropdown"
0 commit comments