Skip to content

Process hangs indefinitely when using lineHeight property in specific layout contexts #3245

@tomer-amir-pan

Description

@tomer-amir-pan

Bug Report

Description

The PDF rendering process hangs indefinitely (infinite loop) when using the lineHeight property on a Text component within a flex container.

Environment

  • @react-pdf/renderer version: 4.3.1
  • Node.js version: v20.19.5
  • Operating System: macOS

Reproduction

The following code causes the renderer to hang during PDF generation:

const styles = StyleSheet.create({
    metricValueContainer: {
        flexDirection: 'row',
        alignItems: 'center',
    },
    metricValue: {
        fontSize: 19.2,
        color: '#333333',
        lineHeight: 25.6,  // This causes the hang
    },
})

// Usage in component
<View style={styles.metricValueContainer}>
    <Text style={styles.metricValue}>
        {value}
    </Text>
</View>

Expected Behavior

The PDF should render successfully with the specified line height.

Actual Behavior

The process hangs indefinitely during PDF generation. No error is thrown, the process just never completes.

Workaround

Removing or commenting out the lineHeight property resolves the issue:

metricValue: {
    fontSize: 19.2,
    color: '#333333',
    // lineHeight: 25.6,  // Removed to prevent hang
},

Additional Context

  • The hang appears to be related to layout calculations in the yoga-layout engine
  • The specific ratio between fontSize and lineHeight seems to trigger the issue
  • Other lineHeight values in the same file (e.g., lineHeight: 8.889) work fine
  • The issue occurs specifically when the Text is inside a flex container with alignItems: 'center'

Possible Related Issues

This might be related to infinite layout recalculation loops when the layout engine tries to calculate text bounds with certain lineHeight values in flex contexts.

Would appreciate any insights or fixes for this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions