From 2fdcdedb50ee8c388f44a9416bc20bf7669dd6bc Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Wed, 6 Sep 2023 18:06:22 +0530 Subject: [PATCH] fix: attempt to activate the first app frame Closes: #48 --- src/Youch.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Youch.js b/src/Youch.js index 6085289..234b7fa 100644 --- a/src/Youch.js +++ b/src/Youch.js @@ -15,6 +15,7 @@ const cookie = require('cookie') const Mustache = require('mustache') const { fileURLToPath } = require('url') const StackTracey = require('stacktracey') +const { serialize } = require('v8') const VIEW_PATH = './error.compiled.mustache' const viewTemplate = fs.readFileSync(path.join(__dirname, VIEW_PATH), 'utf-8') @@ -131,17 +132,13 @@ class Youch { * * @return {String} */ - _getDisplayClasses (frame, index) { + _getDisplayClasses (frame) { const classes = [] - if (index === 0) { - classes.push('active') - } - if (!frame.isApp) { classes.push('native-frame') } - return classes.join(' ') + return classes } /** @@ -344,12 +341,22 @@ class Youch { return new Promise((resolve, reject) => { this._parseError() .then((stack) => { + let foundActiveFrame = false + const data = this._serializeData(stack, (frame, index) => { const serializedFrame = this._serializeFrame(frame) - serializedFrame.classes = this._getDisplayClasses( - serializedFrame, - index - ) + const classes = this._getDisplayClasses(serializedFrame) + + /** + * Adding active class to first app framework + */ + if (!foundActiveFrame && (serializedFrame.isApp || index + 1 === stack.length)) { + classes.push('active') + foundActiveFrame = true + } + + serializedFrame.classes = classes.join(' ') + return serializedFrame })