Skip to content

Commit e32908e

Browse files
authored
fix[ReactDevTools]: wrap sendMessage expressions in setTimeout (#113)
1 parent c4c9edf commit e32908e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

front_end/models/react_native/ReactDevToolsBindingsModel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ export class ReactDevToolsBindingsModel extends SDK.SDKModel.SDKModel {
161161
}
162162

163163
const serializedMessage = JSON.stringify(message);
164-
165-
await runtimeModel.agent.invoke_evaluate({expression: `${RUNTIME_GLOBAL}.sendMessage('${domainName}', '${serializedMessage}')`});
164+
const sendMessageExpression = `${RUNTIME_GLOBAL}.sendMessage('${domainName}', '${serializedMessage}')`;
165+
166+
// As of today, all expressions which were scheduled via Runtime.evaluate method are not going through RuntimeScheduler
167+
// This means that the task is not being placed on the Event Loop, and any transitively called Microtasks are not executed properly
168+
// We are wrapping the expression in setTimeout to make sure that this code (and everything what is called by it) goes through the Event Loop implementation
169+
// See T200616136 for more context
170+
// TODO(hoxyq): remove setTimeout once Runtime.evaluate expressions are passed through React Native Runtime Scheduler
171+
await runtimeModel.agent.invoke_evaluate({expression: `void setTimeout(() => ${sendMessageExpression}, 0)`});
166172
}
167173

168174
async enable(): Promise<void> {

0 commit comments

Comments
 (0)