question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@vx/text width prop breaks w/ SSR

See original GitHub issue

(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

it renders this: image

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, so I tried shorting that by creating / passing a new style object on render, but no such luck.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
techniqcommented, Apr 9, 2018

@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 getDerivedStateFromProps in the future).

1reaction
brandonmpcommented, Apr 9, 2018

i was able to reproduce it in the docs by modifying text.js to this:

import React, { Component } from 'react';
import { Text } from '@vx/text';

export default () => (
    <div
        style={{
            display: 'flex',
            width: '90vw',
            height: '90vh',
            justifyContent: 'center',
            alignItems: 'center'
        }}
    >
        <svg width={500} height={200}>
            <Text
                scaleToFit
                width={25}
                x={250}
                textAnchor={'middle'}
                y={18}
                angle={-90}
            >
                This should be vertical
            </Text>
        </svg>
        <svg width={100} height={200}>
            <Text width={25} x={15} textAnchor={'middle'} y={25} angle={-90}>
                This is vertical
            </Text>
        </svg>
    </div>
);

here’s a live demo

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I insert a line break into a <Text> component in ...
Here is a solution for React (not React Native) using TypeScript. The same concept can be applied to React Native import React from...
Read more >
Advanced Usage - styled-components
Passing a ref prop to a styled component will give you one of two things depending on the styled target: the underlying DOM...
Read more >
Best practices to increase the speed for Next.js apps
Fortunately, developers can follow a number of best practices to improve the speed of their Next.js applications. Use server-side rendering.
Read more >
extension-react-ssr - Remirror
package @remirror/extension-react-ssr ... property props​. Signature: ... export declare type SsrTransformer = (element: JSX.Element, state?
Read more >
Change Log - Ant Design
Major version release is not included in this schedule for breaking ... #38249; 🔥 Progress circle type support responsive format text for small...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found