commit 4c13e8ea1640036d346b329fe136dfe20f8fd4f6 Author: Ole Date: Fri Oct 9 20:24:11 2020 +0200 Refactor reload 7: Await syntax highlighting This function is very hard to follow. Making small steps to ensure careful review. Makes this inner bit more in line with the rest of the code. This does result in the diffViewContentDisplayed being reported before the synchronous code in syntaxLayer.process, but that's just a few lines of JS so it should not really matter. Change-Id: Ib5438b00480d57f73613f1cb4a0c4dd2bd45c6cc diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts index b9c268d..c9351b1 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts +++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts @@ -372,30 +372,29 @@ export class GrDiffHost extends GestureEventListeners( }; this.addEventListener('render', callback); }); + if (shouldReportMetric) { + // We report diffViewContentDisplayed only on reload caused + // by params changed - expected only on Diff Page. + this.reporting.diffViewContentDisplayed(); + } const needsSyntaxHighlighting = event.detail && event.detail.contentRendered; - let result: Promise = Promise.resolve(); if (needsSyntaxHighlighting) { this.reporting.time(TimingLabel.SYNTAX); - result = this.$.syntaxLayer.process().finally(() => { + try { + await this.$.syntaxLayer.process(); + } finally { this.reporting.timeEnd(TimingLabel.SYNTAX); - }); - } - result.finally(() => { - this.reporting.timeEnd(TimingLabel.TOTAL); - }); - if (shouldReportMetric) { - // We report diffViewContentDisplayed only on reload caused - // by params changed - expected only on Diff Page. - this.reporting.diffViewContentDisplayed(); + } } - await result; } catch (e) { if (e instanceof Response) { this._handleGetDiffError(e); } else { console.warn('Error encountered loading diff:', e); } + } finally { + this.reporting.timeEnd(TimingLabel.TOTAL); } this._loading = false; }