Skip to main content
skill CX Codex

reactlynx-best-practices — Claude Code skill for ReactLynx

Reviews, writes and refactors ReactLynx code for Lynx's dual-thread runtime: thread boundaries, lifecycle, event handlers, code splitting.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add lynx-community/skills --skill reactlynx-best-practices -a claude-code
Open on GitHub

What reactlynx-best-practices does

The skill kicks in when you write, audit or refactor ReactLynx components. The programming model is React's, but Lynx runs two threads, so side effects, lifecycle timing and event handlers behave differently than in plain React. It first classifies the task as writing, review or refactor, then walks a checklist.

A lightweight Node.js scanner ships with it and catches common background-only and lifecycle problems. It is a heuristic helper, not a parser, and does not replace reading the code — the actual rules live in rules/*.md and the agent is expected to apply them. No native parser such as @ast-grep/napi is required. Auto-fixes target detect-background-only diagnostics and should be reviewed before you apply them.

Vanilla Lynx Element PAPI without JSX is out of scope, as is debugging a running app through DevTool/CDP and Rspeedy or tsconfig setup — separate skills cover those. One thing worth checking: if your code reads lynx.__globalProps directly, migrating to globalPropsMode: 'event' matters, because the root forceUpdate no longer fires. useLayoutEffect is unsupported here; use useEffect for background side effects and main-thread events or refs for layout reads.

What it helps with

  • sort side effects by thread so native APIs never run from render
  • replace useLayoutEffect with something the dual-thread model supports
  • tell which bind* and catch* handlers run in the background and which need main-thread:*
  • publish a component library with preserved JSX and matching declarations
  • find hot render, diff and commit paths in a trace before optimizing

Example prompts for the agent

  • Review this ReactLynx component for thread boundaries and lifecycle issues
  • Refactor the code that uses runOnMainThread and runOnBackground per the skill rules
  • Walk through this trace with render, diff and commit events and tell me what to optimize

How to install reactlynx-best-practices

1Skills CLI (Vercel)

npx skills add lynx-community/skills --skill reactlynx-best-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/reactlynx-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/reactlynx-best-practices/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about reactlynx-best-practices

How do I install reactlynx-best-practices in Claude?

Run npx skills add lynx-community/skills --skill reactlynx-best-practices -a claude-code. The skill file then lands at ~/.claude/skills/reactlynx-best-practices/SKILL.md.

What does reactlynx-best-practices do?

It reviews, writes and refactors ReactLynx code and component libraries for Lynx's dual-thread model. It covers useLayoutEffect, main-thread:*, runOnMainThread and runOnBackground, lazy and Suspense, globalPropsMode and performance traces.

How is it different from vanilla-lynx and lynx-devtool?

It does not cover vanilla Lynx Element PAPI without ReactLynx JSX, nor debugging a running app through DevTool/CDP — those belong to vanilla-lynx and lynx-devtool. Rspeedy and tsconfig configuration is also outside its scope and handled by lynx-typescript.

Source text

SKILL.md · Apache-2.0
---
name: reactlynx-best-practices
description: Reviews, writes, and refactors ReactLynx code and component libraries for Lynx dual-thread best practices. Applies when writing ReactLynx components, or handling background-only, useLayoutEffect, bindtap/catchtap, main-thread:*, runOnMainThread/runOnBackground, lazy/Suspense, globalPropsMode/__globalProps, component-library publishing (preserved JSX vs React.createElement), or render/diff/commit performance traces. Excludes vanilla Lynx Element PAPI without ReactLynx JSX (use vanilla-lynx), running-app debugging via DevTool/CDP (use lynx-devtool), or Rspeedy/tsconfig config (use lynx-typescript).
---

# ReactLynx Best Practices

Use this skill when writing, reviewing, or refactoring ReactLynx code. ReactLynx follows the React programming model, but Lynx's dual-thread runtime changes how side effects, lifecycle timing, event handlers, and main-thread scripts should be reasoned about.

This skill intentionally does not require `@ast-grep/napi` or any native parser at runtime. The bundled scanner is a lightweight heuristic helper for common issues. The agent must still read the code and apply the rule documents in `rules/*.md`.

## When to Apply

- Writing new ReactLynx components or application code.
- Publishing or reviewing reusable ReactLynx component libraries.
- Reviewing ReactLynx code for thread-boundary, lifecycle, event, lynx.__globalProps, code-splitting, or performance issues.
- Refactoring code that calls `lynx.getJSModule`, `NativeModules`, `runOnMainThread`, `runOnBackground`, `lazy`, `Suspense`, or `useLayoutEffect`.
- Investigating performance traces that include ReactLynx render, diff, commit, patch, or setState events.

## Official References

- Thinking in ReactLynx: https://lynxjs.org/next/react/thinking-in-reactlynx.html
- Rendering Process and Lifecycle: https://lynxjs.org/next/react/lifecycle.html
- Main Thread Script: https://lynxjs.org/next/react/main-thread-script.html
- Code Splitting: https://lynxjs.org/next/react/code-splitting.html
- Performance Profiling: https://lynxjs.org/next/react/performance/profiling
- lynx.__globalProps: https://lynxjs.org/next/api/lynx-api/lynx/lynx-global-props.html
- globalPropsMode: https://lynxjs.org/next/zh/api/rspeedy/react-rsbuild-plugin.pluginreactlynxoptions.globalpropsmode.html
- Rslib React and preserved JSX: https://rslib.rs/guide/solution/react
- TypeScript JSX emit modes: https://www.typescriptlang.org/docs/handbook/jsx
- ReactLynx 0.121.0 `React.createElement` support: https://github.com/lynx-family/lynx-stack/blob/main/packages/react/CHANGELOG.md#01210

## Workflow

### 1. Classify the task

Use one of these modes:

| Mode | Use when |
|------|----------|
| `writing` | The user asks for new ReactLynx code or best-practice guidance |
| `review` | The user asks to check, audit, explain, or validate existing code |
| `refactor` | The user asks to fix or rewrite existing code |

If the mode is not explicit, infer it from the user's wording. Prefer `review` before `refactor` when code has not been inspected yet.

### 2. Inspect the code

For repository work, search before editing:

```bash
rg "lynx.getJSModule|NativeModules|useLayoutEffect|main-thread:|runOnMainThread|runOnBackground|lazy\\(|Suspense|background only|globalPropsMode|__globalProps|jsx|exports" <target>
```

Read nearby components, custom hooks, custom components that forward event handlers, Rspeedy config, and performance-related code before making changes.

### 3. Run the helper scanner when source is available

The scanner catches common background-only and lifecycle issues. It is not a complete parser and must not replace code review.

```bash
node -e "
import fs from 'fs';
import { ReactLynxWorkflow, formatScanReport } from '<path_to_skill>/scripts/index.mjs';

const input = '<sourceCodeOrFilePath>';
const sourceCode = fs.existsSync(input) ? fs.readFileSync(input, 'utf-8') : input;
const workflow = new ReactLynxWorkflow('review');
const summary = workflow.reviewCode(sourceCode);
console.log(formatScanReport(summary));
"
```

### 4. Apply the rule checklist

Always combine scanner output with these manual checks:

- Dual-thread boundaries: render code may run on the main thread; side effects and native APIs must be background-only.
- Background-only propagation: code called only from background-only code is background-only, but custom prop and custom hook boundaries often need an explicit `'background only'` directive.
- Lifecycle: `useLayoutEffect` is unsupported; use `useEffect` for background side effects or main-thread layout events/refs for layout reads.
- Events: normal `bind*`/`catch*` handlers run on the background thread; `main-thread:*` handlers require `'main thread'` and have stricter limitations.
- MTS: captured values must be JSON-serializable, captured variables cannot be modified, nested main-thread functions are unsupported, and cross-thread calls must use `runOnMainThread()` or `runOnBackground()`.
- Shared modules: import helpers with `with { runtime: 'shared' }` only for code sharing, not state sharing.
- Component libraries: publish type-erased `dist` ESM with authored JSX preserved in JSX-bearing `.jsx` files and matching declarations; export the actual `.js` or `.jsx` entry that the build emits. Expose TS/TSX source only through an explicit source field or supported condition. Check Rslib, TypeScript, Babel, and SWC output for classic, automatic, or custom-factory JSX lowering. Treat intentional `React.createElement` according to the `@lynx-js/react` peer range instead of assuming every call is incompatible.
- `lynx.__globalProps`: Host-injected cross-page/global data updated through `updateGlobalProps`.
- `globalPropsMode`: `'reactive'` triggers root `forceUpdate`; `'event'` requires explicit updates with `useGlobalPropsChanged`. When migrating to `'event'`, scan direct `lynx.__globalProps` reads because root `forceUpdate` no longer applies.
- Code splitting: lazy components need default exports, `Suspense`, CSS scope awareness, and error handling for important boundaries.
- Profiling: use trace events and readable `displayName` values to identify hot render/diff/update paths before optimizing.

### 5. Refactor safely

For refactor mode:

1. Report current findings first.
2. Explain which fixes are mechanical and which require human design judgment.
3. Apply only scoped changes.
4. Re-run the helper scanner or package tests after edits.

Use auto-fixes only as suggestions. The current auto-fixes are designed for `detect-background-only` diagnostics and should be reviewed before applying.

```bash
node -e "
import fs from 'fs';
import { ReactLynxWorkflow, formatFixPlan } from '<path_to_skill>/scripts/index.mjs';

const input = '<sourceCodeOrFilePath>';
const sourceCode = fs.existsSync(input) ? fs.readFileSync(input, 'utf-8') : input;
const workflow = new ReactLynxWorkflow('refactor');
workflow.reviewCode(sourceCode);
const plan = workflow.generateFixPlan();

if (plan) {
  console.log(formatFixPlan(plan));
}
"
```

## Rules

| Rule | Impact | Use for |
|------|--------|---------|
| [detect-background-only](./rules/detect-background-only.md) | CRITICAL | `lynx.getJSModule`, `NativeModules`, `'background only'`, custom event/hook boundaries |
| [avoid-use-layout-effect](./rules/avoid-use-layout-effect.md) | MEDIUM | Lifecycle and layout reads |
| [proper-event-handlers](./rules/proper-event-handlers.md) | MEDIUM | `bindtap`, `catchtap`, propagation, dataset, custom prop handlers |
| [main-thread-scripts-guide](./rules/main-thread-scripts-guide.md) | MEDIUM | `main-thread:*`, `useMainThreadRef`, cross-thread calls, shared modules |
| [component-library-packaging](./rules/component-library-packaging.md) | HIGH | ReactLynx component-library exports, type-erased ESM, preserved JSX, Rslib, `tsc` |
| [global-props-mode](./rules/global-props-mode.md) | MEDIUM | `globalPropsMode` config, direct `lynx.__globalProps` reads, `useGlobalPropsChanged` migration |
| [code-splitting](./rules/code-splitting.md) | MEDIUM | `lazy`, `Suspense`, standalone lazy bundles, CSS bundle scope |
| [performance-profiling](./rules/performance-profiling.md) | MEDIUM | ReactLynx trace events, flow IDs, displayName |
| [hoist-static-jsx](./rules/hoist-static-jsx.md) | LOW | Static JSX and render cost |

## API Reference

```typescript
function runSkill(source: string): Diagnostic[];
function runSkillWithFixes(source: string): DiagnosticWithFix[];
function analyzeBackgroundOnlyUsage(source: string): Diagnostic[];
function analyzeLifecycleUsage(source: string): Diagnostic[];
function generateFixes(source: string, diagnostic: Diagnostic): Fix[];
function applyFix(source: string, fix: Fix): string;
function applyFixes(source: string, fixes: Fix[]): string;
function formatScanReport(summary: ScanSummary): string;
function formatFixPlan(plan: FixPlan): string;
```

```typescript
class ReactLynxWorkflow {
  constructor(mode: WorkflowMode);
  reviewCode(source: string): ScanSummary;
  generateFixPlan(): FixPlan | null;
  applyAutoFixes(source: string): { fixed: string; appliedFixes: Fix[] };
}
```

© lynx-community · Apache-2.0 · lynx-community/skills

Similar skills

Everything for Frontend and UI →

From the same set4

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor