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.StrictMode>-compliance #1739

Closed
wants to merge 5 commits into from

Conversation

erlendfh
Copy link

@erlendfh erlendfh commented Sep 1, 2020

In reference to #1200 I've started on removing references to findDOMNode().

I've gotten ridd of all of them except one in EventContainerWrapper, which needs a larger rethink due to refs not working quite the same as findDOMNode() with components that use React.cloneElement() in render().

I've also converted the draggable context from the legacy format to using React.createContext(). A larger rewrite would probably be necessary to bring this part of the code base more in line with modern React, but this works for now.

Finally, I've replaced UNSAFE_componentWillReceiveProps() with componentDidUpdate() and getDerivedStateFromProps() equivalents.

Copy link
Owner

@jquense jquense left a comment

Choose a reason for hiding this comment

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

thanks for working on this 👍

/>
)}
</div>
<DragAndDropContext.Consumer>
Copy link
Owner

Choose a reason for hiding this comment

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

this should use static contextType where possible to avoid the extra component and instance assigning in the render fn

src/TimeGrid.js Outdated
}

UNSAFE_componentWillReceiveProps(nextProps) {
componentDidUpdate(prevProps) {
Copy link
Owner

Choose a reason for hiding this comment

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

some of this should be in a getSnapshotBeforeUpdate hook, it's important that the measuring code run before render

src/TimeGrid.js Outdated
componentDidMount() {
this.calculateScroll()
Copy link
Owner

Choose a reason for hiding this comment

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

see comment below

@erlendfh
Copy link
Author

erlendfh commented Sep 7, 2020

@jquense Thanks for the feedback, even learned a few new tricks in the process! Please take a look at the new commits when you have some time available. Any thoughts on the remaining findDOMNode() in EventContainerWrapper?

@jquense
Copy link
Owner

jquense commented Sep 8, 2020

I've gotten ridd of all of them except one in EventContainerWrapper, which needs a larger rethink due to refs not working quite the same as findDOMNode() with components that use React.cloneElement() in render().

Not sure i understand specifically what you mean here. Adding a ref via cloneElement works well enough. Is the concern that it would override an existing ref, or that the ref may be passed to a function component? For the former case mergeRefs can handle it, and for the latter case, it's a fine restriction for users that their component must accept a ref and pass it to the DOM node. As a migration path, I suggest something like: https://github.com/react-bootstrap/react-overlays/blob/master/src/safeFindDOMNode.ts which will fall back to findDOMNode if needed, which allows users to migrate at their own pace

@erlendfh
Copy link
Author

@jquense My mistake, I was of the impression that EventContainerWrapper expected an array of children, but it's a single child element, which made this a trivial fix. The examples project still has errors / warnings in the console due to an old version of Bootstrap being used, but I'm going to leave that for a separate PR as it seems at first glance to be a bit more involved than just changing the version number in package.json.

render(
<React.StrictMode>
<Example />
</React.StrictMode>,
Copy link
Owner

Choose a reason for hiding this comment

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

lets not add this to the examples

@jquense
Copy link
Owner

jquense commented Sep 21, 2020

there are a few places where code was switched to componentDidUpdate that depended on running before render, e.g. slotMetric sets and the like.

@luanraithz
Copy link

luanraithz commented Oct 30, 2020

Couldn't we throw the slotMetric stuff inside the component's state and use getDerivedStateFromProps instead of doing this manual re-initialization?

Maybe a reference

@runtothefather
Copy link

any chances to get this merged?

@ixnas
Copy link

ixnas commented Jul 8, 2022

Any updates on this? It's been a while, and it would be great to be able to use this library in StrictMode without errors.

@cutterbl
Copy link
Collaborator

cutterbl commented Jul 8, 2022

@erlendfh Thanks for your work here. I integrated your changes with current code, taking into account @jquense feedback. The only stuff I didn't use was your DnD context stuff, for now. This is in the v1.2.0 release.

@cutterbl cutterbl closed this Jul 8, 2022
@erlendfh
Copy link
Author

erlendfh commented Jul 8, 2022

Wow, what a blast from the past! Awesome to finally get this merged though 👍🏻

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 this pull request may close these issues.

6 participants