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(runtime): 修复react事件回调里没有合并更新的问题,fix #8516 #8539

Merged
merged 1 commit into from
Jan 15, 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
9 changes: 8 additions & 1 deletion packages/taro-runtime/src/dom/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export function eventHandler (event: MpEvent) {

const node = document.getElementById(event.currentTarget.id)
if (node != null) {
node.dispatchEvent(createEvent(event, node))
const dispatch = () => {
node.dispatchEvent(createEvent(event, node))
}
if (typeof CurrentReconciler.batchedEventUpdates === 'function') {
CurrentReconciler.batchedEventUpdates(dispatch)
} else {
dispatch()
}
}
}
3 changes: 3 additions & 0 deletions packages/taro-runtime/src/dsl/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ function setReconciler () {
},
modifyEventType (event) {
event.type = event.type.replace(/-/g, '')
},
batchedEventUpdates (cb) {
ReactDOM.unstable_batchedUpdates(cb)
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/taro-runtime/src/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface Reconciler<Instance, DOMElement = TaroElement, TextElement = Ta

getLifecyle(instance: Instance, lifecyle: keyof PageInstance): Function | undefined | Array<Function>

batchedEventUpdates?(cb: () => void): void

// h5
createPullDownComponent?(el: Instance, path: string, framework)

Expand Down