Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Compatibility: Ensure useRef usage includes an argument. #38765

Merged
merged 5 commits into from
Aug 9, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

React 19 compatibility: Making sure useRef includes an argument.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const InPlaceConnection = props => {
} = props;
let { height = '300' } = props;

const iframeWrapRef = useRef();
const iframeRef = useRef();
const iframeWrapRef = useRef( undefined );
const iframeRef = useRef( undefined );

/**
* Handles messages received from inside the iframe.
Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/connection/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automattic/jetpack-connection",
"version": "0.34.1",
"version": "0.34.2-alpha",
"description": "Jetpack Connection Component",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/connection/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

React 19 compatibility: Making sure useRef includes an argument.
2 changes: 1 addition & 1 deletion projects/packages/forms/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-forms",
"version": "0.32.7",
"version": "0.32.8-alpha",
"description": "Jetpack Forms",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/forms/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useJetpackFieldStyles } from './use-jetpack-field-styles';

const JetpackDropdown = ( { attributes, clientId, isSelected, name, setAttributes } ) => {
const { id, label, options, required, requiredText, toggleLabel, width } = attributes;
const optionsWrapper = useRef();
const optionsWrapper = useRef( undefined );
const formStyle = useFormStyle( clientId );

const classes = clsx( 'jetpack-field jetpack-field-dropdown', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRef } from '@wordpress/element';

export const withStyleVariables = WrappedComponent => props => {
const { generateStyleVariables } = window.jetpackForms;
const componentRef = useRef();
const componentRef = useRef( undefined );

return (
<WrappedComponent
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/class-jetpack-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class Jetpack_Forms {

const PACKAGE_VERSION = '0.32.7';
const PACKAGE_VERSION = '0.32.8-alpha';

/**
* Load the contact form module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const SwitchTransition = ( { activeViewKey, children, duration, ...props }, ref
const [ viewKey, setViewKey ] = useState( activeViewKey );
const [ activeView, setActiveView ] = useState( 0 );

const refA = useRef();
const refB = useRef();
const refA = useRef( undefined );
const refB = useRef( undefined );

useEffect( () => {
if ( viewKey === activeViewKey ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import GoogleDriveExport from './google-drive';
import './style.scss';

const ExportModal = ( { isVisible, onClose } ) => {
const backdrop = useRef();
const backdrop = useRef( undefined );

const selected = useSelect( select => select( STORE_NAME ).getSelectedResponseIds(), [] );
const { query } = useFeedbackQuery();
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/dashboard/inbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const TABS = [
];

const Inbox = () => {
const stickySentinel = useRef();
const stickySentinel = useRef( undefined );
const [ responseAnimationDirection, setResponseAnimationDirection ] = useState( 1 );
const [ showExportModal, setShowExportModal ] = useState( false );
const [ isSticky, setSticky ] = useState( false );
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/dashboard/inbox/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { formatFieldName, formatFieldValue, getDisplayName } from './util';
const InboxResponse = ( { loading, response } ) => {
const [ emailCopied, setEmailCopied ] = useState( false );

const ref = useRef();
const ref = useRef( undefined );

useEffect( () => {
if ( ! ref.current ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

React 19 compatibility: Making sure useRef includes an argument.
2 changes: 1 addition & 1 deletion projects/packages/videopress/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-videopress",
"version": "0.23.30",
"version": "0.23.31-alpha",
"description": "VideoPress package",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/videopress/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/videopress/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* The Package_Version class.
*/
class Package_Version {
const PACKAGE_VERSION = '0.23.30';
const PACKAGE_VERSION = '0.23.31-alpha';

const PACKAGE_SLUG = 'videopress';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function Player( { isSelected, attributes } ) {
const [ isPlayerReady, setIsPlayerReady ] = useState( false );
const [ token, setToken ] = useState();
const [ previewCheckAttempts, setPreviewCheckAttempts ] = useState( 0 );
const previewCheckTimer = useRef();
const previewCheckTimer = useRef( undefined );

// Fetch token for a VideoPress GUID
useEffect( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ React custom hook to listen and control the video player through events provided

```jsx
function myVideoComponent( { id, guid } ) {
const iframeRef = useRef();
const iframeRef = useRef( undefined );
const { playerIsReady } = useVideoPlayer( iframeRef, isRequestingPreview );

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react'
const Timer = ( { label, timeClassName, expiryDate } ) => {
const date = useMemo( () => new Date( expiryDate ), [ expiryDate ] );
const [ duration, setDuration ] = useState( date - Date.now() );
const intervalRef = useRef();
const intervalRef = useRef( undefined );

const tick = useCallback( () => {
setDuration( date - Date.now() );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

React 19 compatibility: Making sure useRef includes an argument.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const useAIAssistant = ( {
const postId = useSelect( select => select( 'core/editor' ).getCurrentPostId() );

const updatedMessages = useRef( [] );
const lastUserPrompt = useRef();
const lastUserPrompt = useRef( undefined );

const onSuggestion = detail => {
// Remove the delimiter from the suggestion and update the block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function useRecommendations( enabled = false ) {
const [ isLoading, setIsLoading ] = useState( false );
const [ errorMessage, setErrorMessage ] = useState( null );
const [ recommendations, setRecommendations ] = useState( [] );
const abortControllerRef = useRef();
const abortControllerRef = useRef( undefined );

useEffect( () => {
if ( ! enabled ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function useSubscriptions( { ignore_user_blogs } ) {
const [ isLoading, setIsLoading ] = useState( false );
const [ errorMessage, setErrorMessage ] = useState( null );
const [ subscriptions, setSubscriptions ] = useState( [] );
const abortControllerRef = useRef();
const abortControllerRef = useRef( undefined );

useEffect( () => {
setIsLoading( true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Edit = ( { attributes, clientId, isSelected, setAttributes } ) => {
let sizes = null;

const blockProps = useBlockProps();
const juxtaposeRef = useRef();
const juxtaposeRef = useRef( undefined );
if ( useResizeObserver ) {
// Let's look for resize so we can trigger the thing.
[ resizeListener, sizes ] = useResizeObserver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function ImageTransition( { src, alt, spacing } ) {
const [ loaded, setLoaded ] = useState( false );
const [ containerHeight, setContainerHeight ] = useState( 'auto' );

const img = useRef();
const img = useRef( undefined );

const onImageLoad = () => {
setLoaded( true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useMapkit } from '../mapkit/hooks';
const placeholderText = __( 'Add a marker…', 'jetpack' );

const MapkitLocationSearch = ( { label, onAddPoint } ) => {
const containerRef = useRef();
const textRef = useRef();
const containerRef = useRef( undefined );
const textRef = useRef( undefined );
const { mapkit } = useMapkit();
const search = new mapkit.Search( {
includePointsOfInterest: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from '@wordpress/element';

export default function usePrevious( value ) {
const ref = useRef();
const ref = useRef( undefined );

useEffect( () => {
ref.current = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const PodcastPlayerEdit = ( {
const [ defaultMaxItems, setDefaultMaxItems ] = useState( 10 );

// State.
const cancellableFetch = useRef();
const cancellableFetch = useRef( undefined );
const [ { selectedGuid, checkUrl, ...state }, dispatch ] = useReducer( podcastPlayerReducer, {
editedUrl: url || '',
isEditing: ! url && ! exampleFeedData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function ExpandableSandbox( {
playerQuerySelector,
children,
} ) {
const rootElementRef = useRef();
const modalRef = useRef();
const rootElementRef = useRef( undefined );
const modalRef = useRef( undefined );
const [ lastScrollPosition, setLastScrollPosition ] = useState( null );
const shouldUseFullscreenAPI = isMobile && fullscreenAPI.enabled();
const isFullPageModalOpened = fullscreen && ! shouldUseFullscreenAPI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback, useEffect, useRef } from '@wordpress/element';

const useLongPress = callback => {
const touchTimer = useRef();
const targetElement = useRef();
const touchTimer = useRef( undefined );
const targetElement = useRef( undefined );
const savedCallback = useRef( callback );

const preventGhostClick = useCallback( event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function PlayerUI( { id, slides, metadata, disabled } ) {
[ id ]
);

const slideContainerRef = useRef();
const slideContainerRef = useRef( undefined );
const [ maxSlideWidth, setMaxSlideWidth ] = useState( null );
const [ resizeListener, { width, height } ] = useResizeObserver();
const [ targetAspectRatio, setTargetAspectRatio ] = useState( settings.defaultAspectRatio );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default createHigherOrderComponent(
const { name } = useBlockEditContext();
const usableBlocksProps = getUsableBlockProps( name );

const preUploadFile = useRef();
const preUploadFile = useRef( undefined );
if ( ! usableBlocksProps?.mediaReplaceFlow || ! isUpgradable( name ) ) {
return <MediaReplaceFlow { ...props } />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useSiteLogo from '../hooks/use-site-logo.js';
* @returns {Component} The react component.
*/
export function QRPost() {
const wrapperElementRef = useRef();
const wrapperElementRef = useRef( undefined );

// Pick and convert Jetpack logo to data image.
const [ jetpackLogoUrl, setJetpackLogo ] = useState();
Expand Down Expand Up @@ -59,7 +59,7 @@ export function QRPost() {
}

export function QRPostButton() {
const qrCodeRef = useRef();
const qrCodeRef = useRef( undefined );
const [ isModalOpen, setIsModalOpen ] = useState( false );
const switchModal = () => setIsModalOpen( v => ! v );
const closeModal = () => setIsModalOpen( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function AudioPlayer( {
loadWhenReady = false,
preload = 'metadata',
} ) {
const audioRef = useRef();
const audioRef = useRef( undefined );

/**
* Play current audio.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function OpenverseMedia( props ) {
[ getMedia, searchQuery ]
);

const previousSearchQueryValue = useRef();
const previousSearchQueryValue = useRef( undefined );
const onSearch = useCallback(
event => {
event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function PexelsMedia( props ) {
[ getMedia, searchQuery ]
);

const previousSearchQueryValue = useRef();
const previousSearchQueryValue = useRef( undefined );
const onSearch = useCallback(
event => {
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/extensions/shared/use-width.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from '@wordpress/element';

const usePrevious = value => {
const ref = useRef();
const ref = useRef( undefined );

useEffect( () => {
ref.current = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

React 19 compatibility: Making sure useRef includes an argument.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useMigrationstatus( restApi: {
fetchMigrationStatus: () => Promise< MigrationStatus >;
} ): MigrationStatus {
const FETCH_INTERVAL = 3000;
const activeIntervalId = useRef();
const activeIntervalId = useRef( undefined );
const [ migrationStatus, setMigrationStatus ] = useState();

const clearActiveInterval = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

React 19 compatibility: Making sure useRef includes an argument.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const NavigationList = ( { children } ) => (
);

const NavigationDropdown = ( { children, data } ) => {
const ref = useRef();
const ref = useRef( undefined );
const [ listOpen, setListOpen ] = useState( false );
const item = data?.items?.find( navItem => navItem?.id === data?.selectedItem ) ?? {
label: __( 'See all results', 'jetpack-protect' ),
Expand Down
Loading