-
Notifications
You must be signed in to change notification settings - Fork 715
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
fix: Improve typing in @visx/responsive enhancers #1783
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @paolostyle 🙏 This looks great overall, had just a couple minor comments.
I did not change the actual implementation but I'm happy to contribute useParentSize and useScreenSize hooks in a separate MR which I believe would be a bit easier to use. These two HOCs could then use these hooks internally instead.
Definitely would love to see this! agree hooks are more useful these days (visx
is showing it's age 🤭)
💥 Breaking Changes: Technically for TypeScript it does contain a breaking change, you can currently manually pass parentWidth/parentHeight /screenWidth/screenHeight prop to the component wrapped in withParentSize/withScreenSize. Now whether that makes any sense is arguable as it basically invalidates entire purpose of the HOC. The actual runtime behavior did not change, it's just that now TypeScript will scream at you
thanks for noting this. also wanted to say I agree this is okay to change as this isn't desired behavior, I wouldn't mark this as a breaking version change.
Thanks for the review! I'll try to contribute the hooks when I have some free time 😊 |
7c2f140
to
5a187ee
Compare
@williaster I updated the PR with
Slightly offtopic - are there some blockers I should be aware of if I wanted to update some very old dependencies (TypeScript, Jest, JSDOM)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @paolostyle thanks for taking another pass at all of this and adding the hooks! it looks great overall 😎
I had a few relatively minor comments, and I think there's a breaking change export that's failing CI. good catch withreact <16.8
support, we use hooks in some packages but mark ^16.8
in the peer dependencies. I wonder if this even compiles now for folks on 16
, even if they don't explicitly use the hooks 🤔 I think because they were there before this change, it's okay.
I don't think there are major things to note regarding older infra that we have. lmk if you hit any issues when tinkering or refactoring, though.
enableDebounceLeadingCall: true, | ||
}; | ||
|
||
displayName = `withScreenSize(${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for improving this as well 🙏
expect(result.current).toEqual({ width: 1280, height: 1024 }); | ||
}); | ||
|
||
test('it should update the screen size on window resize', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for adding these!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the changes I had to adjust it and use real timers, Jest fake timers pre-v26 are absolutely unusable and frankly I don't have any interest in figuring out why they don't work - they were replaced for a reason. I wanted to upgrade Jest to the current version and then these tests were behaving as expected but then there are tons of TypeScript errors when building other packages (because of the old TypeScript version). Like I mentioned I would like to upgrade the dependencies across visx packages so consider it a temporary change.
So just to make sure I understand correctly - do you want to me to adjust the enhancers implementations to use the hooks? I have the code that uses the hooks stashed so that doesn't require any effort but just want to make sure that's what you mean. |
sorry for not being clear. I just verified that if you deep import |
Updated the PR, I think there shouldn't be any build errors and I addressed your feedback. |
Shameless bump - @williaster I would really appreciate if you could take a look at the PR, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the ping @paolostyle 🙏 and again for all the hard work and iteration here ❤️ lgtm, should be released soon 🚀
🎉 This PR is included in version |
export { default as withParentSize, WithParentSizeProvidedProps } from './enhancers/withParentSize'; | ||
export { default as withScreenSize, WithScreenSizeProvidedProps } from './enhancers/withScreenSize'; | ||
export { default as useParentSize, UseParentSizeConfig } from './hooks/useParentSize'; | ||
export { default as useScreenSize, UseScreenSizeConfig } from './hooks/useScreenSize'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines seem to be causing an error in TypeScript (if you have it scan node_modules) because those new types are not exported from the transpiled versions of these 4 files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah damn. Sorry about that. Created a PR that should fix this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof, thank you. also found a blind spot in our CI, thanks for the quick report and fix 🙏
💥 Breaking Changes
parentWidth
/parentHeight
/screenWidth
/screenHeight
prop to the component wrapped inwithParentSize
/withScreenSize
. Now whether that makes any sense is arguable as it basically invalidates entire purpose of the HOC. The actual runtime behavior did not change, it's just that now TypeScript will scream at you if you try to do this. I can roll this change back if you feel like this is too big of a change.🚀 Enhancements
WithParentSizeProvidedProps
andWithScreenSizeProvidedProps
to make it easier to properly type props of the component to be enhanced.📝 Documentation
debounceTime
,enableDebounceLeadingCall
and their counterparts inwithScreenSize
,initialWidth
,initialHeight
) to the readme🐛 Bug Fix
withParentSize
andwithScreenSize
HOCs on a component that contains required props different from the ones injected by the HOC without some ugly hacks. Example:There is no reason why this shouldn't be allowed, so this PR fixes it (i.e. the code above now transpiles correctly). I adjusted a test for this HOC as well to make it more clear that passing other props is now allowed. It also fixes #1645.
🏠 Internal
useParentSize
anduseScreenSize
hooks in a separate MR which I believe would be a bit easier to use. These two HOCs could then use these hooks internally instead.defaultProps
as it makes typing way more difficult and in this particular case it can be easily replaced by??
operator, it's used in only one place.