22
33import Select from '@node-core/ui-components/Common/Select' ;
44import { useTranslations } from 'next-intl' ;
5- import { useEffect , use , useMemo } from 'react' ;
5+ import { useEffect , use , useMemo , useRef } from 'react' ;
66
77import useClientContext from '#site/hooks/useClientContext' ;
88import { ReleaseContext } from '#site/providers/releaseProvider' ;
@@ -24,9 +24,15 @@ const PlatformDropdown: FC = () => {
2424 const currentPlatform =
2525 architecture && bitness ? getUserPlatform ( architecture , bitness ) : null ;
2626
27+ // Track whether the user has manually selected a platform via the dropdown.
28+ // When true the OS/version effect will respect their choice instead of
29+ // resetting to the auto-detected value.
30+ const userSelectedPlatformRef = useRef ( false ) ;
31+
2732 useEffect (
2833 ( ) => {
2934 if ( currentPlatform ) {
35+ userSelectedPlatformRef . current = false ;
3036 release . setPlatform ( currentPlatform ) ;
3137 }
3238 } ,
@@ -53,9 +59,14 @@ const PlatformDropdown: FC = () => {
5359 useEffect (
5460 ( ) => {
5561 if ( release . os !== 'LOADING' && release . platform !== '' ) {
56- // Use the current platform if available, otherwise fall back to the current release platform
57- const currentTargetPlatform = currentPlatform ?? release . platform ;
58- release . setPlatform ( nextItem ( currentTargetPlatform , parsedPlatforms ) ) ;
62+ // If the user has not manually selected a platform and there is a currently
63+ // auto-detected one then use it otherwise fallback to the current release platform
64+ const basePlatform =
65+ ! userSelectedPlatformRef . current && currentPlatform
66+ ? currentPlatform
67+ : release . platform ;
68+
69+ release . setPlatform ( nextItem ( basePlatform , parsedPlatforms ) ) ;
5970 }
6071 } ,
6172 // We only want to react on the change of the OS and Version
@@ -70,7 +81,12 @@ const PlatformDropdown: FC = () => {
7081 loading = { release . os === 'LOADING' || release . platform === '' }
7182 placeholder = { t ( 'layouts.download.dropdown.unknown' ) }
7283 ariaLabel = { t ( 'layouts.download.dropdown.platform' ) }
73- onChange = { platform => platform && release . setPlatform ( platform ) }
84+ onChange = { platform => {
85+ if ( platform ) {
86+ userSelectedPlatformRef . current = true ;
87+ release . setPlatform ( platform ) ;
88+ }
89+ } }
7490 className = "min-w-28"
7591 inline = { true }
7692 />
0 commit comments