Skip to content

Doing something that requires a re-render in OnAfterRender doesn't seem to work #8435

@DeanRoddey

Description

@DeanRoddey

Describe the bug

Since you can't (I think) depend on component references to be valid until OnAfterRender, that seems to be the only place you can make calls to your components to do any manual setup. But, if any of those requires a re-render, it doesn't seem to work (I'm on the 0.9.0 blazor stuff in VS Preview 4.1.)

Does the 'need to re-render' flag get cleared upon return from OnAfterRender()? Or is it not legal to do things that will require a re-render in OnAfterRender? If the latter I would think another callback needs to be made of the DoComponentSetup() type or something.

If I make calls to components in OnAfterRender() and they call StateHasChanged(), those changes aren't rendered. Only the stuff (presumably) that where rendered before OnAfterRender() area actually rendered.

Before going through the hassle of trying to create some reproduceable bit, I just wanted to make sure it is supposed to be OK to do this kind of thing. If not, then it's just that we need some sort of component setup callback. If it's supposed to work, maybe someone else can sanity check me, and I can try to create a small scenario that demonstrates it.

The particular scenario is setting the selected row in a list box component. We can't know that until we get initialized and get the data loaded. And then we can't actually set it until the component references are valid. So I'm setting them in OnAfterRender, and calling StateHasChanged(), but those changes are never rendered in the initial display of the screen. The selection visually stays on the 0th row. I can see in the debugger that the call is made and the target index is stored and StateHasChanged() is called.

But she no redraw.

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions