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
fix: skip empty text instance creation in jsx conditions #1604
Conversation
1e7417f
to
8c76b81
Compare
@jeetiss I resume this. I think throwing in these cases is too agressive. On this PR I just ignore these cases with a warning |
55e34f0
to
dbc6b61
Compare
console.warn( | ||
`Invalid '${child.value}' string child outside <Text> component`, | ||
); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I think there are some mistakes here. If we haven't push these node, that may got error when insertBefore
called.
insertBefore(parentInstance, child, beforeChild) {
const index = parentInstance.children?.indexOf(beforeChild);
if (index === undefined) return;
if (index !== -1 && child)
parentInstance.children.splice(index, 0, child);
},
child will be droped if beforeChild is not OrphanTextInstance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide a test that shows the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { Document, Font, Image, Link, Page, PDFViewer, StyleSheet, Text, View } from '@react-pdf/renderer'
import ReactMarkdown from 'react-markdown'
import { ReactMarkdownProps } from 'react-markdown/lib/ast-to-react'
const App = () => (
<PDFViewer style={{ width: '100%', height: 800 }}>
<Document>
<Page style={styles.body}>
{/*<Text>*/}
<ReactMarkdown components={{
h1: ({ children }: ReactMarkdownProps) => <Text>{children}</Text>,
p: ({ children }: ReactMarkdownProps) => <Text>{children}</Text>,
}}>{`# a
b`}</ReactMarkdown>
{/*</Text>*/}
</Page>
</Document>
</PDFViewer>
)
if add <Text>
out of ReactMarkdown
:
Actually, That can be found without ReactMarkdown. But I don't know when will insertBefore be called.
Fix #1602