-
Notifications
You must be signed in to change notification settings - Fork 716
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
@vx/text width prop breaks w/ SSR #266
Comments
Is it possible that there is not getBoundingClientRect in the SSR env?
@vx/text needs this to measure word widths.
…On Sun, Apr 8, 2018, 7:53 PM brandon ***@***.***> wrote:
(I'm not actually sure if this has anything to do with SSR, but the
problem presents only on fresh page loads in my nextjs project, so that's
normally the culprit.)
I'm calling the component like so:
<Text
scaleToFit
width={25}
x={9}
textAnchor={'middle'}
y={18}
angle={-90}
>
Some label
</Text>
On page load, however, the rendered styles on the <text> element are
broken. specifically, the transform value is: matrix(Infinity, 0, 0,
Infinity, -Infinity, -Infinity) rotate(-90, 9, 18)
The practical implication of this bad transform in my case is that text
I'm trying to render vertically shows up w/ a horizontal orientation.
e.g. instead of this:
[image: image]
<https://user-images.githubusercontent.com/14139991/38473972-0da8d69c-3b66-11e8-908c-86f3317d399c.png>
it renders this:
[image: image]
<https://user-images.githubusercontent.com/14139991/38473978-158213ce-3b66-11e8-90d5-d54c655351b1.png>
When hot reloading updates the bundle, however, the transform prop gets
updated to a valid value, and the text renders as it ought to:
matrix(0.7368114063658365, 0, 0, 0.7368114063658365, 2.3686973427074713, 4.737394685414943) rotate(-90, 9, 18)
I thought maybe it was the memoization (i think?) pattern you've got going
on in componentWillReceiveProps
<https://github.com/hshoff/vx/blob/master/packages/vx-text/src/Text.js>,
so I tried shorting that by creating / passing a new style object on
render, but no such luck.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#266>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAK1RFI96o57BX-Bn0XohEBrm_WCKCK9ks5tmqMQgaJpZM4TLxFn>
.
|
hmm that's odd. I'm not seeing any errors when loading https://vx-demo.now.sh/text which uses nextjs...even tried making To help me reproduce this problem, which version of next are you using? |
@hshoff I'm using
ETA just re-read your note that you tried w/ same props from example, so scratch this theory. looking at src I'm thinking it has to be @techniq I think you're right. It looks like getStringWidth is called in Normally when |
i was able to reproduce it in the docs by modifying
|
Recharts (where I originally submitted this component too) has a SSR check before calculating the word widths that we should do as well. I haven't used SSR much myself so I've never ran into this. I'm guessing if we don't run this on the server, it should run the calculations during the client render. |
I'm also less familiar with SSR, can this be fixed with the SSR check + moving it to |
@williaster we need to recalculate the word widths any time the children (i.e. text) or styles change so it needs to happen anytime the props change (although this will need to be changed to |
@techniq is it good enough to just put a ballpark value based on string length for SSR, then calc the real value when the component mounts? it's admittedly a 'good enough' solution, but i've used similar approaches in a few cases working around SSR constraints. so, e.g., where getStringWidth.js returns null on the server:
you could simply do
Could also add a
|
also: the typical way i see ssr checked is i like the try/catch approach, but maybe a more explicit check is better here |
@brandonmp seems reasonable. I'm not very familiar with SSR and how state is reconstituted on the client. Would want to make sure another calculation occurred on the client to correct the values. Also, seems like matching how recharts handles this would work. Changing this to if ((props.width || props.scaleToFit) && typeof window !== 'undefined') { |
was there any alignment on the desired approach here? simply adding the line @techniq called out? if ((props.width || props.scaleToFit) && typeof window !== 'undefined') { |
I've not used SSR enough to give a definitive answer.
…On Tue, Jun 26, 2018, 2:34 PM Chris Williams ***@***.***> wrote:
was there any alignment on the desired approach here? simply adding the
line @techniq <https://github.com/techniq> called out?
if ((props.width || props.scaleToFit) && typeof window !== 'undefined') {
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#266 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAK1RFaUeucuETbJbf0cA61FQD-bgCC-ks5uAn7AgaJpZM4TLxFn>
.
|
(I'm not actually sure if this has anything to do with SSR, but the problem presents only on fresh page loads in my
nextjs
project, so that's normally the culprit.)I'm calling the component like so:
On page load, however, the rendered styles on the
<text>
element are broken. specifically, thetransform
value is:matrix(Infinity, 0, 0, Infinity, -Infinity, -Infinity) rotate(-90, 9, 18)
The practical implication of this bad transform in my case is that text I'm trying to render vertically shows up w/ a horizontal orientation.
e.g. instead of this:
it renders this:
When hot reloading updates the bundle, however, the
transform
prop gets updated to a valid value, and the text renders as it ought to:I thought maybe it was the memoization (i think?) pattern you've got going on in componentWillReceiveProps, so I tried shorting that by creating / passing a new style object on render, but no such luck.
The text was updated successfully, but these errors were encountered: