From 7d34f2ef26b1423c89ed041094d97130da0f1987 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Sun, 4 Nov 2018 14:47:56 +0000 Subject: [PATCH] refactor: persist isModernBrowser on http connection (#4268) --- packages/vue-renderer/src/renderer.js | 16 +++++++++------- scripts/dev | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/vue-renderer/src/renderer.js b/packages/vue-renderer/src/renderer.js index 8a07029919..10a3bf93af 100644 --- a/packages/vue-renderer/src/renderer.js +++ b/packages/vue-renderer/src/renderer.js @@ -224,16 +224,18 @@ export default class VueRenderer { return { html, getPreloadFiles } } - const { req } = context - const ua = req && req.headers && req.headers['user-agent'] - const isModernBrowser = this.renderer.modern && ua && matchesUA(ua, { - allowHigherVersions: true, - browsers: this.modernBrowsers - }) + const { req: { socket = {}, headers } = {} } = context + if (socket.isModernBrowser === undefined) { + const ua = headers && headers['user-agent'] + socket.isModernBrowser = this.renderer.modern && ua && matchesUA(ua, { + allowHigherVersions: true, + browsers: this.modernBrowsers + }) + } let APP // Call renderToString from the bundleRenderer and generate the HTML (will update the context as well) - if (isModernBrowser) { + if (socket.isModernBrowser) { APP = await this.renderer.modern.renderToString(context) } else { APP = await this.renderer.ssr.renderToString(context) diff --git a/scripts/dev b/scripts/dev index 23a7898816..ff8d204b4f 100755 --- a/scripts/dev +++ b/scripts/dev @@ -23,7 +23,7 @@ const _require = esm(module, { }) module.exports = _require('../src/index') -`} +` } async function main() { // Read package at current directory