Skip to content

Commit 9aaeddb

Browse files
authored
Merge pull request #19411 from unoplatform/dev/dr/hrUpdates
fix: Fix possible null ref
2 parents d1fc1c7 + 70a7fc7 commit 9aaeddb

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.MetadataUpdate.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ select handler.Value
190190
// For instance, a DataTemplate in a resource dictionary may mark the type as updated in `updatedTypes`
191191
// but it will not be considered as a new type even if "CreateNewOnMetadataUpdate" was set.
192192

193-
return (fe, ImmutableArray<ElementUpdateHandlerActions>.Empty, liveType);
193+
return (fe, [], liveType);
194194
}
195195
else
196196
{
197-
return !handlers.IsDefaultOrEmpty || mappedType is not null
197+
return (!handlers.IsDefaultOrEmpty || mappedType is not null)
198198
? (fe, handlers, mappedType)
199-
: default;
199+
: (null, [], null);
200200
}
201201
},
202202
parentKey: default);
@@ -208,21 +208,26 @@ select handler.Value
208208
// or replace the element with a new one
209209
foreach (var (element, elementHandlers, elementMappedType) in instancesToUpdate)
210210
{
211+
if (element is null)
212+
{
213+
continue;
214+
}
215+
211216
// Action: ElementUpdate
212217
// This is invoked for each existing element that is in the tree that needs to be replaced
213218
foreach (var elementHandler in elementHandlers)
214219
{
215220
elementHandler?.ElementUpdate(element, updatedTypes);
221+
}
216222

217-
if (elementMappedType is not null)
223+
if (elementMappedType is not null)
224+
{
225+
if (_log.IsEnabled(LogLevel.Trace))
218226
{
219-
if (_log.IsEnabled(LogLevel.Trace))
220-
{
221-
_log.Error($"Updating element [{element}] to [{elementMappedType}]");
222-
}
223-
224-
ReplaceViewInstance(element, elementMappedType, elementHandler);
227+
_log.Error($"Updating element [{element}] to [{elementMappedType}]");
225228
}
229+
230+
ReplaceViewInstance(element, elementMappedType, elementHandlers, updatedTypes);
226231
}
227232
}
228233

@@ -408,7 +413,7 @@ private static void UpdateResourceDictionaries(List<Uri> updatedDictionaries, Re
408413
}
409414
#endif
410415

411-
private static void ReplaceViewInstance(UIElement instance, Type replacementType, ElementUpdateAgent.ElementUpdateHandlerActions? handler = default, Type[]? updatedTypes = default)
416+
private static void ReplaceViewInstance(UIElement instance, Type replacementType, in ImmutableArray<ElementUpdateHandlerActions> handlers, Type[] updatedTypes)
412417
{
413418
if (replacementType.GetConstructor(Array.Empty<Type>()) is { } creator)
414419
{
@@ -429,11 +434,17 @@ private static void ReplaceViewInstance(UIElement instance, Type replacementType
429434
oldStore.ClonePropertiesToAnotherStoreForHotReload(newStore);
430435
#endif
431436

432-
handler?.BeforeElementReplaced(instanceFE, newInstanceFE, updatedTypes);
437+
foreach (var handler in handlers)
438+
{
439+
handler.BeforeElementReplaced(instanceFE, newInstanceFE, updatedTypes);
440+
}
433441

434442
SwapViews(instanceFE, newInstanceFE);
435443

436-
handler?.AfterElementReplaced(instanceFE, newInstanceFE, updatedTypes);
444+
foreach (var handler in handlers)
445+
{
446+
handler.AfterElementReplaced(instanceFE, newInstanceFE, updatedTypes);
447+
}
437448
}
438449
}
439450
else

0 commit comments

Comments
 (0)