From ec1e977084e805538951c52c14dfefa949a3e9ed Mon Sep 17 00:00:00 2001 From: Daniel Abramowitz Date: Thu, 29 Nov 2018 08:16:25 -0800 Subject: [PATCH] Fix "invalid weak map key" error when nodes in the layout inspector are empty strings Summary: When nodes didn't have any metadata, the data was an empty string, which fails json parsing. This causes data be passed to the InspectorSidebarSection as ''. The weak map inside that component expects data to be an object, not a string, and crashes if it's actually a string. This will ensure that data is always an object. Reviewed By: jknoxville Differential Revision: D13109384 fbshipit-source-id: 469a1b5c1c00130ef37636bf7c6796b2463fb34b --- src/ui/components/elements-inspector/sidebar.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ui/components/elements-inspector/sidebar.js b/src/ui/components/elements-inspector/sidebar.js index 9535e8743..25f65eea2 100644 --- a/src/ui/components/elements-inspector/sidebar.js +++ b/src/ui/components/elements-inspector/sidebar.js @@ -144,7 +144,11 @@ export class InspectorSidebar extends Component { try { data = JSON.parse(data); } catch (e) { - // data was not a valid JSON, using string instead + // data was not a valid JSON, type is required to be an object + console.error( + `ElementsInspector unable to parse extra section: ${extraSection}`, + ); + data = {}; } } sections.push(