Skip to content

Commit 6064355

Browse files
committed
whoops
1 parent 52f3a58 commit 6064355

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

vnext/Microsoft.ReactNative/CoalescingEventEmitter.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,24 @@ void CoalescingEventEmitter::EnsureRenderCallbackRegistered() noexcept {
7575
}
7676

7777
void CoalescingEventEmitter::OnRendering() noexcept {
78-
std::unique_lock lock(m_mutex);
78+
auto jsDispatcher = m_context->Properties().Get(ReactDispatcherHelper::JSDispatcherProperty()).as<IReactDispatcher>();
7979

8080
// Submit the batch of requests to the JS queue
81-
while (!m_eventQueue.empty()) {
82-
auto &evt = m_eventQueue.front();
83-
if (!evt.expired) {
84-
m_context->CallJSFunction("RCTEventEmitter", "receiveEvent", std::move(evt.args));
81+
jsDispatcher.Post([weakThis{get_weak()}]() noexcept {
82+
auto strongThis = weakThis.get();
83+
if (!strongThis) {
84+
return;
8585
}
8686

87-
m_eventQueue.pop_front();
88-
}
87+
while (!strongThis->m_eventQueue.empty()) {
88+
auto &evt = strongThis->m_eventQueue.front();
89+
if (!evt.expired) {
90+
strongThis->m_context->CallJSFunction("RCTEventEmitter", "receiveEvent", std::move(evt.args));
91+
}
92+
93+
strongThis->m_eventQueue.pop_front();
94+
}
95+
});
8996

9097
// Don't leave the callback continuously registered as it can waste power.
9198
// See https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.compositiontarget.rendering?view=winrt-19041

0 commit comments

Comments
 (0)