Skip to content

Commit

Permalink
Gracefully handle empty "xstyle" prop values (facebook#23190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored and zhengjitf committed Apr 15, 2022
1 parent f6caca7 commit 0c9b5a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ describe('Stylex plugin utils', () => {
});
});

it('should gracefully handle empty values', () => {
expect(getStyleXData(null)).toMatchInlineSnapshot(`
Object {
"resolvedStyles": Object {},
"sources": Array [],
}
`);

expect(getStyleXData(undefined)).toMatchInlineSnapshot(`
Object {
"resolvedStyles": Object {},
"sources": Array [],
}
`);

expect(getStyleXData('')).toMatchInlineSnapshot(`
Object {
"resolvedStyles": Object {},
"sources": Array [],
}
`);
});

it('should support simple style objects', () => {
defineStyles(`
.foo {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/backend/StyleX/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function crawlData(
sources: Set<string>,
resolvedStyles: Object,
): void {
if (data == null) {
return;
}

if (isArray(data)) {
data.forEach(entry => {
if (isArray(entry)) {
Expand Down

0 comments on commit 0c9b5a1

Please sign in to comment.