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

[HybridWebView] Support calling void and "no return" functions in JS #27094

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Jan 13, 2025

Description of Change

Currently, the HybridWebView assumes that all functions return a value and immediately tries to deserialize the result.

This PR changes that to first check to see if the value is "null" / "undefined" and then skips the deserialization since those values represent null in .NET.

There is also a new API in the HybridWebView control that provides a way to avoid having to provide a type and type info that will just be ignored.

After this PR, there will be 3 ways to invoke a void function:

  1. hybridWebView.InvokeJavaScriptAsync<TReturn>(name, TReturn info, ...)
    This is the current way, we just no longer crash if the return value is null.
  2. hybridWebView.InvokeJavaScriptAsync<TReturn>(name, null, ...)
    This is a better way, we allow passing null as the type info, but we still need the generic argument - which can be anything, object, string, etc
  3. NEW hybridWebView.InvokeJavaScriptAsync(name, ...)
    This is the new API where it is not generic and does not have a return type info parameter

Issues Fixed

Fixes #26766

Outstanding Work

Since the API can't be changed for .NET 9, we will need to delay the one small part: #27191

Void methods can still be run, just not with the new API.

@Copilot Copilot bot review requested due to automatic review settings January 13, 2025 13:21
@mattleibow mattleibow requested a review from a team as a code owner January 13, 2025 13:21
Copy link
Contributor

@Copilot 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.

Copilot reviewed 4 out of 20 changed files in this pull request and generated 2 comments.

Files not reviewed (16)
  • src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt: Language not supported
  • src/Controls/tests/DeviceTests/Resources/Raw/HybridTestRoot/index.html: Language not supported
  • src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt: Language not supported
  • src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt: Language not supported
Comments suppressed due to low confidence (1)

src/Controls/src/Core/HybridWebView/HybridWebView.cs:84

  • Ensure that the new method InvokeJavaScriptAsync in HybridWebView is covered by tests.
public async Task InvokeJavaScriptAsync(string methodName, object?[]? paramValues = null, JsonTypeInfo?[]? paramJsonTypeInfos = null)

@mattleibow mattleibow added this to the .NET 9 SR4 milestone Jan 13, 2025
@mattleibow mattleibow requested a review from Eilon January 13, 2025 13:41
@mattleibow mattleibow added the area-controls-hybridwebview HybridWebView control label Jan 13, 2025
@mattleibow mattleibow assigned mattleibow and unassigned mattleibow Jan 13, 2025
@mattleibow mattleibow changed the title Support calling void and "no return" functions in JS [HybridWebView] Support calling void and "no return" functions in JS Jan 15, 2025
@mattleibow mattleibow marked this pull request as draft January 17, 2025 12:19
@mattleibow mattleibow marked this pull request as ready for review January 17, 2025 12:31
@mattleibow mattleibow force-pushed the dev/hybridwebview-void-return branch from 984dd0e to e7ec0f0 Compare January 17, 2025 12:35
@mattleibow mattleibow force-pushed the dev/hybridwebview-void-return branch from 03b2d48 to b2e89c6 Compare January 17, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-hybridwebview HybridWebView control
Projects
Status: Ready To Review
1 participant