This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: react-native-fabric-shadowtree-mutation-fence-standard

React Native 0.77 Fabric ShadowTree Concurrent Mutation Fence

Enforces strict mutation fencing in React Native 0.77's Fabric renderer to eliminate C++ ShadowTree commit clobbering. Guarantees that continuous high-frequency gesture interactions executing via Reanimated worklets do not interleave non-atomically with concurrent background Yoga layout passes or asynchronous React state transactions. Prevents dropped frames, ShadowNode revision desynchronization, and silent layout rollbacks.

Prohibited Anti-Pattern: Interleaving Imperative JS State Transitions Inside High-Frequency Gesture Loops Triggering ShadowTree Commit Clashes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: React Native 0.77 Fabric ShadowTree Concurrent Mutation Fence - Enforces strict mutation fencing in React Native 0.77's Fabric renderer to eliminate C++ ShadowTree commit clobbering. Guarantees that continuous high-frequency gesture interactions executing via Reanimated worklets do not interleave non-atomically with concurrent background Yoga layout passes or asynchronous React state transactions. Prevents dropped frames, ShadowNode revision desynchronization, and silent layout rollbacks.
globs: src/**/*.{ts,tsx}, app/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/react-native-fabric-shadowtree-mutation-fence-standard"
---

# React Native 0.77 Fabric ShadowTree Concurrent Mutation Fence

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Interleaving Imperative JS State Transitions Inside High-Frequency Gesture Loops Triggering ShadowTree Commit Clashes

## System Constraints
You are a Principal Mobile Architect enforcing React Native 0.77 Fabric ShadowTree concurrency fences. Mandate absolute isolation between high-frequency gesture pipelines executing on the UI thread and asynchronous background reconciliation passes. Ensure zero out-of-order Fabric C++ commits by requiring strict separation of imperative layout state from continuous UI thread transforms and enforcing React Concurrent transitions for batching.

## Strict Guidelines
- Engineers MUST ALWAYS isolate high-frequency gesture transforms to Reanimated SharedValues and native transform matrices without mutating React state during an active gesture stream.
- Engineers MUST NOT dispatch imperative layout calculations (`measure`, `measureInWindow`, or synchronous state setters) within gesture event handlers or worklet tick loops.
- Code SHOULD wrap non-gesture state updates that trigger ShadowTree layout passes in `startTransition` to defer background reconciliation until the gesture lifecycle completes.
- Services MUST gate layout reconfiguration commits using an explicit commit fence or state flag (`isGestureActive`) to prevent C++ ShadowNode revision conflicts.
- Components NEVER bridge continuous native gesture streams back to the JavaScript thread via non-throttled callbacks while concurrent layout passes are in flight.

## Bad vs Good Implementations
### Synchronizing High-Frequency Gestures with ShadowTree Concurrent Layout

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Updating React component state directly in `onUpdate` forces JavaScript-driven re-renders during an active gesture. In Fabric (RN 0.77), this spawns unbatched C++ ShadowTree commit attempts from JS that race against native UI thread mutations and background Yoga calculations, corrupting the revision tree or causing severe frame drops.
```typescript
import React, { useState } from 'react';
import { View, StyleSheet } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';

export const DraggablePane = () => {
  const [position, setPosition] = useState({ x: 0, y: 0 });
  const [isExpanding, setIsExpanding] = useState(false);

  // BAD: Dispatches React state updates on every frame of the pan gesture.
  // This triggers concurrent C++ Fabric commits that conflict with Yoga background
  // layout calculations, causing out-of-order ShadowTree revisions and dropped frames.
  const panGesture = Gesture.Pan()
    .onUpdate((event) => {
      setPosition({ x: event.translationX, y: event.translationY });
      if (event.translationY > 100 && !isExpanding) {
        setIsExpanding(true); // Triggers heavy layout recalculation while gesture is active
      }
    })
    .onEnd(() => {
      setPosition({ x: 0, y: 0 });
      setIsExpanding(false);
    });

  return (
    <GestureDetector gesture={panGesture}>
      <View style={[styles.box, { transform: [{ translateX: position.x }, { translateY: position.y }] }]}>
        {isExpanding && <View style={styles.expandedContent} />}
      </View>
    </GestureDetector>
  );
};
```

