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 } return { html, getPreloadFiles }
} }
const { req } = context const { req: { socket = {}, headers } = {} } = context
const ua = req && req.headers && req.headers['user-agent'] if (socket.isModernBrowser === undefined) {
const isModernBrowser = this.renderer.modern && ua && matchesUA(ua, { const ua = headers && headers['user-agent']
socket.isModernBrowser = this.renderer.modern && ua && matchesUA(ua, {
allowHigherVersions: true, allowHigherVersions: true,
browsers: this.modernBrowsers browsers: this.modernBrowsers
}) })
}
let APP let APP
// Call renderToString from the bundleRenderer and generate the HTML (will update the context as well) // 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) APP = await this.renderer.modern.renderToString(context)
} else { } else {
APP = await this.renderer.ssr.renderToString(context) APP = await this.renderer.ssr.renderToString(context)

View File

@ -23,7 +23,7 @@ const _require = esm(module, {
}) })
module.exports = _require('../src/index') module.exports = _require('../src/index')
`} ` }
async function main() { async function main() {
// Read package at current directory // Read package at current directory