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

minor fix to <Text> and re-enable unit tests. #790

Merged
merged 2 commits into from
Aug 27, 2020

Conversation

kristw
Copy link
Collaborator

@kristw kristw commented Aug 26, 2020

🐛 Bug Fix

  • Fix complains when NaN or invalid values are passed as x or y
Warning: Received NaN for the `%s` attribute. If this is expected, cast the value to a string.%s

🏠 Internal

  • Remove prop-types from dependency. (no longer used)
  • List lodash.memoize in dependency of vx/text which is smaller than entire lodash.
  • Fix issue with jsdom and re-enable unit tests.

Copy link
Collaborator

@williaster williaster left a comment

Choose a reason for hiding this comment

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

Awesome fix for the tests! I had some comments on the deps tho.

"@types/react": "*",
"classnames": "^2.2.5",
"lodash": "^4.17.15",
"prop-types": "^15.7.2",
"lodash.memoize": "^4.1.2",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've gone through and done this before but had forgot this was intentional, see #66

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh ok sure. will revert.

"@types/react": "*",
"classnames": "^2.2.5",
"lodash": "^4.17.15",
"prop-types": "^15.7.2",
Copy link
Collaborator

Choose a reason for hiding this comment

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

we actually need this because we have a babel plugin that adds proptypes based on the types defined for a component.

this is useful for consumers I think (proptypes complain in dev / in the console), but @hshoff also was surprised by this recently so maybe we could consider removing it througout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok!

@@ -176,6 +185,11 @@ class Text extends React.Component<TextProps, TextState> {
const { wordsByLines } = this.state;
const { x, y } = textProps;

// Cannot render <text> if x or y is invalid
if (!isValidXOrY(x) || !isValidXOrY(y)) {
return <svg ref={innerRef} x={dx} y={dy} fontSize={textProps.fontSize} style={SVG_STYLE} />;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you think we should return null or an svg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking about return null but think if at least having the svg may keep the layout from changing if consumer depends on having some element there.

* JSDom does not implement getComputedTextLength()
* so this function add mock implementation for testing.
*/
export function addMock() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

@hshoff hshoff added this to the 0.0.199 milestone Aug 27, 2020
@kristw kristw merged commit ea2bdec into airbnb:master Aug 27, 2020
@kristw kristw deleted the kristw--text branch August 27, 2020 05:20
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.

3 participants