fix(android): allow synchronous replies on the modern bridge#8383
Open
richavos wants to merge 1 commit intoionic-team:mainfrom
Open
fix(android): allow synchronous replies on the modern bridge#8383richavos wants to merge 1 commit intoionic-team:mainfrom
richavos wants to merge 1 commit intoionic-team:mainfrom
Conversation
Store the JavaScript reply proxy before dispatching a modern bridge message so a plugin that resolves synchronously can reply through the modern bridge instead of falling back to WebView JavaScript execution. Add a regression test for the first modern-bridge call and a minimal TextUtils host-test stub so the real postMessage path can run in unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale
On Android's modern bridge,
MessageHandlerstoredjavaScriptReplyProxyafter dispatching the message topostMessage(...).That meant a plugin that resolved synchronously during the first modern-bridge call could reach
sendResponseMessage()before the reply proxy was available, causing Capacitor to fall back to the legacyWebViewJavaScript response path.This is unreliable as a fallback, so can result in promises never being settled for plugin calls.
Changes
This change stores the reply proxy before dispatching the message, so that all plugin calls should be settlable, and adds a regression test for this scenario.
Testing
To provide a minimal test, I've added a small
TextUtilshost-test stub so the realpostMessagepath can be run in the test.I've also added two reflection-based methods that attempt to surgically insert only what is required to allow the "normal" bridge call codepath to be run.
The tradeoff here is concision against brittleness - let me know/feel free to adjust the test to fit with the project as a whole.
Change Type
Platforms Affected
Closes #8382