Skip to content

Commit 934f722

Browse files
author
Brian Vaughn
authored
Gracefully handle empty "xstyle" prop values (facebook#23190)
1 parent 529dc3c commit 934f722

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/react-devtools-shared/src/backend/StyleX/__tests__/utils-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ describe('Stylex plugin utils', () => {
3333
});
3434
});
3535

36+
it('should gracefully handle empty values', () => {
37+
expect(getStyleXData(null)).toMatchInlineSnapshot(`
38+
Object {
39+
"resolvedStyles": Object {},
40+
"sources": Array [],
41+
}
42+
`);
43+
44+
expect(getStyleXData(undefined)).toMatchInlineSnapshot(`
45+
Object {
46+
"resolvedStyles": Object {},
47+
"sources": Array [],
48+
}
49+
`);
50+
51+
expect(getStyleXData('')).toMatchInlineSnapshot(`
52+
Object {
53+
"resolvedStyles": Object {},
54+
"sources": Array [],
55+
}
56+
`);
57+
});
58+
3659
it('should support simple style objects', () => {
3760
defineStyles(`
3861
.foo {

packages/react-devtools-shared/src/backend/StyleX/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export function crawlData(
2929
sources: Set<string>,
3030
resolvedStyles: Object,
3131
): void {
32+
if (data == null) {
33+
return;
34+
}
35+
3236
if (isArray(data)) {
3337
data.forEach(entry => {
3438
if (isArray(entry)) {

0 commit comments

Comments
 (0)