Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Summary of the changes

Blazor components can now use @layout null to disable layouts without compilation errors. Previously, this generated invalid C# code [LayoutAttribute(typeof(null))] causing build failures.

Implementation:

  • ComponentLayoutDirectivePass.cs - Skip LayoutAttribute generation when token content is "null"
  • DesignTimeDirectiveTargetExtension.cs - Skip type validation for "null" directive tokens to prevent invalid design-time code

Generated code:

// Before: compilation error
[LayoutAttribute(typeof(null))]  // typeof(null) is invalid C#

// After: no attribute, component has no layout
public partial class TestComponent : ComponentBase
{
    // Clean - no LayoutAttribute
}

Components without a LayoutAttribute are treated as having no layout by the framework.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • bcnvsblobprodcus378.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet build src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for @layout null in blazor</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.
Sometimes you need no layout within a blazor app for some pages, e.g. for a print preview.
Adding @layout null to the component results in not compilable code.

This StackOverflow post does the trick but it should work by default just like in razor pages.
https://stackoverflow.com/questions/59518988/disable-layout-for-page-under-blazor

</issue_description>

Comments on the Issue (you are @copilot in this section)

@ Thanks for contacting us. We're moving this issue to the `Next sprint planning` milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process [here](https://github.com/dotnet/aspnetcore/blob/master/docs/TriageProcess.md). @ We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our [Triage Process](https://github.com/dotnet/aspnetcore/blob/master/docs/TriageProcess.md). @ We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our [Triage Process](https://github.com/dotnet/aspnetcore/blob/main/docs/TriageProcess.md). @SteveSandersonMS > wouldn't this be a compiler ask or is this something to enable on Blazor side?

Yes I think it would be a compiler feature.</comment_new>
<comment_new>@SteveSandersonMS

Otherwise, it doesn't seem possible?

You can always render in an otherwise-blank layout, but I agree it's strange and inconvenient.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: dbreshears <3432571+dbreshears@users.noreply.github.com>
@dbreshears dbreshears assigned chsienki and unassigned dbreshears Jan 16, 2026
Co-authored-by: dbreshears <3432571+dbreshears@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for @layout null in Blazor Add support for @layout null in Blazor components Jan 16, 2026
Copilot AI requested a review from dbreshears January 16, 2026 00:49
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.

Add support for @layout null in blazor

3 participants