Decode diagnostics in production
Surface DecodeDiagnostics in debug overlays and logs. A malformed widget should be a telemetry event, not a blank screen.
Decode diagnostics in production SDUI are how you keep a page alive when the payload is wrong. Unknown types, malformed widgets, dropped array elements, and duplicate ids are recorded with a coding path. The rest of the page still renders. A malformed widget should be a telemetry event, not a blank page.
Flow-UI's promise in resilience is that one bad widget never blanks the page. This post is the operational half: DecodeDiagnostics as data, FlowDebugOverlay while you develop, and how a host should log the same entries in TestFlight and App Store builds without shipping the overlay.
What gets recorded#
DecodeDiagnostics is a class in FlowCore. It is @unchecked Sendable with an internal lock. Each Entry has a kind, optional widget type, coding path string, and message.
| Kind | Meaning |
|---|---|
unknownType | The widget type string has no registered content model |
malformedPayload | The type is registered but its payload failed to decode |
droppedElement | An array element could not be decoded at all and was dropped |
duplicateID | Two widgets claimed the same id; the later one was renamed |
Messages are readable on purpose: Missing key 'title' at page.sections.Index 0.widgets.Index 3.data. describeDecodingError turns a DecodingError into that line, including key-not-found, type mismatch, null-where-value, and corrupted data.
PageStore owns the diagnostics instance for the latest decode. Refresh replaces it. Views observe the store; the overlay reads store.diagnostics.entries.
Unknown types also follow UnknownWidgetPolicy: labelled placeholder in debug by default, skip in release by default. Diagnostics still record the type either way. Release users should not see an orange placeholder on a merchandising row. Your telemetry should still see unknownType.
Call that after a successful load, not only after State.failed. A loaded page can still contain five recorded problems. State.failed is for loader or whole-document failure. Widget problems are lossy by design.
The debug overlay is a debug tool#
flowDebugOverlay(store:) attaches the in-app console. Debug builds get a floating bug button labelled "Flow-UI debug console". It opens a panel with three tools:
- Diagnostics. Kind, widget type, message, coding path. Empty state: "The last decode was clean."
- Actions. What fired, who handled it, source widget id. Unhandled actions render as a warning in that list.
- Inspector. Toggle outlines every widget with its type and id so you can match pixels to JSON.
Release builds compile the modifier to the unmodified view. Do not #if DEBUG around your telemetry. The overlay is gone in release; DecodeDiagnostics is not.
Do not treat the overlay as a production support UI. It is compiled out. If a retailer needs a "what's wrong with this page" tool in a store build, that is a host feature you write against store.diagnostics, with your own auth and redaction.
How to hang it on a page#
UIKit: wrap the same FlowPageView inside FlowHostingController, then the overlay still attaches in SwiftUI land. The hosting controller does not include the overlay by default. Add it if you want the ladybug on UIKit-hosted pages during development.
Production telemetry without leaking payloads#
Log kind, type, path, message, page id, app version, and a schema version if your host sends one. Flow-UI does not invent a built-in version header. Additive JSON is the compatibility rule; unknown types skip on old binaries.
Do not log full page documents from production by default. They contain copy, images, and sometimes personalisation. Sample, or log only when entries is non-empty, or gate on a host flag.
Alert on rates, not on a single unknown type. A new widget rolling out to old binaries will produce unknownType until those binaries age out. That is expected. A spike of malformedPayload on a type you shipped last week is a CMS or backend bug: missing required key, wrong shape, null in a non-optional field.
droppedElement on button_row means one malformed button did not empty the row. That is the LossyArray contract. The row still renders; the missing button is still a bug.
duplicateID means mutations and ForEach identity are now ambiguous even though the later widget was renamed (cart_row then cart_row#2). Fix the backend ids. Do not rely on the suffix.
Loaded is not the same as clean#
PageStore.State.failed is for the loader throwing or the whole document failing to decode. Teams alert on failed and ignore loaded with a full diagnostics array. That is how a merchandising row vanishes on Friday night with no ticket.
After every transition to loaded, read store.diagnostics.isEmpty. If it is false, you had a partial success. Partial success is the SDUI default. Treat it like a 206 in HTTP: the page is up, something is missing.
UnknownWidgetPolicy defaults to .placeholder in debug and .skip in release. Changing release to .placeholder will show labelled boxes to customers. Changing debug to .skip will hide the problem you are trying to fix. Leave the defaults unless you have a host reason.
Duplicate ids are renamed so ForEach still works. Mutations that target the original id may hit the wrong row. If you use replace_widget, stable ids are not optional polish.
Overlay versus logs#
The overlay is a debugger. The log is an archive. Do not make on-call read a screenshot of the ladybug panel. Emit structured fields your query language can group: kind, widget_type, page_id, app_version. Then you can chart malformedPayload by type after a CMS change.
Action log in the overlay is debug-only on the dispatcher. Production "unhandled deeplink" belongs in your handler, which should return false so the next handler can try, and log when the chain ends unhandled. That is not DecodeDiagnostics. Do not mix the two streams.
Make it a test, not a rumour#
FlowCore has no SwiftUI import. Fixture tests can decode a payload and assert on diagnostics.entries. That is cheaper than a UI test that looks for a blank page.
Keep a "resilience" fixture that matches the docs: unknown type, missing key, typeless widget, healthy neighbours. Assert two healthy widgets, the recorded kinds, and that decode did not throw.
The playground on this docs site shows a diagnostics list under the JSON editor. The examples page has a resilience preset that is the same idea. Use it to reproduce a CMS bug before you file it. It is not the iOS Simulator and it is not the Swift demo app.
Read next#
- Resilience is the decode policy table.
- How to implement SDUI on iOS is the iOS tutorial that refuses a fatal unknown type.
- How to build server driven UI in SwiftUI is the four-seam path this telemetry sits on.
Decode diagnostics in production: DecodeDiagnostics on the store, overlay in debug, logs in release. The page stays up. The path in the entry is how you fix the JSON.
Related documentation
Related articles
- Production6 min read
Swift 6 and MainActor widgets
WidgetView is MainActor. Swift 6 language mode is the default for Flow-UI. Register widgets that are safe to render on the main actor.
- Production6 min read
Accessibility in server driven SwiftUI
Native widgets inherit VoiceOver. The schema still has to send alt text, button traits, and type that scales.
- Production6 min read
Theming server driven SwiftUI
Hex colors with dark_hex out of the box. Design tokens through ThemeProvider. Light and dark without a second payload.
More on the blog.
Read the source
Flow-UI is MIT licensed. The schema, renderer and starter widgets live on GitHub.
GitHubGet started with Flow-UI
Install the Swift package, register a widget, and render a page from JSON.
Get started