Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a6b40e9
Name the component, not its element, in RenderError
azchohfi Oct 2, 2026
3404692
Report render errors an ErrorBoundary catches
azchohfi Oct 2, 2026
6728ac4
Cover RenderError on func/memo mount, nested boundary throws, and bot…
azchohfi Oct 5, 2026
96b4ab9
Cache generic component names and skip ComponentUnmount naming when t…
azchohfi Oct 5, 2026
d348e74
CHANGELOG: RenderError names the component and reports every render e…
azchohfi Oct 5, 2026
fe20e8f
Record the render-error catches in the spec-044 swallowed-error ledger
azchohfi Oct 5, 2026
5f95751
Don't read Exception.Message when emitting RenderError
azchohfi Oct 5, 2026
b1c100e
Report every exception an ErrorBoundary recovers from; fix stale attr…
azchohfi Oct 5, 2026
d8496be
Report OOM/SO render failures outside a boundary too
azchohfi Oct 6, 2026
4075055
Merge origin/main into azchohfi-render-error-component-name
azchohfi Oct 7, 2026
9ee41ea
Report root effect failures; name rollback unmounts like other unmounts
azchohfi Oct 7, 2026
0469209
Attribute root failures to the root that threw; format generic array …
azchohfi Oct 7, 2026
10f0fdb
Merge origin/main into azchohfi-render-error-component-name
azchohfi Oct 7, 2026
ef58dd2
Name derived function/memo elements by their own type on mount
azchohfi Oct 7, 2026
288575b
Merge remote-tracking branch 'origin/main' into azchohfi-render-error…
azchohfi Oct 7, 2026
b585258
Format generic derived element names like any other generic component
azchohfi Oct 7, 2026
918ab90
Merge remote-tracking branch 'origin/main' into azchohfi-render-error…
azchohfi Oct 7, 2026
3cc6999
Use System.Threading.Lock for the host registry gate (IDE0330)
azchohfi Oct 7, 2026
671fed2
Merge remote-tracking branch 'origin/main' into azchohfi-render-error…
azchohfi Oct 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ Conventions for contributors:

### Fixed

