Skip to content

Commit

Permalink
fix: safari perf optimizations, strip html from diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Aug 30, 2023
1 parent 1429f92 commit 17fcb7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,14 @@ html.h-100.no-js(
id=ctx.pathWithoutLocale === "/" && !isBot(ctx.get("User-Agent")) ? "freddy" : "",
data-ignore-hash-change=ctx.pathWithoutLocale === "/" ? true : false
)
//- Safari has performance issues
//- <https://stackoverflow.com/a/40463096>
- const isSafari = /^((?!chrome|android|crios|fxios).)*safari/i.test(ctx.get("User-Agent"));
if (ctx.pathWithoutLocale === '/' && !isBot(ctx.get('User-Agent')))
#stars.user-select-none
#rocket.user-select-none
#waving.user-select-none
if !isSafari
#rocket.user-select-none
#waving.user-select-none
- const isHelp = ctx.pathWithoutLocale && ctx.pathWithoutLocale === "/help";
- const isRegisterOrLogin = ctx.pathWithoutLocale && ["/register", config.loginRoute].includes(ctx.pathWithoutLocale);

Expand Down
19 changes: 17 additions & 2 deletions helpers/get-diagnostic-code.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
const RE2 = require('re2');
const isSANB = require('is-string-and-not-blank');
const { convert } = require('html-to-text');

const getErrorCode = require('./get-error-code');

const config = require('#config');

const REGEX_DIAGNOSTIC_CODE = new RE2(/^\d{3} /);

const options = {
wordwrap: false,
selectors: [
{ selector: 'img', format: 'skip' },
{ selector: 'ul', options: { itemPrefix: ' ' } },
{
selector: 'a',
options: { baseUrl: config.urls.web, linkBrackets: false }
}
]
};

function getDiagnosticCode(err) {
if (isSANB(err.response) && REGEX_DIAGNOSTIC_CODE.test(err.response))
return err.response;
return `${getErrorCode(err)} ${err.message}`;
return convert(err.response, options);
return `${getErrorCode(err)} ${convert(err.message, options)}`;
}

module.exports = getDiagnosticCode;

0 comments on commit 17fcb7e

Please sign in to comment.