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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69007aa
skip empty text instance creation in jsx conditions
jeetiss 2f9f2ac
add error message
jeetiss ea9d523
fix: ignore orphan text instance cases
diegomura 220e049
chore: warn
diegomura dbc6b61
chore: add changeset
diegomura 9b24fea
chore: change warn
diegomura File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@react-pdf/renderer': patch | ||
--- | ||
|
||
fix: skip empty text instance creation in jsx conditions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable react/jsx-curly-brace-presence */ | ||
import React from 'react'; | ||
import { Text, Document, Page } from '@react-pdf/primitives'; | ||
import renderToImage from './renderComponent'; | ||
|
||
const emptyString = ''; | ||
|
||
const mount = async children => { | ||
const image = await renderToImage( | ||
<Document> | ||
<Page>{children}</Page> | ||
</Document>, | ||
); | ||
|
||
return image; | ||
}; | ||
|
||
describe('renderer', () => { | ||
test('empty string', async () => { | ||
const image = await mount(<>{emptyString && <Text>{emptyString}</Text>}</>); | ||
|
||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test('string', async () => { | ||
const image = await mount(<>{'text' || <Text>text</Text>}</>); | ||
|
||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test('boolean', async () => { | ||
const image = await mount(<>{true || <Text>text</Text>}</>); | ||
|
||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test('zero', async () => { | ||
const image = await mount(<>{0 && <Text>text</Text>}</>); | ||
|
||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test('numbers', async () => { | ||
const image = await mount(<>{10 || <Text>text</Text>}</>); | ||
|
||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
}); |
Binary file added
BIN
+3.7 KB
packages/renderer/tests/snapshots/orphan-texts-test-js-renderer-boolean-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.7 KB
.../renderer/tests/snapshots/orphan-texts-test-js-renderer-empty-string-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.7 KB
packages/renderer/tests/snapshots/orphan-texts-test-js-renderer-numbers-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.7 KB
packages/renderer/tests/snapshots/orphan-texts-test-js-renderer-string-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.7 KB
packages/renderer/tests/snapshots/orphan-texts-test-js-renderer-zero-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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.
if add
<Text>
out ofReactMarkdown
:Actually, That can be found without ReactMarkdown. But I don't know when will insertBefore be called.