Skip to content
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

Bug where styles are not correctly inherited #1790

Closed
4 tasks done
iSilkline opened this issue May 9, 2024 · 0 comments
Closed
4 tasks done

Bug where styles are not correctly inherited #1790

iSilkline opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@iSilkline
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

When using tags nested in another tag, styles are not correctly rendered.

Steps to reproduce

Reproduce using this code

// Font Import
Font.register({
  family: 'Inter-Regular',
  src: 'https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfMZg.ttf',
});
Font.register({
  family: 'Inter-Bold',
  src: 'https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuGKYMZg.ttf',
});

// Create styles
const styles = StyleSheet.create({
  page: {
    paddingTop: 35,
    paddingBottom: 65,
    paddingHorizontal: 35,
    fontFamily: 'Inter-Regular',
    fontSize: 9,
  },
  regularText: {
    fontFamily: 'Inter-Regular',
  },
  boldText: {
    fontFamily: 'Inter-Bold',
  },
});
<Document>
  <Page size="A4" style={styles.page}>
    {/* Example of text style inheritance bug */}
    <Text style={[styles.regularText]}>
      <Text style={[styles.boldText]}>{`Label: `}</Text>
      <Text style={[styles.regularText]}>{`Value`}</Text>
    </Text>
    <Text style={[styles.boldText]}>{`Label: `}</Text>
    <Text style={[styles.regularText]}>{`Value`}</Text>
  </Page>
</Document>

Expected behavior

Each tag should render for it's own styles (or inherits styles from parent tags), and should not be attributed styles of preceding tag.

Actual behavior

When nested in a parent tag (regardless of that tag's styles), the second child tag is incorrectly attributed the styles of the first child tag.

See three examples in the screenshot below:

  1. Two tags nested in parent tag. First child tag has bold styles, second child tag has regular styles. Render outcome: both are bold.
  2. Two tags nested in parent tag. First child tag has regular styles, second child tag has bold styles. Render outcome: both are regular.
  3. No parent tag. Each text tag renders correctly for their respective styles
Screenshot 2024-05-09 at 10 11 39 AM

Additional information

No response

Environment

Chrome: 124.0.6367.119
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
├─ @react-pdf/[email protected]
└─ @react-pdf/[email protected]

@iSilkline iSilkline added the bug Something isn't working label May 9, 2024
@iSilkline iSilkline closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant