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[ReactDevTools]: wrap sendMessage expressions in setTimeout #113

Merged
merged 1 commit into from
Sep 9, 2024
Merged
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
10 changes: 8 additions & 2 deletions front_end/models/react_native/ReactDevToolsBindingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,14 @@ export class ReactDevToolsBindingsModel extends SDK.SDKModel.SDKModel {
}

const serializedMessage = JSON.stringify(message);

await runtimeModel.agent.invoke_evaluate({expression: `${RUNTIME_GLOBAL}.sendMessage('${domainName}', '${serializedMessage}')`});
const sendMessageExpression = `${RUNTIME_GLOBAL}.sendMessage('${domainName}', '${serializedMessage}')`;

// As of today, all expressions which were scheduled via Runtime.evaluate method are not going through RuntimeScheduler
// This means that the task is not being placed on the Event Loop, and any transitively called Microtasks are not executed properly
// 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
// See T200616136 for more context
// TODO(hoxyq): remove setTimeout once Runtime.evaluate expressions are passed through React Native Runtime Scheduler
await runtimeModel.agent.invoke_evaluate({expression: `void setTimeout(() => ${sendMessageExpression}, 0)`});
}

async enable(): Promise<void> {
Expand Down
Loading