diegomura / react-pdf

đź“„ Create PDF files using React
https://react-pdf.org
MIT License
14.92k stars 1.18k forks source link

Crash when overflowing text inside a view with a height #1923

Open SpudNyk opened 2 years ago

SpudNyk commented 2 years ago

Describe the bug

When rendering text that overflows its container (even if it's overflow hidden) I get the following error:

worker.ts:38 TypeError: Cannot read properties of undefined (reading 'y')
    at textkit.es.js:787:1
    at Array.map (<anonymous>)
    at layoutLines (textkit.es.js:778:1)
    at textkit.es.js:825:1
    at textkit.es.js:877:1
    at compose.js:32:1
    at textkit.es.js:1748:19
    at layoutText (index.es.js:2085:1)
    at index.es.js:2926:1

This did not occur in version 2.1.1, but did in 2.3.0

To Reproduce The following code will reproduce the error in the repl

const styles = {
    container: {
        height: 30,
    },
    content: {
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        maxLines: 1,
    },
};

function TextOverflowError() {
    return (
        <Document>
            <Page>
                <View style={styles.container}>
                    <Text style={styles.content}>
                        En un lugar de la Mancha, de cuyo nombre no quiero
                        acordarme, no ha mucho tiempo que vivĂ­a un hidalgo de
                        los de lanza en astillero, adarga antigua, rocĂ­n flaco y
                        galgo corredor. Una olla de algo más vaca que carnero,
                        salpicón las más noches, duelos y quebrantos los
                        sábados, lentejas los viernes, algún palomino de
                        añadidura los domingos, consumían las tres partes de su
                        hacienda. El resto della concluĂ­an sayo de velarte,
                        calzas de velludo para las fiestas con sus pantuflos de
                        lo mismo, los dĂ­as de entre semana se honraba con su
                        vellori de lo más fino. Tenía en su casa una ama que
                        pasaba de los cuarenta, y una sobrina que no llegaba a
                        los veinte, y un mozo de campo y plaza, que asĂ­
                        ensillaba el rocĂ­n como tomaba la podadera. Frisaba la
                        edad de nuestro hidalgo con los cincuenta años, era de
                        complexiĂłn recia, seco de carnes, enjuto de rostro; gran
                        madrugador y amigo de la caza. Quieren decir que tenĂ­a
                        el sobrenombre de Quijada o Quesada (que en esto hay
                        alguna diferencia en los autores que deste caso
                        escriben), aunque por conjeturas verosĂ­miles se deja
                        entender que se llama Quijana; pero esto importa poco a
                        nuestro cuento; basta que en la narración dél no se
                        salga un punto de la verdad
                    </Text>
                </View>
            </Page>
        </Document>
    );
}

ReactPDF.render(<TextOverflowError />);

react-pdf REPL

Expected behavior A crash to not occur

davbrito commented 2 years ago

I'm having the same issue since the update to the latest version

pganster commented 2 years ago

We experience the same bug when upgrading from @react-pdf/renderer@2.1.1 to @react-pdf/renderer@2.1.2.

Additionally, when a Text is inside a View with a fixed height, whilst the text itself needs more height, the rendering crashes too.

carlobeltrame commented 2 years ago

I already fixed this in #1917. We just have to wait for a release of react-pdf which includes this.

davbrito commented 2 years ago

I already fixed this in #1917. We just have to wait for a release of react-pdf which includes this.

When will this be released? I think it's critical.

ads-silva commented 2 years ago

Do we have any idea when a new version will be released?

modosc commented 2 years ago

any chance for a release here? it's been a month and we can't manually pull in this fix.

carlobeltrame commented 2 years ago

@diegomura seems to be on vacation or something. But the bug was introduced in @react-pdf/renderer v2.3.0, so you can pin to v2.2.0 for now until a new version is released. By the way, @jeetiss you do not by any chance have the rights to publish new versions, do you?

bjornbreck commented 2 years ago

Any updates about when this will get published? @diegomura

christopherromero commented 2 years ago

@diegomura Any updates on this fix?

carlobeltrame commented 2 years ago

This was fixed and published with @react-pdf/textkit@4.1.0. Does the fix not work for you @christopherromero? If it does, this issue could be closed.

pganster commented 2 years ago

After updating to @react-pdf/renderer v3.0.0 I can confirm that no more crashes occur, so I think this issue can be closed.