本文へ移動
cccskills
無料GitHub で公開

code-react

React-specific code shape in the Grida editor. Hooks cannot be tested or benchmarked and silently break tuned UX under layered composition, so they are barred from the engine and main system — load-bearing logic lives in classes and namespaces, hooks only as thin edge wires. `data-testid` follows component-root discipline: one per significant component, not scattered. Use when authoring React in `editor/grida-canvas-react/`, `editor/components/`, `editor/scaffolds/`, or `editor/app/*`.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md6.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

code-react

React in this repo is a thin layer over a framework-agnostic engine. These conventions protect that thinness — where logic is allowed to live, and where test landmarks land in the DOM — so the React layer stays replaceable and easy to read.

Hooks live at the edge

React hooks must not appear in the main system — the canvas engine, reducers, document model, font manager, presentation engine, command handlers, anything that represents domain state or compute logic. Hooks live only at the React edge: small use-* adapters that bridge engine state into components, plus component-local UI state.

The reason is that hooks cannot be tested, cannot be benchmarked, and cannot be reasoned about by inspection once their composition crosses more than a couple of layers. In a complex editor — where one render is a chain of conditional effects, memoized derivations, and re-entrant subscriptions — the execution order and re-render layering are the behavior. A subtle ordering change, a missed dep, a state read one tick later, and the user-visible UX shifts. Features you tuned will get silently dropped — no failing test, no benchmark regression, no noisy error to alert you. By the time someone notices, the regression is weeks deep and no bisect helps, because nothing was ever measurable.

The escape is not "test your hooks better," not "be more careful with deps," not "add a renderHook suite." It is don't use hooks for anything load-bearing in the first place. The rule is prevention, not discipline — discipline fails at the third layer of composition; prevention does not. Logic that matters lives in a class or namespace where the execution order is explicit, the contract is testable, and the hot path is benchmarkable. The hook is reduced to a wire — short enough that you can verify it by sight, and small enough that not testing it is honest.

A hook is acceptable in exactly two situations:

  1. Not testing it is honest. The hook calls useSyncExternalStore, useContext, or a useEffect lifecycle, with no branch and no derivation. The test would be tautological.
  2. The spec would be longer than the code. The hook is short enough that no test could catch a bug the code couldn't already reveal at sight.

If a hook fails both — branching logic, derivations, coordination across effects, anything you would want to benchmark or assert on — extract the logic out, test and benchmark it there, and reduce the hook to a three-line call site.

A pair of examples pins the boundary:

  • Fine. useState and hooks for component-local UI state — hover, focus, open/closed, the in-flight value of an input about to be committed. The spec is the code; not testing it is honest.
  • Never. Hooks for features layered on top of a rich-text or canvas runtime — a slash-menu, mention picker, inline toolbar plugin, anything that composes with the host editor's state machine. Even when the host (e.g. tiptap, lexical) is hook-friendly, your features run on an execution order you do not own. Build them as classes or namespaces against the host's imperative API; React renders the result.

The split is structural, not lint-enforced. The engine package must not import React. The React bindings consume the engine through its public surface — never the reverse — so the engine stays replaceable and the bindings stay verifiable by sight. A use-* that wires useSyncExternalStore, useContext, or a disposal useEffect to the engine is the entire allowed shape; anything more is engine logic in the wrong package.

One data-testid per component root

Test IDs are landmarks, not scattered selectors. A significant component — a panel, a dialog, a workflow root, a complex isolated module — gets one data-testid on its outermost element. Internal children are located via semantic queries (findByRole, text) rooted at that landmark.

Apply to: panels, dialogs, popovers, major layout regions, complex modules. Skip for: Button, Input, Icon, primitive layout wrappers (Box, Flex, Stack), and any element a test can reach with a role or text query from the landmark above it.

Values are kebab-case, factful, and unique: sidebar-right-inspect-node-properties, popover-color-picker-rgba32f, dialog-export-settings. Avoid tying values to file names, UI copy strings, or styling concerns — those churn.

Why: a data-testid is a contract between the DOM and the component that rendered it. If every span has one, the contract is meaningless and tests start coupling to implementation details. One per landmark keeps the contract small and stable.

