Skip to content

fix(craft): renderer media option, intrinsic sizes, live registrations - #39

Open
innkuika wants to merge 2 commits into
craft/fix-parserfrom
craft/fix-renderer
Open

innkuika wants to merge 2 commits into
craft/fix-parserfrom
craft/fix-renderer

Conversation

@innkuika

Copy link
Copy Markdown
Contributor

Description

Fixes to the Flutter adapter and renderer, found by dogfooding. Stacked on #38.

  • Intrinsic sizes: template components work inside IntrinsicWidth / IntrinsicHeight and dry layout (for example in chat bubbles and dialogs) with every media source. templateCatalog gets a media: option.
  • Live updates: the registry notifies listeners after each accepted change, and running template components re-render with fresh state after a library is registered again, so the next tap isn't lost. A throwing listener goes to onListenerError.
  • No name clash with Material: the main library no longer exports the parsed-library node types (Switch, Loop, …); they're in package:a2ui_craft/model.dart.
  • errorBuilder: the error placeholder can be replaced.

Each fix comes with a test that fails without it. An independent review checked the blueprints, tests and code.

Pre-launch Checklist

One time:

For this PR:

  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • License checks pass (python3 ./scripts/fix_licenses.py --check).
  • Format checks pass (./scripts/fix_format.sh --check).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a change notification mechanism to the TemplateRegistry (feature F-CRAFT-REG-10), allowing hosts to listen to registry updates and automatically refresh the CraftRuntime and CraftView when libraries are re-registered. It also implements a custom SpaceBuilder widget in the Flutter adapter to replace LayoutBuilder for the MediaSource.layout mode, enabling template components to correctly answer intrinsic size queries (e.g., inside IntrinsicWidth or IntrinsicHeight). Additionally, the public API of a2ui_craft has been restructured to export library model nodes via a separate model.dart file to prevent naming clashes with Flutter's Switch widget. Comprehensive unit, widget, and conformance tests have been added to validate these new features. I have no review comments or feedback to provide on the changes.

@innkuika
innkuika added this pull request to stack #51 December 1, 2026 19:57
@innkuika
innkuika marked this pull request as ready for review December 2, 2026 20:24
@innkuika
innkuika requested a review from ditman December 2, 2026 20:24
Fixes dogfood bugs B01, B02 and B09, and adds an error placeholder option.

- B01: templateCatalog takes `media:` (a MediaSource) and passes it to
  CraftView. The default `layout` source no longer uses a LayoutBuilder:
  SpaceBuilder builds like one but also in the build phase (for the space
  of its last layout, at first the window's), so template components
  answer intrinsic size queries inside IntrinsicWidth, IntrinsicHeight,
  dialogs and tables. Errors of an expansion replaced in the same frame are
  not reported; a new view keeps a runtime's media context.
- B02: the registry notifies listeners after each accepted change
  (craft_template_registry requirement 10, with conformance cases); a
  listener removed during a notification is not called, and one that
  throws goes to the registry's onListenerError (by default the zone)
  without failing the registration or stopping the other listeners;
  CraftView refreshes its runtime when its registry changes, and
  CraftRuntime.refresh drops the state of a library registered again at
  once (craft_runtime requirement 10), so components on screen render the
  new version in the next frame and the next tap is not swallowed
  (craft_a2ui_integration requirement 7).
- B09: package:a2ui_craft/a2ui_craft.dart exports only the library model
  types hosts need; the nodes of a parsed library (Switch, Loop, ...) move
  to package:a2ui_craft/model.dart, so the main library imports next to
  package:material_ui/material_ui.dart. The main library still exports every
  model type its API names (Import, WidgetDeclaration, BlobNode,
  SymbolReference, ...); checkCallArguments is no longer exported. Tests
  that build libraries import model.dart.
- templateCatalog takes `errorBuilder:` for the placeholder of a failed
  widget, as CraftView does.
The A2UI integration fix in this stack added a test that builds a library
with ConstructorCall and ArgsReference, which this change moves from the
main library to package:a2ui_craft/model.dart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant