Skip to content

fix(android): unblock WebView JS thread during bridge event dispatch#28

Open
modos189 wants to merge 1 commit into
nativescript-community:masterfrom
modos189:fix/async-bridge
Open

fix(android): unblock WebView JS thread during bridge event dispatch#28
modos189 wants to merge 1 commit into
nativescript-community:masterfrom
modos189:fix/async-bridge

Conversation

@modos189
Copy link
Copy Markdown
Contributor

Problem

emitEventToNativeScript runs on the JavaBridge thread. NativeScript dispatches the call to its V8 thread and blocks until the handler completes - store updates, native view property changes, etc.

Under frequent bridge calls in complex scenes with many active scripts, this starves the WebView render pipeline by 10–30 ms per call, accumulating to hundreds of milliseconds of blocked time per second.

Fix

Wrap onWebViewEvent in setTimeout(0) so the JavaBridge thread returns immediately and NativeScript processes the event on its next tick.

Trade-off

Events become asynchronous relative to the WebView caller. Any code that relies on NativeScript state being updated synchronously after a bridge call would be affected. However, this path is architecturally one-way: emitEventToNativeScript is declared void in the @JavascriptInterface contract, so no return value can be passed back to WebView JS regardless. The NativeScript -> WebView channel operates independently via executeJavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant