Skip to content

WIP #1444

Open
dmandar wants to merge 24 commits into
mainfrom
md-autocatalogs
Open

WIP #1444
dmandar wants to merge 24 commits into
mainfrom
md-autocatalogs

Conversation

@dmandar
Copy link
Copy Markdown
Collaborator

@dmandar dmandar commented May 15, 2026

Description

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

List which issues are fixed by this PR. For larger changes, raising an issue first helps reduce redundant work.

Pre-launch Checklist

If you need help, consider asking for advice on the discussion board.

dmandar added 24 commits May 7, 2026 12:36
Copy link
Copy Markdown
Contributor

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

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 compile-time catalog composition system for the A2UI framework, including a demo application and a catalog compiler script. The changes include the addition of new components like McpApp and WeatherWidget, a security-focused domain whitelist for catalog ingestion, and a static registry generation process. Feedback focuses on addressing a memory leak caused by recursive rendering in the demo app, improving type safety by removing unnecessary any casts and non-null assertions, and making the catalog detection logic in the compiler script more robust.

if (feedbackText) {
activeFeedbackText = feedbackText;
// Re-render cleanly to update state reactively
renderActiveComponent(name, catalog);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Calling renderActiveComponent recursively inside the onAction subscription is problematic. Each call creates a new SurfaceModel and a new subscription without disposing of the previous ones. This results in a memory leak as the old SurfaceModel instances and their observers remain in memory. Additionally, it causes a full teardown and rebuild of the component playground on every action, which is inefficient and resets any local UI state (like focus or scroll position). Consider using a persistent model and updating the UI reactively.

// --- Reactive UI Ingesting ---

function renderCatalogSelector() {
const container = document.getElementById('catalog-selector-buttons')!;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using the non-null assertion operator (!) when retrieving DOM elements. If the element catalog-selector-buttons is missing from the document for any reason, this will cause a runtime TypeError. It is safer to check for the element's existence before proceeding.

Suggested change
const container = document.getElementById('catalog-selector-buttons')!;
const container = document.getElementById('catalog-selector-buttons');
if (!container) return;

function renderActiveComponent(name: string, catalog: Catalog<any>) {
const container = document.getElementById('dynamic-surface-container')!;

const surfaceModel = new SurfaceModel('showcase-surface', catalog as any);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using as any to cast the catalog. This bypasses TypeScript's type checking and can hide potential bugs or type mismatches. If the SurfaceModel constructor expects a Catalog<any>, the cast is redundant. If it expects a more specific type, you should ensure the catalog matches that type or define a proper interface.


// Connect via postMessage JSON-RPC
const msgId = 1;
iframe.contentWindow!.postMessage({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The contentWindow property of an iframe can be null if the iframe is not yet attached to the DOM or has been removed. Using a non-null assertion (!) here is unsafe and could lead to a crash. It is better to use optional chaining or an explicit check.

Suggested change
iframe.contentWindow!.postMessage({
iframe.contentWindow?.postMessage({

}

// Dynamically generate the exports registry based on the loaded catalogs!
const weatherCatalogRegistered = targetCatalogs.some(url => url.includes('weather-catalog.json'));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic for detecting and registering catalogs based on hardcoded filename substrings (e.g., weather-catalog.json) is brittle. This approach prevents the --add CLI feature from working correctly with catalogs that have different filenames, even if they contain the same component types. Consider a more robust identification mechanism, such as inspecting the contents of the catalog or using a dedicated metadata field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant