From 08fce6208ed8bede70fa9291eac8412f20ac56b5 Mon Sep 17 00:00:00 2001 From: Luna Ruan Date: Fri, 11 Feb 2022 14:36:36 -0500 Subject: [PATCH] Gracefully handle empty "xstyle" prop values (Part 2) (#23279) #23190 misses if entry is undefined or null. This fixes this issue. --- .../src/backend/StyleX/__tests__/utils-test.js | 7 +++++++ packages/react-devtools-shared/src/backend/StyleX/utils.js | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/packages/react-devtools-shared/src/backend/StyleX/__tests__/utils-test.js b/packages/react-devtools-shared/src/backend/StyleX/__tests__/utils-test.js index d0b8742a82f81..6dffbb52101aa 100644 --- a/packages/react-devtools-shared/src/backend/StyleX/__tests__/utils-test.js +++ b/packages/react-devtools-shared/src/backend/StyleX/__tests__/utils-test.js @@ -54,6 +54,13 @@ describe('Stylex plugin utils', () => { "sources": Array [], } `); + + expect(getStyleXData([undefined])).toMatchInlineSnapshot(` + Object { + "resolvedStyles": Object {}, + "sources": Array [], + } + `); }); it('should support simple style objects', () => { diff --git a/packages/react-devtools-shared/src/backend/StyleX/utils.js b/packages/react-devtools-shared/src/backend/StyleX/utils.js index 230e08360259b..68bda23a2262c 100644 --- a/packages/react-devtools-shared/src/backend/StyleX/utils.js +++ b/packages/react-devtools-shared/src/backend/StyleX/utils.js @@ -35,6 +35,10 @@ export function crawlData( if (isArray(data)) { data.forEach(entry => { + if (entry == null) { + return; + } + if (isArray(entry)) { crawlData(entry, sources, resolvedStyles); } else {