[BUG]: a schema-valid component can crash the surface it renders on
- I have searched the existing issues to make sure this bug has not already been reported.
Describe the Bug
A component that is valid against its own schema can take the whole surface down.
The clearest case is Slider. Its schema says value is a DynamicNumber and min and max are plain numbers, and nothing relates them:
"value": {"$ref": ".../DynamicNumber"},
"min": {"type": "number", "description": "The minimum value. Defaults to 0.0."},
"max": {"type": "number", "description": "The maximum value. Defaults to 1.0."}So {"component": "Slider", "value": 42, "min": 0, "max": 10} is a message an agent can compose by reading the schema and following it. It throws:
'package:flutter/src/material/slider.dart': Failed assertion: line 202 pos 10:
'value >= min && value <= max': Value 42.0 is not between minimum 0.0 and maximum 10.0{"value": 0, "min": 0, "max": -1} is also schema-valid and hits the min <= max assertion on line 200. Nothing in the schema says a model may not pick those numbers.
The wider version is the hard casts. I rendered every catalog item's own generated example with each property replaced by something else the property could plausibly hold, and 69 of those cases threw across five components:
| component | cases that threw | what does it |
|---|---|---|
| Slider | 28 | _json['max'] as num?, plus the two Material assertions above |
| Tabs | 17 | as List<dynamic> on tabs |
| TextField | 11 | as String? on variant |
| DateTimeInput | 10 | as String? on value |
| Row | 3 | 200 children, RenderFlex overflow |
Most of those inputs are schema-invalid, so the fair question is why validation does not stop them. It runs, but after the fact. In surface_controller.dart:225 the comment says it outright:
// Validation does not roll back the mutation; we surface the error
// and let the caller decide._registry.notifyUpdated(surface) happens first, _validateComponents is awaited separately and its result goes to catchError. By the time the error is reported the widget has already been built with the bad value and thrown.
So the two halves lean on each other: validation cannot protect the render because it happens afterwards, and the widgets cannot survive what validation was meant to catch because they cast instead of coerce.
Steps to Reproduce
controller.handleMessage(UpdateComponentsMessage(surfaceId: 's', components: [
{'id': 'root', 'component': 'Slider', 'value': 42, 'min': 0, 'max': 10},
]));
controller.handleMessage(CreateSurfaceMessage(surfaceId: 's', catalogId: basicCatalogId));
// pump -> assertionExpected Behavior
A component the model composed wrongly degrades: it renders something, reports the problem back through reportError, and leaves the rest of the surface alone. One bad property should not be able to blank a screen.
For the Slider specifically, clamping value into the range and swapping min/max when they arrive inverted would cover it without any schema change.
Additional Context
I found these by mutating each item's own generated example rather than by reading the schemas, which is why the list is per property rather than per widget. Happy to send the Slider fix, it is small, and to write up the cast ones separately if you would rather take them one at a time.
Source: a2ui-project/a2ui