Skip to content

Use the async version of evaluateJavaScript method.#93

Merged
Kyome22 merged 1 commit intomainfrom
fix-compile-error
Mar 30, 2026
Merged

Use the async version of evaluateJavaScript method.#93
Kyome22 merged 1 commit intomainfrom
fix-compile-error

Conversation

@Kyome22
Copy link
Copy Markdown
Contributor

@Kyome22 Kyome22 commented Mar 27, 2026

When attempting to build the WebUI with Xcode 26.4, it was discovered that passing Any? as a result within a Task causes a "Sending 'result' risks causing data races" compiler error.

At the time of the initial WebUI implementation (March 2024), the async version of evaluateJavaScript() had the following issue:

Calling a function that returns no value (e.g., console.log(); or window.alert();) was expected to succeed and return nil, but it actually triggered a "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value" crash.

Because of this, we had been using the closure-based callback version of evaluateJavaScript().

However, this issue was fixed by the WebKit team in December 2024, and it now functions as expected in the latest Xcode.
WebKit/WebKit#37519

For these reasons, we are switching to the async version of evaluateJavaScript().

Signed-off-by: Takuto NAKAMURA (Kyome) <kyomesuke@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates WebViewProxy to use the async/await variant of WKWebView.evaluateJavaScript(_:), aligning the WebUI implementation with newer Xcode/WebKit behavior and avoiding the “Sending 'result' risks causing data races” compiler error caused by moving an Any? across a Task boundary.

Changes:

  • Replaced the continuation + completion-handler wrapper with a direct try await call to evaluateJavaScript(_:).
  • Removed the intermediate Task { @MainActor ... } hop that triggered sendability/data-race diagnostics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@antiero
Copy link
Copy Markdown

antiero commented Mar 29, 2026

I think I've just found a duplicate of this issue (#94)

Copy link
Copy Markdown
Collaborator

@b1ackturtle b1ackturtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@Kyome22 Kyome22 merged commit ccb3e63 into main Mar 30, 2026
5 of 7 checks passed
@Kyome22 Kyome22 deleted the fix-compile-error branch March 30, 2026 00:21
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.

4 participants