Skip to content

Fix React key and ref console errors in Report Debug Page #61776

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

Merged
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
1 change: 1 addition & 0 deletions src/components/SidePanel/HelpModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Help({sidePanelTranslateX, closeSidePanel, shouldHideSidePanelBackdrop}
const styles = useThemeStyles();
const {isExtraLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const {paddingTop, paddingBottom} = useSafeAreaPaddings();

const [isRHPVisible = false] = useOnyx(ONYXKEYS.MODAL, {selector: (modal) => modal?.type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED, canBeMissing: true});
const uniqueModalId = useMemo(() => ComposerFocusManager.getId(), []);

Expand Down
13 changes: 10 additions & 3 deletions src/pages/Debug/ConstantSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {useRoute} from '@react-navigation/native';
import React, {useEffect} from 'react';
import type {ForwardedRef} from 'react';
import React, {forwardRef, useEffect} from 'react';
import type {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -29,7 +31,12 @@ type ConstantSelectorProps = {
policyID?: string;
};

function ConstantSelector({formType, policyID, errorText = '', name, value, onInputChange}: ConstantSelectorProps) {
function ConstantSelector(
{formType, policyID, errorText = '', name, value, onInputChange}: ConstantSelectorProps,
// The ref is required by React.forwardRef to avoid warnings, even though it's not used yet.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ref: ForwardedRef<View>,
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to specify this param here. rever this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @parasharrajat, just to clarify—are you suggesting I remove the ref parameter itself, or just the comment associated with it?

As I mentioned in my proposal, removing the ref parameter introduces another warning. Could you please confirm your intention?

Copy link
Member

Choose a reason for hiding this comment

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

Let me check that warning.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like we need it.

) {
const fieldValue = (useRoute().params as Record<string, string> | undefined)?.[name];

useEffect(() => {
Expand Down Expand Up @@ -64,4 +71,4 @@ function ConstantSelector({formType, policyID, errorText = '', name, value, onIn

ConstantSelector.displayName = 'ConstantSelector';

export default ConstantSelector;
export default forwardRef(ConstantSelector);
13 changes: 10 additions & 3 deletions src/pages/Debug/DateTimeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {useRoute} from '@react-navigation/native';
import React, {useEffect} from 'react';
import type {ForwardedRef} from 'react';
import React, {forwardRef, useEffect} from 'react';
import type {View} from 'react-native';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
Expand All @@ -23,7 +25,12 @@ type DateTimeSelectorProps = {
inputID: string;
};

function DateTimeSelector({errorText = '', name, value, onInputChange}: DateTimeSelectorProps) {
function DateTimeSelector(
{errorText = '', name, value, onInputChange}: DateTimeSelectorProps,
// The ref is required by React.forwardRef to avoid warnings, even though it's not used yet.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ref: ForwardedRef<View>,
Comment on lines +28 to +32
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

) {
const fieldValue = (useRoute().params as Record<string, string> | undefined)?.[name];

useEffect(() => {
Expand Down Expand Up @@ -58,4 +65,4 @@ function DateTimeSelector({errorText = '', name, value, onInputChange}: DateTime

DateTimeSelector.displayName = 'DateTimeSelector';

export default DateTimeSelector;
export default forwardRef(DateTimeSelector);
5 changes: 4 additions & 1 deletion src/pages/Debug/DebugDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type DebugDetailsProps = {
function DebugDetails({formType, data, policyHasEnabledTags, policyID, children, onSave, onDelete, validate}: DebugDetailsProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [formDraftData] = useOnyx(ONYXKEYS.FORMS.DEBUG_DETAILS_FORM_DRAFT);
const [formDraftData] = useOnyx(ONYXKEYS.FORMS.DEBUG_DETAILS_FORM_DRAFT, {canBeMissing: true});
const booleanFields = useMemo(
() =>
Object.entries(data ?? {})
Expand Down Expand Up @@ -167,6 +167,7 @@ function DebugDetails({formType, data, policyHasEnabledTags, policyID, children,
const numberOfLines = DebugUtils.getNumberOfLinesFromString((formDraftData?.[key as keyof typeof formDraftData] as string) ?? value);
return (
<InputWrapper
key={key}
InputComponent={TextInput}
inputID={key}
accessibilityLabel={key}
Expand All @@ -187,6 +188,7 @@ function DebugDetails({formType, data, policyHasEnabledTags, policyID, children,
<View style={[styles.mb5, styles.ph5, styles.gap5]}>
{numberFields.map(([key, value]) => (
<InputWrapper
key={key}
InputComponent={TextInput}
inputID={key}
accessibilityLabel={key}
Expand Down Expand Up @@ -234,6 +236,7 @@ function DebugDetails({formType, data, policyHasEnabledTags, policyID, children,
<View style={[styles.mb5, styles.ph5, styles.gap5]}>
{booleanFields.map(([key, value]) => (
<InputWrapper
key={key}
InputComponent={CheckboxWithLabel}
label={key}
inputID={key}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Debug/Report/DebugReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ function DebugReportPage({
>
<View style={[styles.mb5, styles.ph5, styles.gap5]}>
{metadata?.map(({title, subtitle, message, action}) => (
<View style={[StyleUtils.getBackgroundColorStyle(theme.cardBG), styles.p5, styles.br4, styles.flexColumn, styles.gap2]}>
<View
key={title}
style={[StyleUtils.getBackgroundColorStyle(theme.cardBG), styles.p5, styles.br4, styles.flexColumn, styles.gap2]}
>
<View style={[styles.flexRow, styles.justifyContentBetween]}>
<Text style={styles.h4}>{title}</Text>
<Text>{subtitle}</Text>
Expand Down