-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add API to Renderer to trigger a UI refresh on hot reload #30884
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
Changes from all commits
55e88af
7311d25
eec977a
89b9b4b
ee77867
cebf3bf
b9e9b5a
faadec8
aea65f3
5bbe396
d9e3b4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.HotReload | ||
{ | ||
/// <summary> | ||
/// A context that indicates when a component is being rendered because of a hot reload operation. | ||
/// </summary> | ||
public sealed class HotReloadContext | ||
{ | ||
/// <summary> | ||
/// Gets a value that indicates if the application is re-rendering in response to a hot-reload change. | ||
/// </summary> | ||
public bool IsHotReloading { get; internal set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.AspNetCore.Components.HotReload | ||
{ | ||
internal class HotReloadEnvironment | ||
{ | ||
public static readonly HotReloadEnvironment Instance = new(Environment.GetEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES") == "debug"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any chance that a static constructor prevents the linker from removing the type? I would guess that static constructors may always have side effects and hence always have to be left in and will run. It's probably not a big deal. I'll leave it up to you whether you think it's worth doing in a less convenient way! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I have no idea how smart the linker is about figuring out whether the static constructor would run or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static ctors are hard to trim away and guarantee correctness. I believe the only time a static ctor will be trimmed is if the whole type can be trimmed. Maybe also if it was @vitek-karas and @MichalStrehovsky would know the exact rules here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the rule is basically:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was able to do some "fun" substitutions.xml to trim references to this type. Here's what the trimmed results look like now: Removing the interface and the context is difficult because |
||
|
||
public HotReloadEnvironment(bool isHotReloadEnabled) | ||
{ | ||
IsHotReloadEnabled = isHotReloadEnabled; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value that determines if HotReload is configured for this application. | ||
/// </summary> | ||
public bool IsHotReloadEnabled { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Reflection; | ||
|
||
[assembly: AssemblyMetadata("ReceiveHotReloadDeltaNotification", "Microsoft.AspNetCore.Components.HotReload.HotReloadManager")] | ||
|
||
namespace Microsoft.AspNetCore.Components.HotReload | ||
{ | ||
internal static class HotReloadManager | ||
{ | ||
internal static event Action? OnDeltaApplied; | ||
|
||
public static void DeltaApplied() | ||
{ | ||
OnDeltaApplied?.Invoke(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.HotReload | ||
{ | ||
/// <summary> | ||
/// Allows a component to receive a <see cref="HotReloadContext"/>. | ||
/// </summary> | ||
public interface IReceiveHotReloadContext : IComponent | ||
{ | ||
/// <summary> | ||
/// Configures a component to use the hot reload context. | ||
/// </summary> | ||
/// <param name="context">The hot reload context.</param> | ||
void Receive(HotReloadContext context); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<linker> | ||
<assembly fullname="Microsoft.AspNetCore.Components" > | ||
<!-- HotReload will not be available in a trimmed app. We'll attempt to aggressively remove all references to it. --> | ||
<type fullname="Microsoft.AspNetCore.Components.RenderTree.Renderer"> | ||
<method signature="System.Void RenderRootComponentsOnHotReload()" body="remove" /> | ||
<method signature="System.Void InitializeHotReload(System.IServiceProvider)" body="stub" /> | ||
<method signature="System.Void InstatiateComponentForHotReload(Microsoft.AspNetCore.Components.IComponent)" body="stub" /> | ||
<method signature="System.Void CaptureRootComponentForHotReload(Microsoft.AspNetCore.Components.ParameterView,Microsoft.AspNetCore.Components.Rendering.ComponentState)" body="stub" /> | ||
<method signature="System.Void DisposeForHotReload()" body="stub" /> | ||
</type> | ||
<type fullname="Microsoft.AspNetCore.Components.HotReload.HotReloadContext"> | ||
<method signature="System.Boolean get_IsHotReloading()" body="stub" value="false" /> | ||
<method signature="System.Void set_IsHotReloading(System.Boolean)" body="remove" /> | ||
</type> | ||
<type fullname="Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder"> | ||
<method signature="System.Boolean IsHotReloading(Microsoft.AspNetCore.Components.RenderTree.Renderer)" body="stub" value="false" /> | ||
</type> | ||
</assembly> | ||
pranavkm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</linker> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ Microsoft.AspNetCore.Components.ComponentApplicationState.PersistAsJson<TValue>( | |
Microsoft.AspNetCore.Components.ComponentApplicationState.PersistState(string! key, byte[]! value) -> void | ||
Microsoft.AspNetCore.Components.ComponentApplicationState.TryTakeAsJson<TValue>(string! key, out TValue? instance) -> bool | ||
Microsoft.AspNetCore.Components.ComponentApplicationState.TryTakePersistedState(string! key, out byte[]? value) -> bool | ||
Microsoft.AspNetCore.Components.HotReload.HotReloadContext | ||
Microsoft.AspNetCore.Components.HotReload.HotReloadContext.HotReloadContext() -> void | ||
Microsoft.AspNetCore.Components.HotReload.HotReloadContext.IsHotReloading.get -> bool | ||
Microsoft.AspNetCore.Components.HotReload.IReceiveHotReloadContext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we replace this with a property on |
||
Microsoft.AspNetCore.Components.HotReload.IReceiveHotReloadContext.Receive(Microsoft.AspNetCore.Components.HotReload.HotReloadContext! context) -> void | ||
Microsoft.AspNetCore.Components.Lifetime.ComponentApplicationLifetime | ||
Microsoft.AspNetCore.Components.Lifetime.ComponentApplicationLifetime.ComponentApplicationLifetime(Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Components.Lifetime.ComponentApplicationLifetime!>! logger) -> void | ||
Microsoft.AspNetCore.Components.Lifetime.ComponentApplicationLifetime.PersistStateAsync(Microsoft.AspNetCore.Components.Lifetime.IComponentApplicationStateStore! store, Microsoft.AspNetCore.Components.RenderTree.Renderer! renderer) -> System.Threading.Tasks.Task! | ||
|
Uh oh!
There was an error while loading. Please reload this page.