Skip to content

Conversation

@MattyLeslie
Copy link
Contributor

Add DateOnly and TimeOnly support in Blazor change detection

Summary of the changes (Less than 80 chars)
Add DateOnly and TimeOnly as known immutable types in Blazor change detection.

Description

Updated the ChangeDetection class to include DateOnly and TimeOnly in the IsKnownImmutableType method. Introduced a caching mechanism to store immutability checks results using a ConcurrentDictionary<T, U> for performance optimization. Added support for hot reload to clear the cache when a hot reload event occurs.

Fixes #49021

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label May 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 28, 2024
@MattyLeslie MattyLeslie marked this pull request as ready for review May 28, 2024 14:48
@MattyLeslie MattyLeslie requested a review from a team as a code owner May 28, 2024 14:48
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jun 4, 2024
@MattyLeslie
Copy link
Contributor Author

@MackinnonBuck, may I please request a review for this.

Copy link
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MattyLeslie! Looks good so far - just a few suggestions. Let me know if you'd like me to take it from here.

Comment on lines 55 to 66
public static event Action? OnHotReload;

public static void ClearImmutableTypeCache()
{
_immutableNonObjectTypesCache.Clear();
}

public static void HotReloadHandler()
{
ClearImmutableTypeCache();
OnHotReload?.Invoke();
}
Copy link
Member

@MackinnonBuck MackinnonBuck Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like this hooks into the hot reload OnDeltaApplied event, so the cache will never get cleared.

This can all probably be reduced down to something like what we do for RouteView:

static RouteView()
{
if (HotReloadManager.Default.MetadataUpdateSupported)
{
HotReloadManager.Default.OnDeltaApplied += _layoutAttributeCache.Clear;
}
}

@MattyLeslie
Copy link
Contributor Author

@MackinnonBuck If you're will to carry it over the line that would be great otherwise I'll address that feedback as soon as I get time.

@MackinnonBuck MackinnonBuck force-pushed the DateOnly-and-TimeOnly-is-not-supported-in-Blazor-change-detection-for-parameters branch from 800f788 to 77fd269 Compare October 21, 2024 18:58
@MackinnonBuck MackinnonBuck merged commit 92ba095 into dotnet:main Oct 21, 2024
27 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Oct 21, 2024
captainsafia pushed a commit that referenced this pull request Feb 11, 2025
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 community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DateOnly and TimeOnly is not supported in Blazor change detection for parameters

2 participants