-
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(@visx/text) Bad size measurements in Firefox #1175
fix(@visx/text) Bad size measurements in Firefox #1175
Conversation
…etter measurement in firefox
…t to TextSvgElement)
Hey @vovakulikov thanks for really digging into the cause of the issue and the PR 🙏 One issue with this implementation is that there would be If this is truly a bug with https://codesandbox.io/s/priceless-margulis-nctit?file=/index.tsx |
@williaster Thanks for making this demo about
But we render just one visx/packages/visx-text/src/Text.tsx Lines 31 to 37 in d5fb82e
|
Ah yes I totally misread the condition on that line, sorry. In this case maybe this approach will work fine! 🎉 I might still post an issue in as far as avoiding breaking changes for this change, I think I'd probably vote for this option rather than casting to the wrong type
Sorry it's so challenging to avoid breaking changes, have to be creative sometimes 😅 |
@williaster Totally with you about create issue in |
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 again @vovakulikov 🙏 This looks great ❤️
🎉 This PR is included in version |
🐛 Bug Fix
I don't have a clear understanding of this but it seems like
react-use-measure
hook doesn't work well with innersvg
element within .I consider this problem came from how Firefox treats empty svg elements without width and height within another svg element with height and width - They usually have
width=100%
height=100%
of parent size even if we put size value from CSSwidth: 0px; height: 0px;
explicitly.In the first render we're getting a really big value of Text svg height, so we're just stuck with this big initial height value here and therefore have this visual behaviour here.
Possible solution in this PR this is replace
innerRef
target from svg<Text />
root element to<text />
element which can be measured without this problem.Only one concern here this is kind of breaking change in public API types (before we had i
nnerRef: Ref<SVGSvgElement>
, now we haveRef<SVGTextElement>
). I see here two option how to avoid breaking change in types<text ref={innerRef as Ref<SVGTextElement>} />
textInnerRef
withRef<SVGTextElement>
and use this prop to measure size at annotation<Label />
instead of use old innerRefvisx/packages/visx-annotation/src/components/Label.tsx
Lines 225 to 235 in d5fb82e