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

[#104] Implement StyledGroup component to handle style loading state. #105

Closed
wants to merge 7 commits into from

Conversation

esso23
Copy link

@esso23 esso23 commented Jun 18, 2020

#104

WIP

Usage:

<StyledGroup @bind-Loading="@mLoading">
    <Styled>
        ...
    </Styled>
    ...
</StyledGroup>
<Component style="@Visibility">
    ...
</Component>
private bool mLoading = true;
private string Visibility => mLoading ? "visibility: hidden" : null;

This is my proposal to solve the issue mentioned in #104.
Possible improvements:

  • StyledGroup could provide the visibility style directly.
  • StyledGroup could be renamed to something more descriptive

@esso23 esso23 changed the title Implement StyledGroup component to handle style loading state. [#104] Implement StyledGroup component to handle style loading state. Jun 18, 2020
@chanan
Copy link
Owner

chanan commented Jun 18, 2020

Awesome, I will take a look at this after I fix the issues with system.text.json and the object pool extensions dll.

Regarding performance, Many of the performance gains of v3 are in parsing code which occur prior to the javascript call. What are you thoughts of v3.5 adding back the older style of writting to the head using a Blazor tag (like it was doing in v2) assuming that part is faster than the pure javascript way. You would lose some functionality but I don't think you are using those things anyway. It would take some work on my part to support both ways, but then end user can choose which way they want to use BlazorStyled. Thoughts?

@esso23
Copy link
Author

esso23 commented Jun 23, 2020

Tested on my current project, seems to work fine.

Known issues:

  • Since OnAfterRender is called many times for some reason, I still sometimes see a small (few millisecond) flicker when rendering starts. This is caused by a call to StyleGroupContext.SetRendering(false); in OnAfterRenderAsync a small delay and then registering new tasks which causes the context to switch to finalized state for a brief moment and then switch back to Loading state.
    I was thinking about implementing a simple debouncer for this purpose, but I don't want to overcomplicate things.

Remarks:

  • I'm not sure what will happen when you use nesting of StyleGroup components.
  • StyleGroup applies to all components and their children in the hierarchy, which can generate a lot of tasks. In my case, it's around 5-6 thousand tasks registered when rendering a larger component. Can be tens of thousands in some cases.

Answering your question:
I think I already answered it in the issue. The difference in performance is not caused by the approach you chose in v2/v3, but in the execution. When executed in parallel and asynchronously, the performance is actually very similar, so I see no reason to revert back to the old approach.

@chanan
Copy link
Owner

chanan commented Jun 25, 2020

@esso23 I was waiting for MS to solve: dotnet/aspnetcore#23126 before merging this, but it seems it isn't going to be so fast, so I will merge this either over the weekend or early next week. Sorry for the delay.

@esso23
Copy link
Author

esso23 commented Jun 25, 2020

I pushed the debouncer aswell since it was useless without it in my case. I was using timeouts between 250-500ms to eliminate flickers.
Feel free to revert it if you don't want it there.
The obvious downside is that loading cannot take less than the timeout (but only if the styles are not loaded yet).

@chanan
Copy link
Owner

chanan commented Sep 5, 2020

@esso23 Sorry for the very late reply on this. I was finally able to fix the issue with BlazorStyled and system.text.json.

I put the Tag <StyledGroup> around all the cshtml in MainLayout.cs. Running the client side project worked fine. However running the ServerSideSample project exits debug mode without a lot of information:

C:\Users\cbraunstein\source\Personal\BlazorStyled\src\ServerSideSample\bin\Debug\netcoreapp3.1\ServerSideSample.exe (process 23632) exited with code -1073741819.

and in the output window:

The program '[23632] ServerSideSample.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

@chanan
Copy link
Owner

chanan commented Nov 17, 2020

A little more info on this, there seems to be an infinite loop in StyledGroupContext.SetRendering

@chanan
Copy link
Owner

chanan commented Nov 17, 2020

Released 3.1.0

@chanan chanan closed this Nov 17, 2020
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.

2 participants