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

[Bug?] How to call into JSInterop from SetParameters? #15730

Closed
chanan opened this issue Aug 3, 2018 · 4 comments
Closed

[Bug?] How to call into JSInterop from SetParameters? #15730

chanan opened this issue Aug 3, 2018 · 4 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@chanan
Copy link

chanan commented Aug 3, 2018

Now that calling JS is async it is problematic that SetParameters is still sync. In my case, I need to call a JS method inside of SetParameters before the call to _renderHandle.Render(Render);. Would it be possible to make _renderHandle.Render(Render); async as well?

@chanan
Copy link
Author

chanan commented Aug 3, 2018

In fact, I have been able to call the async code properly at all. Here is what I tried:

var updates = Task.Run(async () => await UpdateCss(css, debug, _classname, _attributesToRender)).Result;
if (updates != null) _classname = updates;
_renderHandle.Render(Render);

or as:

var updates = Task.Run(() => UpdateCss(css, debug, _classname, _attributesToRender)).Result;

in both case the Blazor app fails to load with no errors

another attempt was:

Task.Run(async () => {
   var updates = await UpdateCss(css, debug, _classname, _attributesToRender);
   if (updates != null) _classname = updates;
   _renderHandle.Render(Render);
});

Or

Task.Run(async () => {
   var updates = await UpdateCss(css, debug, _classname, _attributesToRender);
   if (updates != null) _classname = updates;
});
 _renderHandle.Render(Render);

Both these dont work either, but at least the app loads.

Is there a way to call JS from within SetParameters?

@chanan chanan changed the title Should IComponent.SetParameters be async? [Bug?] How to call into JSInterop from SetParameters? Aug 7, 2018
@chanan
Copy link
Author

chanan commented Aug 14, 2018

@SteveSandersonMS Sorry to bother you, but I think this is problematic, or am I missing something?

@Andrzej-W
Copy link

@danroth27
Copy link
Member

I need to call a JS method inside of SetParameters before the call to _renderHandle.Render(Render);.

@chanan I think making the JS call from OnParametersSetAsync should do what you want.

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/blazor Oct 27, 2019
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Oct 27, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants