Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-catalogs-load.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/kumo": patch
---

Load catalog schemas when `initCatalog` is awaited so synchronous validation is ready to use.
1 change: 0 additions & 1 deletion packages/kumo/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ Output: ai/component-registry.{json,md} + ai/schemas.ts
- **Compound components**: CommandPalette (14 sub-components), Dialog, Select use two-level contexts
- **13 components use createContext**: SwitchGroup, PaginationContext, RadioGroup, FlowNodeAnchor, Diagram, Descendants, InputGroup, DialogRole, ComboboxSize, Grid, CheckboxGroup, CommandPalette (2)
- **DateRangePicker**: Contains 150 lines of duplicated ternary logic (refactoring target)
- **Catalog `initCatalog`**: Appears to have race condition with async schema loading
- **CLI path inconsistency**: `ls`/`doc` read from `catalog/`, `blocks` from `ai/` directory
- **`PLOP_INJECT_EXPORT`** in `src/index.ts` and `PLOP_INJECT_COMPONENT_ENTRY` in `vite.config.ts` are scaffolding markers
- **5th lint rule** (`no-deprecated-props`): Only in `packages/kumo/lint/`, reads deprecation data from registry
Expand Down
25 changes: 25 additions & 0 deletions packages/kumo/src/catalog/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { describe, it, expect } from "vitest";
import { createKumoCatalog, initCatalog } from "./catalog";
import {
getByPath,
setByPath,
Expand All @@ -12,6 +13,30 @@ import {
} from "./data";
import { evaluateVisibility, createVisibilityContext } from "./visibility";

describe("catalog initialization", () => {
it("loads schemas before synchronous validation", async () => {
const catalog = createKumoCatalog();

await initCatalog(catalog);

expect(catalog.componentNames).toContain("Button");
expect(catalog.hasComponent("Button")).toBe(true);
expect(catalog.validateTree({})).toEqual({
success: false,
error: [
{
message: "Invalid input: expected string, received undefined",
path: ["root"],
},
{
message: "Invalid input: expected record, received undefined",
path: ["elements"],
},
],
});
});
});

describe("data utilities", () => {
describe("getByPath", () => {
it("returns root for empty path", () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/kumo/src/catalog/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ export function createKumoCatalog(config: CatalogConfig = {}): KumoCatalog {
* Initialize the catalog by loading schemas.
* Call this before using synchronous validation methods.
*/
export async function initCatalog(catalog: KumoCatalog): Promise<void> {
// Trigger a validation to load schemas
catalog.validateTree({});
export async function initCatalog(_catalog: KumoCatalog): Promise<void> {
await loadSchemas();
}