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

Consider making isValid something other than an instance method (custom widgets). #1346

Closed
knpwrs opened this issue May 9, 2018 · 4 comments

Comments

@knpwrs
Copy link

knpwrs commented May 9, 2018

When a custom widget with an isValid method is wrapped in a HOC, the following error is thrown when attemping to publish:

Uncaught TypeError: r.wrappedControlValid is not a function

It looks like wrappedControlValid is never set because my HOC is a stateless component, meaning it cannot be ref'd. The function which sets wrappedControlValid returns immediately if a ref is not possible: https://github.com/netlify/netlify-cms/blob/a5d4fd41a4a1f681b117bf6f40ce1263382680a9/src/components/Editor/EditorControlPane/Widget.js#L56-L67

I can probably temporarily fix this with toClass() from recompose, though I'd argue that instance methods on components are sort of a React anti-pattern. I think it would probably be better to pass an isValid prop to the custom widgets. This change would ideally be done in a backwards-compatible way as to not bump the major version.

@knpwrs
Copy link
Author

knpwrs commented May 9, 2018

A quick fix could be something along the lines of what glamorous does as well: allow custom widgets to accept an innerRef prop (or similar) to allow a ref to pass down through to the wrapped component. There might also be something we can do with the newer React.forwardRef API.

@erquhart
Copy link
Contributor

Agreed, definitely open to a PR for this.

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@martinjagodic
Copy link
Member

Closing as stale

@martinjagodic martinjagodic closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants