Skip to content

FeatureHighlight - migrate to new api, remove unsafe method #1290

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 6 commits into from
Jun 3, 2021

Conversation

mendyEdri
Copy link
Contributor

@mendyEdri mendyEdri commented May 5, 2021

Description

Replaced UNSAFE componentWillReceiveProps method with getDerivedStateFromProps

Changelog

Infra: FeatureHighlight migrated to newer React api, replaced UNSAFE method with getDerivedStateFromProps

const target = nextProps?.getTarget?.();
const node = FeatureHighlight.findTargetNode(target);
if (node && node !== prevState?.node) {
return {...prevState, node};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why setting all '...prevState' and not only 'node'? What else has changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

contentPosition, it works without setting it, but any future state change will be reset in prop change, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once a prop changed and getDerivedStateFromProps is called you'll get the last state in 'prevState' parameter. Think of this function as setState(), you don't need to set the whole state object again, only the part you want to change as a result of a prop change. When you don't return anything from this function, the default is 'null'. Returning null doesn't reset the state, it doesn't touch it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks!

}

componentDidUpdate() {
componentDidUpdate(nextProps) {
if (!_.isEqual(nextProps, this.props)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it really necessary to check all the props? All of them are relevant for setting the target position?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, fixed

@mendyEdri mendyEdri requested a review from Inbal-Tish May 19, 2021 15:56
@Inbal-Tish Inbal-Tish changed the title migrate to new api, remove unsafe method FeatureHighlight - migrate to new api, remove unsafe method May 20, 2021
}

componentDidUpdate() {
shouldSetTargetPosition = (nextProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like 'shouldComponentUpdate'... If it's not a pure component you can just implement that method instead and the component will not be updated if it doesn't meet the condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried it before and now again, it's not quite working.
the position of the FeatureHighlight view is getting the previous data, that's why I went with this solution.
(I even tried !_.isEqual(nextProps, this.props))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wierd. Ok...

@mendyEdri mendyEdri requested a review from Inbal-Tish June 1, 2021 11:52
@Inbal-Tish
Copy link
Collaborator

@mendyEdri Where do we stand with this PR?

@mendyEdri
Copy link
Contributor Author

@mendyEdri Where do we stand with this PR?

Fixed what needed, you can review it :)

@Inbal-Tish Inbal-Tish merged commit 152faee into master Jun 3, 2021
@mendyEdri mendyEdri deleted the infra/remove-unsafe-feature-highlight branch June 10, 2021 07:29
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.

2 participants