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

Improve types for animation hooks etc. #1612

Merged
merged 6 commits into from
Oct 31, 2022

Conversation

jhsware
Copy link
Contributor

@jhsware jhsware commented Oct 22, 2022

The typing for animation hooks was incomplete:

  • missing argument props in type for function components
  • missing componentWillMove hook
  • I believe domNode should accept HTMLElement | SVGElement
  • we shouldn't pass the argument props to class component componentWillMove hook (it is inconsistent with the other hook, props should be referenced using this.props)

NOTE: The last change is a BREAKING CHANGE, but I think it is better to fix it now than have it linger. Worth a bump in minor version.

While implementing this I also noted the following inconsistency in typing of argument props:

componentWillUpdate?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: S, context: any): void;

onComponentWillUpdate?(lastProps: Readonly<P>, nextProps: Readonly<P>): void;

Where children? is only added for class component hooks.

Let me know if I should change this.

@coveralls
Copy link
Collaborator

coveralls commented Oct 22, 2022

Coverage Status

Coverage remained the same at 93.27% when pulling 502afcb on jhsware:fix-types-inferno-animation into 688728e on infernojs:master.

@Havunen
Copy link
Member

Havunen commented Oct 23, 2022

Hmm, doing that breaking change aint good idea IMO. It doesnt benefit much, render method in inferno also has nextProps available so its not a big deal

@@ -206,7 +206,6 @@ export function moveVNodeDOM(parentVNode, vNode, parentDOM, nextNode, animations

if (flags & VNodeFlags.ComponentClass) {
refOrInstance = vNode.children;
instanceProps = vNode.props;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm? Why was this line removed?

Copy link
Contributor Author

@jhsware jhsware Oct 23, 2022

Choose a reason for hiding this comment

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

We shouldn't pass instance props to a Component Class since we don't do it in the other hooks (correct me if I am wrong), so I wanted to remove this inconsistency because it could cause confusion. See:

  componentDidMount?(): void;

  componentWillMount?(): void;

Copy link
Contributor Author

@jhsware jhsware Oct 23, 2022

Choose a reason for hiding this comment

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

Whereas I agree that breaking changes are bad, consistency is worth a lot, I think it is better to clean up the API early. We still have very few downloads of v8 and changing from props to this.props is intuitive. However, just updating the type definition and leaving this row would nudge people in the right direction by only throwing a type error. Then we could remove it in v9 (if we remember).

nextProps is different, because there you access current props with this.props too.

@jhsware
Copy link
Contributor Author

jhsware commented Oct 23, 2022

@Havunen what is your take on props having different types for Class Components and Function Components? Fix or don't fix?

componentWillUpdate?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: S, context: any): void;

onComponentWillUpdate?(lastProps: Readonly<P>, nextProps: Readonly<P>): void;

@Havunen
Copy link
Member

Havunen commented Oct 23, 2022

Props should have children property defined in its type

@Havunen
Copy link
Member

Havunen commented Oct 23, 2022

I think we should add context to onComponentWillUpdate too

@jhsware
Copy link
Contributor Author

jhsware commented Oct 23, 2022

Props should have children property defined in its type

Will fix

I think we should add context to onComponentWillUpdate too

Will fix

I'll need a couple of days until I have completed this.

@jhsware
Copy link
Contributor Author

jhsware commented Oct 30, 2022

@Havunen I have made the changes EXCEPT adding context to the on[xxx]Update hooks. That change broke tests and they are used both in normal and compat mode. In compat mode we don't send context (since React didn't) and I ran out of time figuring out what to change, so I backed out on the context change.

@Havunen
Copy link
Member

Havunen commented Oct 30, 2022

Great! Can you fix the conflict please :)

…props to method on Class Component (componentWillMove)
…onentWillMove. It should be referenced using this.props. This was implemented inconsistently with the other Class Component animation hooks and I think it is better to fix it now than have it linger. Worth a bump in minor version.
@jhsware
Copy link
Contributor Author

jhsware commented Oct 31, 2022

@Havunen PR rebased on master. Didn't run prettier at the end because there were many files affected that I haven't worked on. Better to run prettier separately on master.

Copy link
Member

@Havunen Havunen left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR

@Havunen Havunen merged commit 25b6ad1 into infernojs:master Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants