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

.NET 8 Blazor - Navigation - AuthenticationStateProvider Bug #58009

Closed
1 task done
MusixTX opened this issue Sep 21, 2024 · 3 comments
Closed
1 task done

.NET 8 Blazor - Navigation - AuthenticationStateProvider Bug #58009

MusixTX opened this issue Sep 21, 2024 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue Status: No Recent Activity

Comments

@MusixTX
Copy link

MusixTX commented Sep 21, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

A very interesting issue. I have a NavMenu that loads dynamic NavItems. I built a nice template and created the following element for subitems:

<li class="mb-1 mt-1">
    <NavLink href="@subItem.Route" class="link-body-emphasis d-inline-flex text-decoration-none rounded fs-6">
        <span>@subItem.Name</span>
    </NavLink>
</li>

In the past few days, I was desperately trying to figure out why client-side rendered components were behaving strangely. As long as a NavItem had no subitems, my UserService, which accesses the AuthenticationStateProvider, worked without any issues. However, when I navigated using a subitem, the AuthenticationState was always "Unauthenticated". After removing any potential sources of error from the components (the components are, in this case, pages), the only remaining possible issue was the navigation. Interestingly, the AuthState was correctly loaded when I navigated directly via the browser link.

The issue can easily be resolved by embedding an HTML element in the @subItem.Name. But so the enhanced navigation wont work anymore. So maybe this is the problem.

Update:
Its definitive caused by enhanced navigation, if you set data-enhance-nav="false" the problem is gone, but the navbar always reloads...

<li class="mb-1 mt-1">
    <NavLink href="@subItem.Route" class="link-body-emphasis d-inline-flex text-decoration-none rounded fs-6">
        <a>@subItem.Name</a>
    </NavLink>
</li>

Expected Behavior

AuthenticationStateProvider returns IsAuthenticated = false

Steps To Reproduce

Navigate with this NavLink:

<li class="mb-1 mt-1">
    <NavLink href="@subItem.Route" class="link-body-emphasis d-inline-flex text-decoration-none rounded fs-6">
        @subItem.Name
    </NavLink>
</li>

Exceptions (if any)

IsAuthenticated = false

.NET Version

8.0.400

Anything else?

The problem also occurs, if you simply use the <a> Tag. So its not based on the <NavLink />

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Sep 21, 2024
@MusixTX MusixTX changed the title .NET 8 Blazor - Navigation - AuthenticationStateProvider Issue .NET 8 Blazor - Navigation - AuthenticationStateProvider Bug Sep 21, 2024
@javiercn javiercn added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue labels Sep 23, 2024
Copy link
Contributor

Hi @MusixTX. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Copy link
Contributor

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue Status: No Recent Activity
Projects
None yet
Development

No branches or pull requests

2 participants