agentleFS
golid-aigolid-ai/golid/.cursor/rules/frontend-components-advanced.mdc

golid / rules

Cursor rule40 starsChanged 6 months agoMITView on GitHub

Advanced component patterns — lazy loading, production demo-state traps, raw-input exceptions

The file

We split this frontend-components-advanced.mdc into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never call onCleanup() after an await — use mutable refs cleaned up in the synchronous onCleanup registered during component creation.

    line 49
  2. Distinctive:

    Import from other atoms inside an atom (that makes it a molecule)

    line 52
  3. Very specific:

    Use createSignal for internal state unless the component is interactive (forms, toggles)

    line 53
  4. Distinctive:

    Use inline styles — use Tailwind classes

    line 54
  5. Very specific:

    Create a raw HTML element when a component exists (<select> → use <Select>, confirm() → use <DestructiveModal>)

    line 55
  6. Very specific:

    Use lazy() without a <Suspense> boundary — it silently renders nothing

    line 56
  7. Distinctive:

    If a second legitimate case appears, add it here in the same commit that introduces it.

    line 69

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
frontend-components-advanced.mdc
---
description: Advanced component patterns — lazy loading, production demo-state traps, raw-input exceptions
globs: frontend/src/components/**/*.tsx,frontend/src/components/index.ts
alwaysApply: false
---

# Advanced Component Patterns

> **Thesis:** Browser-only components need Suspense and static DOM wrappers; production components must never ship demo behavior; two raw-`<input>` cases are intentional.

## Lazy Loading (Browser-Only Components)

Components that use browser APIs (Three.js, WebRTC, canvas) must be lazy-loaded with `<Suspense>`:

```tsx
// In the CONSUMER file (e.g., a section or page):
import { lazy, Suspense } from "solid-js";
const Canvas3D = lazy(() => import("~/components/molecules/Canvas3D/Canvas3D")
  .then(m => ({ default: m.Canvas3D })));

// Usage — Suspense is REQUIRED or the component silently renders nothing:
<Suspense>
  <Canvas3D />
</Suspense>
```

Inside the lazy component, if `onMount` appends DOM nodes (e.g., `containerRef.appendChild(canvas)`), the return JSX **must include a static wrapper div** — not just a `Switch/Match`. Without a static element, `onMount` may not fire:

```tsx
// GOOD — static div always in DOM, conditional content inside
<div ref={containerRef} class="relative w-full h-full">
  <div class="absolute inset-0 pointer-events-none"
    style={{ display: loading() || error() ? undefined : "none" }}>
    <Switch>
      <Match when={loading()}><Spinner /></Match>
      <Match when={error()}><ErrorText /></Match>
    </Switch>
  </div>
</div>

// BAD — Switch as only child can prevent onMount from firing
<div ref={containerRef}>
  <Switch>
    <Match when={loading()}>...</Match>
  </Switch>
</div>
```

Never call `onCleanup()` after an `await` — use mutable refs cleaned up in the synchronous `onCleanup` registered during component creation.

## Do NOT
- Import from other atoms inside an atom (that makes it a molecule)
- Use `createSignal` for internal state unless the component is interactive (forms, toggles)
- Use inline styles — use Tailwind classes
- Create a raw HTML element when a component exists (`<select>` → use `<Select>`, `confirm()` → use `<DestructiveModal>`)
- Use `lazy()` without a `<Suspense>` boundary — it silently renders nothing
- Build "demo state" (random failures, fake delays, mocked data, `simulateX` helpers) directly into a component that is also used in production. If a component needs a showcase variant, gate the demo behavior on the absence of an integration prop (`Show when={hasFiles() && !props.onFilesSelected}`) so the demo UI only renders when no callback is wired. The Dropzone bug (`9a68b1e`) shipped fake "Upload failed" badges on top of real uploads to real users for weeks because `simulateUpload()` rendered alongside the real upload state. Mock data on dedicated showcase routes (e.g. `(private)/components/sections/`, the `/components` showcase) is fine — those routes are the showcase, not consumers of one.

## Legitimate raw-`<input>` exceptions

Two raw `<input>` cases are intentional and should not be wrapped with the
shared `<Input>` component:

1. **Hidden file inputs triggered by ref.** The `<Input>` component does not
   support file uploads. Use a hidden `<input ref={fileRef} type="file"
   class="hidden" />` clicked from a styled `<Button>`. See
   `components/molecules/Dropzone/Dropzone.tsx`.

If a second legitimate case appears, add it here in the same commit that
introduces it.

## Related Rules

- Atom/molecule/organism taxonomy, template, barrel exports — see `frontend-components`.
- Route-level component usage — see `solidjs-pages`.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.