Skip to content

Commit 0818869

Browse files
committed
Skip reactions this version can't read instead of failing the layout
A node's reactions decode through reactionsFromJson, which leaves out any reaction whose trigger or action type is unknown (one added in a later version). Before, one such reaction made the whole layout fail to load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GfenNMqKhKopni53RqAKgd
1 parent 399bb6a commit 0818869

42 files changed

Lines changed: 200 additions & 243 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎lib/src/api/mixins.dart‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,28 @@ enum IconTypeEnum {
203203
image,
204204
}
205205

206+
/// Decodes a node's reactions, leaving out any this version can't read, such
207+
/// as a trigger or action type added later. One unknown reaction then costs
208+
/// only itself instead of failing the whole layout.
209+
List<Reaction> reactionsFromJson(Object? json) => [
210+
if (json is List)
211+
for (final Object? item in json)
212+
if (item is Map)
213+
if (_tryReaction(item) case final Reaction reaction) reaction,
214+
];
215+
216+
Reaction? _tryReaction(Map json) {
217+
try {
218+
return Reaction.fromJson(json);
219+
} on Object {
220+
return null;
221+
}
222+
}
223+
206224
/// Defines reactions to user interactions on a node.
207225
mixin ReactionMixin {
208226
/// Holds reactions defined on a node.
227+
@JsonKey(fromJson: reactionsFromJson)
209228
late List<Reaction> reactions;
210229

211230
/// Sets the reactions on a node.

‎lib/src/api/models/icon.g.dart‎

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/models/navigation_bar_item.g.dart‎

Lines changed: 21 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/accordion_node.g.dart‎

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/app_bar_node.g.dart‎

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/auto_placeholder_node.g.dart‎

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/badge_node.g.dart‎

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/button_node.g.dart‎

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/canvas_node.g.dart‎

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/src/api/nodes/checkbox_node.g.dart‎

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)