-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: skip empty text instance creation in jsx conditions (#1604)
Co-authored-by: diegomura <[email protected]>
- Loading branch information
Showing
8 changed files
with
73 additions
and
7 deletions.
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
Loading
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
Loading
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
Loading
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
Loading
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.