perf(vue-renderer): early return render when redirect happens (#6973)

This commit is contained in:
Pim 2020-02-16 14:20:08 +01:00 committed by GitHub
parent b71eaee879
commit bfad1e627b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -83,6 +83,14 @@ export default class SSRRenderer extends BaseRenderer {
APP = `<div id="${this.serverContext.globals.id}"></div>` APP = `<div id="${this.serverContext.globals.id}"></div>`
} }
if (renderContext.redirected && !renderContext._generate) {
return {
html: APP,
error: renderContext.nuxt.error,
redirected: renderContext.redirected
}
}
let HEAD = '' let HEAD = ''
// Inject head meta // Inject head meta

View File

@ -155,6 +155,7 @@ describe('basic ssr', () => {
test('/redirect', async () => { test('/redirect', async () => {
const { html, redirected } = await nuxt.server.renderRoute('/redirect') const { html, redirected } = await nuxt.server.renderRoute('/redirect')
expect(html).toContain('<div id="__nuxt"></div>') expect(html).toContain('<div id="__nuxt"></div>')
expect(html).not.toContain('window.__NUXT__')
expect(redirected.path === '/').toBe(true) expect(redirected.path === '/').toBe(true)
expect(redirected.status === 302).toBe(true) expect(redirected.status === 302).toBe(true)
}) })