Skip to content

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

Merged
mattleibow merged 2 commits intomainfrom
dev/hybridwebview-void-return
Jan 23, 2025
Merged

[HybridWebView] Support calling void and "no return" functions in JS#27094
mattleibow merged 2 commits intomainfrom
dev/hybridwebview-void-return

Conversation

@mattleibow
Copy link
Copy Markdown
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 AI 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
Copy Markdown
Contributor

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
@mattleibow
Copy link
Copy Markdown
Member Author

UI test failures unrelated.

@mattleibow mattleibow merged commit d2ed19b into main Jan 23, 2025
@mattleibow mattleibow deleted the dev/hybridwebview-void-return branch January 23, 2025 14:46
@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-hybridwebview HybridWebView control

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

HybridWebView should have a way for C# to call a JS method that doesn't have any return value (or ignore the return value)

3 participants