Skip to content

Commit

Permalink
Merge pull request #14127 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.0/pr-14067

fix: Adjust mobile hotreload (backport #14067)
  • Loading branch information
jeromelaban authored Oct 26, 2023
2 parents 002b397 + 72e539d commit 0b7e581
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ private void InitializeMetadataUpdater(ConfigureServer configureServer)
{
_ = bool.TryParse(_remoteControlServer.GetServerConfiguration("metadata-updates"), out _useRoslynHotReload);

if (_useRoslynHotReload || configureServer.EnableMetadataUpdates)
_useRoslynHotReload = _useRoslynHotReload || configureServer.EnableMetadataUpdates;

if (_useRoslynHotReload)
{
CompilationWorkspaceProvider.InitializeRoslyn(Path.GetDirectoryName(configureServer.ProjectPath));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,20 @@ private string[] GetMetadataUpdateCapabilities()
return Array.Empty<string>();
}

#if __WASM__ || __SKIA__
private void AssemblyReload(AssemblyDeltaReload assemblyDeltaReload)
{
try
{
if (Debugger.IsAttached)
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().Error($"Hot Reload is not supported when the debugger is attached.");
}

return;
}

if (assemblyDeltaReload.IsValid())
{
if (this.Log().IsEnabled(LogLevel.Trace))
Expand Down Expand Up @@ -180,7 +189,7 @@ private void AssemblyReload(AssemblyDeltaReload assemblyDeltaReload)
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().Error($"Failed to process assembly reload {assemblyDeltaReload.FilePath}, Guid:{assemblyDeltaReload.ModuleId}: {e}");
this.Log().Error($"An exception occurred when applying IL Delta for {assemblyDeltaReload.FilePath} ({assemblyDeltaReload.ModuleId})", e);
}
}
}
Expand All @@ -202,7 +211,6 @@ static int[] ReadIntArray(BinaryReader binaryReader)

return values;
}
#endif

private static async Task<bool> ShouldReload()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ public async Task ProcessFrame(Messages.Frame frame)
{
switch (frame.Name)
{
#if __WASM__ || __SKIA__
case AssemblyDeltaReload.Name:
AssemblyReload(JsonConvert.DeserializeObject<HotReload.Messages.AssemblyDeltaReload>(frame.Content)!);
break;
#endif

case FileReload.Name:
await PartialReload(JsonConvert.DeserializeObject<HotReload.Messages.FileReload>(frame.Content)!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private static void ApplyUpdate(Assembly assembly, UpdateDelta item)
}

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Hot reload is only expected to work when trimming is disabled.")]
private static Type[] GetMetadataUpdateTypes(IReadOnlyList<UpdateDelta> deltas)
private Type[] GetMetadataUpdateTypes(IReadOnlyList<UpdateDelta> deltas)
{
List<Type>? types = null;

Expand All @@ -271,6 +271,14 @@ private static Type[] GetMetadataUpdateTypes(IReadOnlyList<UpdateDelta> deltas)
}
}

if (types?.Count != deltas.SelectMany(d => d.UpdatedTypes ?? Array.Empty<int>()).Count())
{
// List all the types that were updated but not found in the assembly.
_log(
"Some types were marked as updated, but were not found in the running app. " +
"This may indicate a configuration mismatch between the compiled app and the hot reload engine.");
}

return types?.ToArray() ?? Type.EmptyTypes;
}

Expand Down

0 comments on commit 0b7e581

Please sign in to comment.