The full reference — with the apply/skip table and worked examples — lives in docs/contributing/react.md. The rule above is the load-bearing part.

The short version

  • Hooks cannot be tested, cannot be benchmarked, and silently shift UX under layered composition. Prevention is the rule, not discipline — discipline fails at the third layer.
  • Load-bearing logic lives in a class or namespace where it can be tested and benchmarked. Hooks are a wire to React, nothing more.
  • A hook is acceptable only when not testing it is honest, or when the spec would be longer than the code. Otherwise extract.
  • data-testid goes on the component root, not its children. Tests find the landmark, then use semantic queries.
  • kebab-case data-testid values, factful and unique; never tied to file names, copy, or styling.

See also code-ts for the TypeScript code shape this builds on, and docs/contributing/react.md for the canonical UI test ID reference.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Grida AI agent system work: `@grida/daemon` (DaemonServer, loopback HTTP perimeter, files/workspaces, secrets store, daemon discovery) and `@grida/agent` (the agent tenant: sessions, providers/BYOK, runtime/tool execution, skills discovery, prompts, tiers, sandbox hosts). Use for `packages/grida-daemon/**`, `packages/grida-ai-agent/**`, desktop sidecar protocol changes, agent chat transport, and bugs in agent state or streams. For pure Electron window, preload, menu, deep-link, or CDP work, use `desktop`.

日本語の概要は準備中です。原文の説明を表示しています。

gridaco/grida2,6652026年10月9日 更新

ai-models

無料

Research, compare, and update shared AI model JSON for TypeScript, web, and Rust consumers. Covers text model tiers, image and video generation models, image tool models, release provenance, pricing data sourcing, and provider-cost metering against prepaid org credit. Use when bumping model versions, adding new models, updating pricing, or auditing model specs against provider documentation.

日本語の概要は準備中です。原文の説明を表示しています。

gridaco/grida2,6652026年10月9日 更新

code-ts

無料

TypeScript code shape inside a well-named module — taste, not lint. Prefer one class or namespace per file (the unit a test targets) over scattered free exports; consolidate related code, don't fragment. The unit of code should be the unit of spec. Use when authoring TS in `editor/grida-canvas*`, `editor/lib/`, or `packages/*`. Sibling to the `naming` skill; React-specific shape lives in `code-react`.

日本語の概要は準備中です。原文の説明を表示しています。

gridaco/grida2,6652026年10月9日 更新

database

無料

Use BEFORE editing any file in `supabase/migrations/` or `supabase/schemas/`, OR when the user runs a `/database` subcommand (`compact local migration`, `rls scenarios`, `align`). Encodes the three contracts that protect the Grida database layer: applied migrations are immutable, RLS implementation mirrors tests (never the reverse), `schemas/*.sql` is the human-readable end-state. Companion to `supabase/AGENTS.md` (RLS, grants, security boundaries).

日本語の概要は準備中です。原文の説明を表示しています。

gridaco/grida2,6652026年10月9日 更新

desktop

無料

Grida Desktop Electron shell and release-impact work: BrowserWindow, preload, `window.grida`, menus, protocol/deep links, file associations, Forge, path-scoped bridge security, Electron-only UI bugs, and CDP / Playwright verification. Use for `desktop/`, `editor/app/desktop/**`, `editor/scaffolds/desktop/**`, `editor/lib/desktop/**`, `/desktop/*` CSP, GRIDA-SEC-004, and deciding whether linked-package or hosted-renderer changes require a native Desktop version bump or coordinated release. For implementing daemon/agent-tenant core behavior, use `agent-system` as well.

日本語の概要は準備中です。原文の説明を表示しています。

gridaco/grida2,6652026年10月9日 更新

docs

無料

Decide which family a doc belongs to before drafting — SDK/developer, user/product, or working-group (WG) — since family sets the audience, home, and tone. Use when creating, moving, or restructuring docs, when unsure which directory a doc belongs in, or when a request says "document this" / "write docs for X" without naming the kind. Routes to the specialized skill for each family.

日本語の概要は準備中です。原文の説明を表示しています。

gridaco/grida2,6652026年10月9日 更新

gridaco のスキルをすべて見る

このスキルの問題を報告する