dotnet / dotnet/roslyn

Blazor local functions in ChildContent don't work correctly

Open
#85,524 4 comments 0 reactions 0 assignees View on GitHub
Area-Razor Area-Razor-Compiler Bug Investigation Required
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

When I call local functions in @{} block inside a .razor component tag the content from the local function isn't getting rendered.

Home.razor
```razor
@page "/"

Issue showcase

Hello 1

@{
IssueLocalFunction();
}

@{
void IssueLocalFunction()
{
Hello 2
}
}
```
IssueComponent.razor
```razor
@ChildContent

@code {
[Parameter]
public RenderFragment? ChildContent { get; set; }
}
```
Output

![image](https://github.com/dotnet/roslyn/assets/160616131/bb212af3-d7fe-46cb-bf1b-5fd0bd551325)

It's getting showed when is prerendering but then it disappears.
Here is my repo with that issue:
https://github.com/EngieDev/BlazorComponentsIssue

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.