From 3f59bde022d16e1eeb33f252067319e00f5112d2 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 18 Oct 2018 10:02:43 +0200 Subject: [PATCH] resolve-props: avoid json parse using simple heuristic (big perf hit in widget init) --- src/browser/js/app/widgets/common/widget.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/browser/js/app/widgets/common/widget.js b/src/browser/js/app/widgets/common/widget.js index 72b07ea8..4a3b0691 100644 --- a/src/browser/js/app/widgets/common/widget.js +++ b/src/browser/js/app/widgets/common/widget.js @@ -489,9 +489,13 @@ class Widget extends EventEmitter { propValue = propValue.replace(new RegExp(k, 'g'), v) } - try { - propValue = JSON.parse(propValue) - } catch (err) {} + // heuristic to avoid using JSON when unnecessary + // if the string starts with one of these chars it's going to fail + if ('/@#.'.indexOf(propValue[0]) === -1) { + try { + propValue = JSON.parse(propValue) + } catch (err) {} + } } else if (propValue != null && typeof propValue == 'object') { for (let k in propValue) {