Skip to content

fix(runtime-core): errorHandler should work when hydrated. #4529

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

Merged
merged 1 commit into from
Sep 21, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,60 @@ describe('SSR hydration', () => {
expect(text.textContent).toBe('bye')
})

test('handle click error in ssr mode', async () => {
const App = {
setup() {
const throwError = () => {
throw new Error('Sentry Error')
}
return { throwError }
},
template: `
<div>
<button class="parent-click" @click="throwError">click me</button>
</div>`
}

const container = document.createElement('div')
// server render
container.innerHTML = await renderToString(h(App))
// hydrate
const app = createSSRApp(App)
const handler = (app.config.errorHandler = jest.fn())
app.mount(container)
// assert interactions
// parent button click
triggerEvent('click', container.querySelector('.parent-click')!)
expect(handler).toHaveBeenCalled()
})

test('handle blur error in ssr mode', async () => {
const App = {
setup() {
const throwError = () => {
throw new Error('Sentry Error')
}
return { throwError }
},
template: `
<div>
<input class="parent-click" @blur="throwError"/>
</div>`
}

const container = document.createElement('div')
// server render
container.innerHTML = await renderToString(h(App))
// hydrate
const app = createSSRApp(App)
const handler = (app.config.errorHandler = jest.fn())
app.mount(container)
// assert interactions
// parent blur event
triggerEvent('blur', container.querySelector('.parent-click')!)
expect(handler).toHaveBeenCalled()
})

test('Suspense', async () => {
const AsyncChild = {
async setup() {
Expand Down
20 changes: 18 additions & 2 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,29 @@ export function createHydrationFunctions(
(forcePatchValue && key.endsWith('value')) ||
(isOn(key) && !isReservedProp(key))
) {
patchProp(el, key, null, props[key])
patchProp(
el,
key,
null,
props[key],
false,
undefined,
parentComponent
)
}
}
} else if (props.onClick) {
// Fast path for click listeners (which is most often) to avoid
// iterating through props.
patchProp(el, 'onClick', null, props.onClick)
patchProp(
el,
'onClick',
null,
props.onClick,
false,
undefined,
parentComponent
)
}
}
// vnode / directive hooks
Expand Down