#### Production Standard (Correct)
> **Standard**: Transforms execute exclusively on the UI thread using Reanimated shared values without touching the ShadowTree commit pipeline. Heavy React layout adjustments are deferred using `runOnJS` and `startTransition` at gesture completion, establishing an architectural fence between gesture execution and Fabric layout mutations.
```typescript
import React, { startTransition, useState } from 'react';
import { StyleSheet } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import Animated, { useAnimatedStyle, useSharedValue, withSpring, runOnJS } from 'react-native-reanimated';

export const DraggablePane = () => {
  const translateX = useSharedValue(0);
  const translateY = useSharedValue(0);
  const [isExpanded, setIsExpanded] = useState(false);

  const commitLayoutTransition = (expanded: boolean) => {
    // GOOD: Fence layout mutations inside a concurrent transition
    // deferred until the high-frequency UI thread commit window stabilizes
    startTransition(() => {
      setIsExpanded(expanded);
    });
  };

  const panGesture = Gesture.Pan()
    .onUpdate((event) => {
      'worklet';
      // GOOD: High-frequency mutations remain on UI thread without triggering C++ ShadowTree commits
      translateX.value = event.translationX;
      translateY.value = event.translationY;
    })
    .onEnd((event) => {
      'worklet';
      const shouldExpand = event.translationY > 100;
      translateX.value = withSpring(0);
      translateY.value = withSpring(0);
      runOnJS(commitLayoutTransition)(shouldExpand);
    });

  const animatedStyle = useAnimatedStyle(() => ({
    transform: [
      { translateX: translateX.value },
      { translateY: translateY.value },
    ],
  }));

  return (
    <GestureDetector gesture={panGesture}>
      <Animated.View style={[styles.box, animatedStyle]}>
        {isExpanded && <Animated.View style={styles.expandedContent} />}
      </Animated.View>
    </GestureDetector>
  );
};
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: React Native 0.77 Fabric ShadowTree Concurrent Mutation Fence

React Native 0.77 Fabric ShadowTree Concurrent Mutation Fence defines an industrial-grade behavioral standard for mobile engineering. Enforces strict mutation fencing in React Native 0.77's Fabric renderer to eliminate C++ ShadowTree commit clobbering. Guarantees that continuous high-frequency gesture interactions executing via Reanimated worklets do not interleave non-atomically with concurrent background Yoga layout passes or asynchronous React state transactions. Prevents dropped frames, ShadowNode revision desynchronization, and silent layout rollbacks. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Interleaving Imperative JS State Transitions Inside High-Frequency Gesture Loops Triggering ShadowTree Commit Clashes Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftInterleaving Imperative JS State Transitions Inside High-Frequency Gesture Loops Triggering ShadowTree Commit ClashesCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS isolate high-frequency gesture transforms to Reanimated SharedValues and native transform matrices without mutating React state during an active gesture stream.

Engineers MUST ALWAYS isolate high-frequency gesture transforms to Reanimated SharedValues and native transform matrices without mutating React state during an active gesture stream.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT dispatch imperative layout calculations (`measure`, `measureInWindow`, or synchronous state setters) within gesture event handlers or worklet tick loops.

Engineers MUST NOT dispatch imperative layout calculations (`measure`, `measureInWindow`, or synchronous state setters) within gesture event handlers or worklet tick loops.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Code SHOULD wrap non-gesture state updates that trigger ShadowTree layout passes in `startTransition` to defer background reconciliation until the gesture lifecycle completes.

Code SHOULD wrap non-gesture state updates that trigger ShadowTree layout passes in `startTransition` to defer background reconciliation until the gesture lifecycle completes.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST gate layout reconfiguration commits using an explicit commit fence or state flag (`isGestureActive`) to prevent C++ ShadowNode revision conflicts.

Services MUST gate layout reconfiguration commits using an explicit commit fence or state flag (`isGestureActive`) to prevent C++ ShadowNode revision conflicts.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER bridge continuous native gesture streams back to the JavaScript thread via non-throttled callbacks while concurrent layout passes are in flight.

Components NEVER bridge continuous native gesture streams back to the JavaScript thread via non-throttled callbacks while concurrent layout passes are in flight.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is React Native 0.77 Fabric ShadowTree Concurrent Mutation Fence critical for AI coding assistants?

Enforces strict mutation fencing in React Native 0.77's Fabric renderer to eliminate C++ ShadowTree commit clobbering. Guarantees that continuous high-frequency gesture interactions executing via Reanimated worklets do not interleave non-atomically with concurrent background Yoga layout passes or asynchronous React state transactions. Prevents dropped frames, ShadowNode revision desynchronization, and silent layout rollbacks. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Interleaving Imperative JS State Transitions Inside High-Frequency Gesture Loops Triggering ShadowTree Commit Clashes) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

React