refactor: persist isModernBrowser on http connection (#4268)

This commit is contained in:
Clark Du 2018-11-04 14:47:56 +00:00 committed by GitHub
parent f10f860292
commit 7d34f2ef26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -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, {
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)