- **`RenderError` names the component that threw, and now reports every render
error** (issue #1321, spec 044 §6.2.1). For class components the event reported
Comment thread
azchohfi marked this conversation as resolved.
the element record (``ComponentElement`1`` / `ComponentElement`) instead of the
component unless the `Render` keyword was also on, so an Errors-only listener
such as `winapp devtools logs` could not tell which component failed. It now
reports the component's type name (`Counter`; a generic one as `Foo<Int32>`),
and the other per-component events agree on it. **Listeners now also receive
errors that were previously silent:** a component (class, function or memo)
throwing on its first render, a `ReactorHost` / `ReactorHostControl` root
component or render function throwing, and any render error an `ErrorBoundary`
catches — reported once, at the throw site, even though the app shows the
fallback. Same event, same payload; the message stays redacted. Generic
component names change from ``Foo`1`` to `Foo<Int32>` in every component event.

- **Dropping an `AutoSuggestBox` right after its text changed can no longer crash
the app** (PR #1302, supersedes #559). WinUI raises the box's `TextChanged` from
an internal timer 150 ms after its text last changed, keeps that timer running
Expand Down
13 changes: 9 additions & 4 deletions docs/_pipeline/templates/source-mapping.md.dt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ consumers can subscribe to just the render channel:
```csharp snippet="source:src/Reactor/Core/Diagnostics/ReactorEventSource.cs#etw-keywords"
```

`ComponentRenderStart` / `ComponentRenderStop` fire with
`componentName = node.Component?.GetType().Name`. That string is the
`ComponentRenderStart` / `ComponentRenderStop` fire with the component's
type name — `Counter` for a `Counter : Component<CounterProps>`, whichever
factory created it. That string is the
attribution token that flows into PerfView / `dotnet-trace` /
`xperf`, and it is the same string [`devtools-internals`](devtools-internals.md)
uses to label overlay frames. Per-component, not per-element — but
sufficient for the common question "which component is re-rendering
on every tick".
on every tick". `RenderError`, `EffectsFlushStart` / `Stop` and
`ComponentUnmount` use the same name. A generic component reports its type
arguments in C# form (`ItemList<Int32>`, not ``ItemList`1``); function and memo
components, which have no type of their own, report `FuncElement` and
`MemoElement`.

![Source attribution: component-name attribution flows Component.GetType().Name into ETW, while per-element attribution stamps each DSL call site with file and line via the interceptor generator, readable from any realized control through ReactorSourceMap.GetSource.](images/source-mapping/attribution.svg)

Expand All @@ -67,7 +72,7 @@ on every tick".
| `ReconcileStart` / `Stop` | Root element type + diff counters | ETW `Reconcile` keyword |
| `EffectsFlushStart` / `Stop` | Component CLR type name | ETW `Render` keyword |
| `StateChange` | Hook kind + value type | ETW `State` keyword |
| `RenderError` | Component name + exception type only (message redacted) | ETW `Errors` keyword |
| `RenderError` | Component name + exception type only (message redacted); emitted on mount, update and host-root renders, including errors an `ErrorBoundary` catches (named at the throw site, once) | ETW `Errors` keyword |
| Per-element file:line | Element call site | `Element.CallSite` / `ReactorSourceMap.GetSource` (when source mapping is enabled at build time) |

The reconcile pass also emits a counter summary on stop:
Expand Down
13 changes: 9 additions & 4 deletions docs/guide/source-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ public static class Keywords
}
```

`ComponentRenderStart` / `ComponentRenderStop` fire with
`componentName = node.Component?.GetType().Name`. That string is the
`ComponentRenderStart` / `ComponentRenderStop` fire with the component's
type name — `Counter` for a `Counter : Component<CounterProps>`, whichever
factory created it. That string is the
attribution token that flows into PerfView / `dotnet-trace` /
`xperf`, and it is the same string [`devtools-internals`](devtools-internals.md)
uses to label overlay frames. Per-component, not per-element — but
sufficient for the common question "which component is re-rendering
on every tick".
on every tick". `RenderError`, `EffectsFlushStart` / `Stop` and
`ComponentUnmount` use the same name. A generic component reports its type
arguments in C# form (`ItemList<Int32>`, not ``ItemList`1``); function and memo
components, which have no type of their own, report `FuncElement` and
`MemoElement`.

![Source attribution: component-name attribution flows Component.GetType().Name into ETW, while per-element attribution stamps each DSL call site with file and line via the interceptor generator, readable from any realized control through ReactorSourceMap.GetSource.](images/source-mapping/attribution.svg)

Expand All @@ -74,7 +79,7 @@ on every tick".
| `ReconcileStart` / `Stop` | Root element type + diff counters | ETW `Reconcile` keyword |
| `EffectsFlushStart` / `Stop` | Component CLR type name | ETW `Render` keyword |
| `StateChange` | Hook kind + value type | ETW `State` keyword |
| `RenderError` | Component name + exception type only (message redacted) | ETW `Errors` keyword |
| `RenderError` | Component name + exception type only (message redacted); emitted on mount, update and host-root renders, including errors an `ErrorBoundary` catches (named at the throw site, once) | ETW `Errors` keyword |
Comment thread
azchohfi marked this conversation as resolved.
Outdated
| Per-element file:line | Element call site | `Element.CallSite` / `ReactorSourceMap.GetSource` (when source mapping is enabled at build time) |

The reconcile pass also emits a counter summary on stop:
Expand Down
82 changes: 82 additions & 0 deletions src/Reactor/Core/Diagnostics/ComponentNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Microsoft.UI.Reactor.Core.Diagnostics;

/// <summary>
/// The component name Reactor's diagnostics report (<c>ReactorEventSource</c>
/// <c>RenderError</c>, <c>ComponentRenderStart</c>/<c>Stop</c>,
/// <c>EffectsFlushStart</c>/<c>Stop</c>, <c>ComponentUnmount</c>, and the
/// reconciler's <c>ILogger</c> messages).
///
/// <para><b>Why not <c>element.GetType().Name</c>.</b> A class component is carried by a
/// <see cref="ComponentElement"/> — and by <c>ComponentElement&lt;TProps&gt;</c> for
/// <c>Component&lt;T, TProps&gt;(…)</c> — so naming the <em>element</em> reports
/// <c>ComponentElement</c> / <c>ComponentElement`1</c> for every class component in
/// the app. The component is <see cref="ComponentElement.ComponentType"/> (or the live
/// instance's type, which wins after a hot-reload type swap).</para>
///
/// <para><b>Shape.</b> The type's own simple name, as before, for a non-generic
/// component (<c>Counter</c>), so existing traces and greps are unchanged. A generic
/// component renders its arity in C# form (<c>Counter&lt;Int32&gt;</c>) instead of the
/// metadata name (<c>Counter`1</c>). Function and memo components have no type of their
/// own and keep reporting <c>FuncElement</c> / <c>MemoElement</c>.</para>
///
/// <para><b>PII.</b> Output is built only from developer-authored type names — never
/// props, state, keys or paths — so it is safe on the ETW payload
/// (spec 044 §6.2.1).</para>
///
/// <para>Reflection-light (<c>Type.Name</c> and <c>Type.GetGenericArguments()</c>),
/// so it is trim- and AOT-safe.</para>
/// </summary>
internal static class ComponentNames
{
/// <summary>
/// Name for a component node: the live <paramref name="instance"/>'s type when there
/// is one, else the component type an element declares, else the element's own type
/// (<c>FuncElement</c>, <c>MemoElement</c>).
/// </summary>
internal static string For(Component? instance, Element? element)
{
if (instance is not null) return For(instance.GetType());
if (element is ComponentElement componentElement) return For(componentElement.ComponentType);
return element?.GetType().Name ?? "unknown";
Comment thread
azchohfi marked this conversation as resolved.
Outdated
}

/// <summary>Display name of a component type; see the class remarks for the shape.</summary>
internal static string For(Type type)
{
if (!type.IsGenericType) return type.Name;

// Generic names are built, so cache them: the name is asked for on every traced
// render and unmount. A weak table, so it never roots a collectible or hot-reloaded type.
return s_genericNames.GetValue(type, static t =>
{
var sb = new global::System.Text.StringBuilder();
Append(sb, t);
return sb.ToString();
});
}
Comment thread
azchohfi marked this conversation as resolved.

private static readonly global::System.Runtime.CompilerServices.ConditionalWeakTable<Type, string> s_genericNames = new();

private static void Append(global::System.Text.StringBuilder sb, Type type)
{
var name = type.Name;
var tick = name.IndexOf('`');
sb.Append(tick >= 0 ? name.Substring(0, tick) : name);

if (!type.IsGenericType) return;

// For a nested generic the flat argument list also carries the declaring type's
// arguments; this name only reports the ones it introduces itself.
var args = type.GetGenericArguments();
int own = tick >= 0 && int.TryParse(name.AsSpan(tick + 1), out var arity) ? arity : 0;
if (own == 0) return;

sb.Append('<');
for (int i = args.Length - own; i < args.Length; i++)
{
if (i > args.Length - own) sb.Append(", ");
Append(sb, args[i]);
}
sb.Append('>');
}
}
27 changes: 26 additions & 1 deletion src/Reactor/Core/Reconciler.Mount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,18 @@ private UIElement MountComponent(ComponentElement compElement, Action requestRer
}
component.Context.FlushEffects();
}
// Inside an ErrorBoundary: name the failing component, then let the boundary
// handle it (see ReconcileComponent).
catch (Exception ex) when (_errorBoundaryDepth > 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
EmitRenderError(Diagnostics.ComponentNames.For(component, compElement), ex);
throw;
Comment thread
azchohfi marked this conversation as resolved.
Outdated
}
catch (Exception ex) when (_errorBoundaryDepth == 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
_logger?.LogError(ex, "Component Render() threw during mount: {ComponentName}", compElement.GetType().Name);
var failedName = Diagnostics.ComponentNames.For(component, compElement);
_logger?.LogError(ex, "Component Render() threw during mount: {ComponentName}", failedName);
EmitRenderError(failedName, ex);
childElement = ErrorFallback.BuildElement(ex);
}
UIElement? childControl = Mount(childElement, componentRerender);
Expand Down Expand Up @@ -905,9 +914,17 @@ private UIElement MountFuncComponent(FuncElement funcElement, Action requestRere
}
ctx.FlushEffects();
}
// Inside an ErrorBoundary: name the failing component, then let the boundary
// handle it (see ReconcileComponent).
catch (Exception ex) when (_errorBoundaryDepth > 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
EmitRenderError(nameof(FuncElement), ex);
Comment thread
azchohfi marked this conversation as resolved.
Outdated
throw;
}
catch (Exception ex) when (_errorBoundaryDepth == 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
_logger?.LogError(ex, "FuncComponent Render() threw during mount");
EmitRenderError(nameof(FuncElement), ex);
childElement = ErrorFallback.BuildElement(ex);
}
UIElement? childControl = Mount(childElement, componentRerender);
Expand Down Expand Up @@ -945,9 +962,17 @@ private UIElement MountMemoComponent(MemoElement memoElement, Action requestRere
}
ctx.FlushEffects();
}
// Inside an ErrorBoundary: name the failing component, then let the boundary
// handle it (see ReconcileComponent).
catch (Exception ex) when (_errorBoundaryDepth > 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
EmitRenderError(nameof(MemoElement), ex);
Comment thread
azchohfi marked this conversation as resolved.
Outdated
throw;
}
catch (Exception ex) when (_errorBoundaryDepth == 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
_logger?.LogError(ex, "MemoComponent Render() threw during mount");
EmitRenderError(nameof(MemoElement), ex);
childElement = ErrorFallback.BuildElement(ex);
}
UIElement? childControl = Mount(childElement, componentRerender);
Expand Down
59 changes: 45 additions & 14 deletions src/Reactor/Core/Reconciler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,23 @@ private void PopulateDirtyAncestorPath()
// without a matching decrement, which silently suppresses all later spans.
internal int ReconcileTraceDepthForTests => _reconcileTraceDepth;

/// <summary>
/// <c>ReactorEventSource.RenderError</c> for a component whose Render() threw and was
/// replaced by the error fallback. Shared by the mount and update paths so both name
/// the component the same way (<see cref="Diagnostics.ComponentNames"/>). The event
/// sink drops <paramref name="ex"/>'s message from the ETW payload (TASK-064 PII
/// redaction); only the component name and exception type are written.
/// </summary>
internal static void EmitRenderError(string componentName, Exception ex)
{
if (Diagnostics.ReactorEventSource.Log.IsEnabled(
global::System.Diagnostics.Tracing.EventLevel.Error,
Diagnostics.ReactorEventSource.Keywords.Errors))
{
Diagnostics.ReactorEventSource.Log.RenderError(componentName, ex.GetType().Name, ex.Message);
Comment thread
azchohfi marked this conversation as resolved.
Outdated
}
}
Comment thread
azchohfi marked this conversation as resolved.

private static void FlushEffectsTraced(RenderContext ctx, string? componentName)
{
// Fast path when the Render keyword is off: no Stopwatch, no event emit.
Expand Down Expand Up @@ -2072,7 +2089,7 @@ private void ReconcileComponent(Element oldEl, Element newEl, UIElement control,
long renderStart = 0;
if (traceRender)
{
componentName = node.Component?.GetType().Name ?? newEl.GetType().Name;
componentName = Diagnostics.ComponentNames.For(node.Component, newEl);
Diagnostics.ReactorEventSource.Log.ComponentRenderStart(
componentName, selfTriggered ? "self" : "parent");
renderStart = global::System.Diagnostics.Stopwatch.GetTimestamp();
Expand Down Expand Up @@ -2142,21 +2159,25 @@ private void ReconcileComponent(Element oldEl, Element newEl, UIElement control,
_logger?.LogWarning(ex,
"Hot reload: hook order/type changed in child component — " +
"resetting state and re-rendering: {ComponentName}",
componentName ?? newEl.GetType().Name);
componentName ?? Diagnostics.ComponentNames.For(node.Component, newEl));
hotReloadRetried = true;
renderCtx.ResetForHotReload();
continue;
}
// Inside an ErrorBoundary the exception propagates to the boundary, which
// renders its fallback. Name the failing component here, at the throw site —
// the boundary itself cannot know which descendant threw — so a listener sees
// the error even though the app recovered. Rethrown unchanged.
catch (Exception ex) when (_errorBoundaryDepth > 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
EmitRenderError(componentName ?? Diagnostics.ComponentNames.For(node.Component, newEl), ex);
throw;
Comment thread
azchohfi marked this conversation as resolved.
Outdated
}
catch (Exception ex) when (_errorBoundaryDepth == 0 && ex is not OutOfMemoryException and not StackOverflowException)
{
_logger?.LogError(ex, "Component Render() threw: {ComponentName}", newEl.GetType().Name);
if (Diagnostics.ReactorEventSource.Log.IsEnabled(
global::System.Diagnostics.Tracing.EventLevel.Error,
Diagnostics.ReactorEventSource.Keywords.Errors))
{
Diagnostics.ReactorEventSource.Log.RenderError(
componentName ?? newEl.GetType().Name, ex.GetType().Name, ex.Message);
}
var failedName = componentName ?? Diagnostics.ComponentNames.For(node.Component, newEl);
_logger?.LogError(ex, "Component Render() threw: {ComponentName}", failedName);
EmitRenderError(failedName, ex);
newChildElement = ErrorFallback.BuildElement(ex);
}
break;
Expand Down Expand Up @@ -2444,8 +2465,13 @@ private void UnmountRecursive(UIElement control)

if (_componentNodes.TryGetValue(control, out var node))
{
Diagnostics.ReactorEventSource.Log.ComponentUnmount(
node.Component?.GetType().Name ?? node.Element?.GetType().Name ?? "unknown");
if (Diagnostics.ReactorEventSource.Log.IsEnabled(
global::System.Diagnostics.Tracing.EventLevel.Informational,
Diagnostics.ReactorEventSource.Keywords.Lifecycle))
{
Diagnostics.ReactorEventSource.Log.ComponentUnmount(
Diagnostics.ComponentNames.For(node.Component, node.Element));
Comment thread
azchohfi marked this conversation as resolved.
}
node.Component?.Context.RunCleanups();
node.Context?.RunCleanups();
_componentNodes.Remove(control);
Expand Down Expand Up @@ -2841,8 +2867,13 @@ private void UnmountAndCollect(UIElement control, List<FrameworkElement> toPool)
// Run cleanup logic (component teardown, etc.)
if (_componentNodes.TryGetValue(control, out var node))
{
Diagnostics.ReactorEventSource.Log.ComponentUnmount(
node.Component?.GetType().Name ?? node.Element?.GetType().Name ?? "unknown");
if (Diagnostics.ReactorEventSource.Log.IsEnabled(
global::System.Diagnostics.Tracing.EventLevel.Informational,
Diagnostics.ReactorEventSource.Keywords.Lifecycle))
{
Diagnostics.ReactorEventSource.Log.ComponentUnmount(
Diagnostics.ComponentNames.For(node.Component, node.Element));
}
node.Component?.Context.RunCleanups();
node.Context?.RunCleanups();
_componentNodes.Remove(control);
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/Hosting/ReactorHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ void RecoverFromHookOrder(HookOrderException ex, RenderContext ctx, string mode)
{
Debugger.BreakForUserUnhandledException(ex);
_logger?.LogError(ex, "Component Render() threw");
Reconciler.EmitRenderError(
Microsoft.UI.Reactor.Core.Diagnostics.ComponentNames.For(_rootComponent, element: null), ex);
Comment thread
azchohfi marked this conversation as resolved.
Outdated
ShowErrorFallback(ex);
return;
}
Expand All @@ -595,6 +597,7 @@ void RecoverFromHookOrder(HookOrderException ex, RenderContext ctx, string mode)
catch (Exception ex)
{
_logger?.LogError(ex, "Function component threw");
Reconciler.EmitRenderError(nameof(FuncElement), ex);
ShowErrorFallback(ex);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/Hosting/ReactorHostControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ void RecoverFromHookOrder(HookOrderException ex, RenderContext ctx, string mode)
catch (Exception ex)
{
_logger?.LogError(ex, "Component Render() threw");
Reconciler.EmitRenderError(
Microsoft.UI.Reactor.Core.Diagnostics.ComponentNames.For(_rootComponent, element: null), ex);
Comment thread
azchohfi marked this conversation as resolved.
Outdated
ShowErrorFallback(ex);
return;
}
Expand All @@ -421,6 +423,7 @@ void RecoverFromHookOrder(HookOrderException ex, RenderContext ctx, string mode)
catch (Exception ex)
{
_logger?.LogError(ex, "Function component threw");
Reconciler.EmitRenderError(nameof(FuncElement), ex);
ShowErrorFallback(ex);
return;
}
Expand Down
Loading
Loading