Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"eslint-plugin-jest": "27.4.3",
"eslint-plugin-jest-dom": "5.0.2",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react-compiler": "19.0.0-beta-0dec889-20241115",
"eslint-plugin-react-compiler": "19.0.0-beta-ebf51a3-20250411",
"eslint-plugin-ssr-friendly": "1.0.6",
"eslint-plugin-storybook": "0.6.13",
"eslint-plugin-testing-library": "6.0.2",
Expand Down
7 changes: 0 additions & 7 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ function LinkControl( {
const isMountingRef = useRef( true );
const wrapperNode = useRef();
const textInputRef = useRef();
const isEndingEditWithFocusRef = useRef( false );

@t-hamano t-hamano Apr 19, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ref was originally used as part of a conditional statement to prevent focus loss: d66d53b?diff=unified#diff-278587d24f4060dd3b05ef00adba5f9afdda8fe5b52a8587005b5012a9fc8df0R115

However, since the conditional statement itself has been removed, this ref is no longer used anywhere: https://github.com/WordPress/gutenberg/pull/32552/files#diff-278587d24f4060dd3b05ef00adba5f9afdda8fe5b52a8587005b5012a9fc8df0L158-L167


const settingsKeys = settings.map( ( { id } ) => id );

Expand Down Expand Up @@ -235,8 +234,6 @@ function LinkControl( {
wrapperNode.current;

nextFocusTarget.focus();

isEndingEditWithFocusRef.current = false;
}, [ isEditingLink, isCreatingPage ] );

// The component mounting reference is maintained separately
Expand All @@ -256,10 +253,6 @@ function LinkControl( {
* the next render, if focus was within the wrapper when editing finished.
*/
const stopEditing = () => {
isEndingEditWithFocusRef.current = !! wrapperNode.current?.contains(
wrapperNode.current.ownerDocument.activeElement
);

setIsEditingLink( false );
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useMemo, useRef, useInsertionEffect } from '@wordpress/element';
import { useMemo, useState, useInsertionEffect } from '@wordpress/element';
import { useRefEffect } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -34,13 +34,16 @@ const allEventListeners = [
];

export function useEventListeners( props ) {
const propsRef = useRef( props );
const [ state, setState ] = useState( props );
useInsertionEffect( () => {
propsRef.current = props;
setState( props );
} );
const refEffects = useMemo(
() => allEventListeners.map( ( refEffect ) => refEffect( propsRef ) ),
[ propsRef ]
() =>
allEventListeners.map( ( refEffect ) =>
refEffect( { current: state } )
),
[ state ]
);

return useRefEffect(
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function UnforwardedModal(
// Keeps a fresh ref for the subsequent effect.
const onRequestCloseRef = useRef< ModalProps[ 'onRequestClose' ] >();
useEffect( () => {
// eslint-disable-next-line react-compiler/react-compiler
onRequestCloseRef.current = onRequestClose;
}, [ onRequestClose ] );

Expand Down
14 changes: 1 addition & 13 deletions packages/components/src/palette-edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import {
useState,
useRef,
useEffect,
useCallback,
useMemo,
} from '@wordpress/element';
import { useState, useRef, useCallback, useMemo } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
import { useDebounce } from '@wordpress/compose';
Expand Down Expand Up @@ -296,12 +290,6 @@ function PaletteEditListView< T extends PaletteElement >( {
popoverProps,
addColorRef,
}: PaletteEditListViewProps< T > ) {
// When unmounting the component if there are empty elements (the user did not complete the insertion) clean them.
const elementsReferenceRef = useRef< typeof elements >();
useEffect( () => {
elementsReferenceRef.current = elements;
}, [ elements ] );

Comment on lines -299 to -304

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ref was originally used as part of a conditional statement: https://github.com/WordPress/gutenberg/pull/36820/files#diff-3749f548d9b617ffd46aadb474aae082c8e26ce9bab26599e892f2fd9f2f1b35R160

However, since the conditional statement itself has been removed, this ref is no longer used anywhere.

const debounceOnChange = useDebounce(
( updatedElements: T[] ) =>
onChange( deduplicateElementSlugs( updatedElements ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import useRefEffect from '../use-ref-effect';
function useUpdatedRef( value ) {
const ref = useRef( value );
useLayoutEffect( () => {
// eslint-disable-next-line react-compiler/react-compiler
ref.current = value;
}, [ value ] );
return ref;
Expand Down
13 changes: 8 additions & 5 deletions packages/rich-text/src/component/event-listeners/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useMemo, useRef, useInsertionEffect } from '@wordpress/element';
import { useMemo, useState, useInsertionEffect } from '@wordpress/element';
import { useRefEffect } from '@wordpress/compose';

/**
Expand All @@ -26,13 +26,16 @@ const allEventListeners = [
];

export function useEventListeners( props ) {
const propsRef = useRef( props );
const [ state, setState ] = useState( props );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the warning here? This latest prop pattern should still be supported.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unit tests are failing, so this code is wrong, and it seems to need to be reverted.

However, the latest eslint-plugin-react-compiler displays a warning for this code 🤔

image

useInsertionEffect( () => {
propsRef.current = props;
setState( props );
} );
const refEffects = useMemo(
() => allEventListeners.map( ( refEffect ) => refEffect( propsRef ) ),
[ propsRef ]
() =>
allEventListeners.map( ( refEffect ) =>
refEffect( { current: state } )
),
[ state ]
);

return useRefEffect(
Expand Down