Skip to content

Commit

Permalink
Components: Fix React Compiler error for 'useAutocomplete' (WordPress…
Browse files Browse the repository at this point in the history
…#66496)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent ffba007 commit ba17e59
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/components/src/autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function useAutocomplete( {
( ( props: AutocompleterUIProps ) => JSX.Element | null ) | null
>( null );

const backspacing = useRef( false );
const backspacingRef = useRef( false );

function insertCompletion( replacement: React.ReactNode ) {
if ( autocompleter === null ) {
Expand Down Expand Up @@ -177,7 +177,7 @@ export function useAutocomplete( {
}

function handleKeyDown( event: KeyboardEvent ) {
backspacing.current = event.key === 'Backspace';
backspacingRef.current = event.key === 'Backspace';

if ( ! autocompleter ) {
return;
Expand Down Expand Up @@ -323,7 +323,7 @@ export function useAutocomplete( {
// Ex: "Some text @marcelo sekkkk" <--- "kkkk" caused a mismatch, but
// if the user presses backspace here, it will show the completion popup again.
const matchingWhileBackspacing =
backspacing.current && wordsFromTrigger.length <= 3;
backspacingRef.current && wordsFromTrigger.length <= 3;

if ( mismatch && ! ( matchingWhileBackspacing || hasOneTriggerWord ) ) {
if ( autocompleter ) {
Expand Down

0 comments on commit ba17e59

Please sign in to comment.