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
This commit is contained in:
Daniel Abramowitz
2018-11-29 08:16:25 -08:00
committed by Facebook Github Bot
parent 6c4467a03d
commit ec1e977084

View File

@@ -144,7 +144,11 @@ export class InspectorSidebar extends Component<Props, State> {
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(