Skip to content

Conversation

@TimonFeldmann
Copy link
Contributor

@TimonFeldmann TimonFeldmann commented Jul 21, 2024

Pull Request

📖 Description

This issue occurs exclusively in version 4.9.2, downgrading to 4.9.1 resolves the issue.

When injecting any design token and calling .SetValue() with any element reference, the DesignToken class fails to inject the registered LibraryConfiguration causing an Object reference not set to an instance of an object exception to be thrown inside UrlFormatterExtensions.cs.

🎫 Issues

Fix for #2425

👩‍💻 Reviewer Notes

Component:

@using Microsoft.FluentUI.AspNetCore.Components.DesignTokens

<div class="container">
	<FluentTextField @ref="Test" @bind-Value=Title></FluentTextField>
</div>

@code {
	[Parameter, EditorRequired]
	public string Title { get; set; } = null!;

	FluentTextField Test;

	[Inject]
	private Density _density { get; set; } = default!;

	protected override async Task OnAfterRenderAsync(bool firstRender)
	{
		if (firstRender)
		{
			await _density.SetValueFor(Test.Element, 10);

			StateHasChanged();
		}
	}
}

Startup:

    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });

            builder.Services.AddMauiBlazorWebView();
	    builder.Services.AddHttpClient();
            builder.Services.AddFluentUIComponents();

#if DEBUG
            builder.Services.AddBlazorWebViewDeveloperTools();
            builder.Logging.AddDebug();
#endif

            return builder.Build();
        }
    }

📑 Test Plan

Utilize the above code to reproduce this issue on version 4.9.2.

Rendering the Component code I outlined above, you should receive an exception on the following line without my change:

await _density.SetValueFor(Test.Element, 10);

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

- Add LibraryConfiguration to DesignTokenGenerator.
@TimonFeldmann TimonFeldmann changed the title - Missing LibraryConfiguring Injection in DesignToken.razor.c - Missing LibraryConfiguring Injection in DesignToken.razor.cs Jul 21, 2024
@TimonFeldmann
Copy link
Contributor Author

@microsoft-github-policy-service agree

@TimonFeldmann TimonFeldmann changed the title - Missing LibraryConfiguring Injection in DesignToken.razor.cs Missing LibraryConfiguring Injection in DesignToken.razor.cs - #2425 Jul 21, 2024
@vnbaaij vnbaaij added this to the v4.9.3 milestone Jul 22, 2024
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.

Possible bug in the 4.9.2 javascript Toolbar example preview error Fix For: Missing LibraryConfiguring Injection in DesignToken.razor.cs

2 participants