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

Pages Editor: Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component? #7116

Open
eatyourgreens opened this issue May 31, 2024 · 2 comments · May be fixed by #7114

Comments

@eatyourgreens
Copy link
Contributor

eatyourgreens commented May 31, 2024

Expected behavior

The app should really run in development mode without this warning (but it's only a problem in development, not production.)

Current behavior

Please include any error messages from the browser console and/or screenshots

The pages editor uses propTypes on forwardRef in a couple of places, but prop types are only allowed on React components. forwardRef(function (props, ref)) doesn't take a component as an argument, so the following prop types are ignored by React.

EditStepDialog.propTypes = {
allTasks: PropTypes.object,
deleteTask: PropTypes.func,
enforceLimitedBranchingRule: PropTypes.shape({
stepHasBranch: PropTypes.bool,
stepHasOneTask: PropTypes.bool,
stepHasManyTasks: PropTypes.bool
}),
onClose: PropTypes.func,
step: PropTypes.object,
stepIndex: PropTypes.number,
updateTask: PropTypes.func
};

NewTaskDialog.propTypes = {
addTask: PropTypes.func,
enforceLimitedBranchingRule: PropTypes.shape({
stepHasBranch: PropTypes.bool,
stepHasOneTask: PropTypes.bool,
stepHasManyTasks: PropTypes.bool
}),
openEditStepDialog: PropTypes.func,
stepIndex: PropTypes.number
};

forwardRef(function (props, ref)) returns a React component, so what you want to do is something like:

function MyComponentWithRef(props, ref) {
  return <SomeComponent ref={ref} {...props} />;
}

const MyComponent = forwardRef(MyComponentWithRef);
MyComponent.propTypes = {
/*
  Define your prop types here.
*/
}

export default MyComponent;

Steps to replicate

Load up the app in development mode and these warnings will show up near the top of the console.

Additional information

Noticed while I was chasing down some React development errors that broke #7114.

This will hopefully get easier in React 19, which gets rid of forwardRef.

@eatyourgreens eatyourgreens changed the title Pageds Editor: Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component? Pages Editor: Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component? May 31, 2024
@eatyourgreens
Copy link
Contributor Author

Pinging @shaunanoordin.

@eatyourgreens
Copy link
Contributor Author

I've included the fix for this in #7114 but I've put it in its own commit, so that you can git cherry-pick it out if you want to isolate the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant