Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): reset current instance after rendering error on SSR.(fix #6110) #6184

Merged
merged 1 commit into from Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/server-renderer/__tests__/render.spec.ts
Expand Up @@ -20,7 +20,8 @@ import {
resolveDynamicComponent,
renderSlot,
onErrorCaptured,
onServerPrefetch
onServerPrefetch,
getCurrentInstance
} from 'vue'
import { escapeHtml } from '@vue/shared'
import { renderToString } from '../src/renderToString'
Expand Down Expand Up @@ -781,6 +782,23 @@ function testRender(type: string, render: typeof renderToString) {
).toHaveBeenWarned()
expect(`Element is missing end tag`).toHaveBeenWarned()
})

// #6110
test('reset current instance after rendering error', async () => {
const prev = getCurrentInstance()
expect(prev).toBe(null)
try {
await render(
createApp({
data() {
return { msg: null }
},
template: `<div>{{ msg.text }}</div>`
})
)
} catch {}
expect(getCurrentInstance()).toBe(prev)
})
})

test('serverPrefetch', async () => {
Expand Down
27 changes: 15 additions & 12 deletions packages/server-renderer/src/render.ts
Expand Up @@ -174,18 +174,21 @@ function renderComponentSubTree(

// set current rendering instance for asset resolution
const prev = setCurrentRenderingInstance(instance)
ssrRender(
instance.proxy,
push,
instance,
attrs,
// compiler-optimized bindings
instance.props,
instance.setupState,
instance.data,
instance.ctx
)
setCurrentRenderingInstance(prev)
try {
ssrRender(
instance.proxy,
push,
instance,
attrs,
// compiler-optimized bindings
instance.props,
instance.setupState,
instance.data,
instance.ctx
)
} finally {
setCurrentRenderingInstance(prev)
}
} else if (instance.render && instance.render !== NOOP) {
renderVNode(
push,
Expand Down