Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 71 ยท Getting Started

How React Native Runs Your Code

See how React Native runs your JavaScript: Hermes, the JS and UI threads, JSI, Fabric's render, commit and mount phases, TurboModules and bridgeless mode.

You can build many apps without knowing how React Native works inside. But when a list stutters, a gesture feels late or a native module misbehaves, a mental model of the machinery turns guessing into diagnosis. This lesson explains the moving parts of the current architecture: the JavaScript engine, the threads, the renderer called Fabric, and the way JavaScript and native code talk to each other.

Real and stand-in. All of this happens inside the native app, so it cannot run on this site. The explanations describe the real system in simplified form. The TryIts are stand-ins: plain JavaScript that models the phases and the thread hand-offs and prints a log, so you can follow the order of events.

Two worlds: JavaScript and native

A running React Native app contains two worlds side by side:

  • The JavaScript world. Your components, hooks and business logic run here, inside a JavaScript engine. React Native uses Hermes, an engine built for mobile that starts quickly and uses little memory. In release builds, your code is compiled ahead of time into Hermes bytecode, so the phone does not parse source text at launch.
  • The native world. The actual views, touch handling, animations and platform APIs run here, in Swift/Objective-C on iOS and Kotlin/Java on Android, with a shared C++ core in the middle.

The app uses several threads. Three matter most:

Thread Job
JavaScript thread Runs your code and React's render step
UI (main) thread Creates and updates real native views, handles touches
Background thread Computes layout (Yoga, the Flexbox engine) off the other two

If your JavaScript thread is busy (a heavy loop, a huge setState cascade), your logic and React updates stall, but a native scroll can still run smoothly. If the UI thread is busy, the screen itself freezes. Keeping both threads light is the core of mobile performance, and you will work with that in Debugging and Performance Profiling.

Three threads that matter

JS thread Your code and React render.
Background thread Layout with Yoga.
UI thread Real views and touches.

Work on one thread should not block the others.

1 / 2

JSI: how JavaScript talks to native

In the old architecture, JavaScript and native code exchanged asynchronous JSON messages over a bridge. Every call was serialized, queued and parsed again, and you could not call native code and get an answer immediately.

The JavaScript Interface (JSI) replaced that. It is a small C++ layer that lets JavaScript hold direct references to C++ objects, called host objects, and call their functions. There is no JSON step and calls can be synchronous. Everything else in the New Architecture is built on it. Nothing in your app code mentions JSI directly; it is the plumbing used by Fabric and TurboModules.

TurboModules

A native module is native code your JavaScript can call, such as the camera, storage or Bluetooth. TurboModules are the modern version:

  • They load lazily, when first used, instead of all at startup, which makes launch faster.
  • They are described by a typed spec (TypeScript or Flow). A tool called Codegen generates the native glue, so mismatched types fail at build time, not at 2 a.m. in production.
  • They can use JSI to be called synchronously when that makes sense.

When you install a library such as expo-camera, you are using modules like these. Writing your own is covered in Native Modules, Expo Modules and Config Plugins.

Fabric: the renderer in three phases

Fabric is how a React update becomes pixels. When state changes, three phases run:

  1. Render (JavaScript thread). React runs your components and produces a tree of React elements. Fabric turns it into a tree of lightweight objects in C++ called the shadow tree. Shadow trees are immutable: each update builds a new tree and shares unchanged parts.
  2. Commit (background thread, usually). The new shadow tree gets its layout computed by Yoga (sizes and positions of every node), then it is promoted to be the current tree. A diff against the previous tree lists what changed.
  3. Mount (UI thread). The diff is applied to the real native views: create, update, move or delete.
sequenceDiagram
  participant JS as JS thread
  participant BG as Background thread
  participant UI as UI thread
  JS->>JS: Render (components to shadow tree)
  JS->>BG: Commit (layout with Yoga, diff)
  BG->>UI: Mount (update native views)
  UI-->>JS: Events (touches, layout)

One state update flows through render, commit and mount.

Because the layout and tree are shared C++ data and calls go through JSI, Fabric can also do synchronous layout reads (a measure that returns right away) and process high-priority events, like a touch, ahead of lower-priority work. That is what makes gestures and text input feel more native than under the old bridge.

Simulated render pipeline with logged phases

Press the button: only the text that changed is updated in the mount phase, while the footer is untouched. That is why React Native does not redraw everything on every state change.

The old bridge in detail: execution and threads

Older articles describe React Native in terms of the bridge, so it helps to know how it worked. An app had three main threads:

Thread Job
JavaScript thread runs your code: components, state, fetch callbacks, timers
Main (UI) thread draws native views and receives touch events
Shadow thread computes layout (Yoga) for the next frame

When your component rendered, the JavaScript thread serialized a description of the changes to JSON and sent it asynchronously over the bridge. The native side deserialized it, the shadow thread laid it out, and the main thread created or updated the real views. Events travelled back the same way. The consequences are what people mean by "the bridge is a bottleneck":

  • A busy JavaScript thread (a big loop, a heavy render) delays touches, because the handler runs in JavaScript.
  • Everything crossing the bridge was copied as JSON, so sending large data (an image as base64) was slow.
  • Calls were always asynchronous: you could not read a native value and use it on the same line.
  • Native modules were loaded at startup whether or not you used them.

This also answers "does a long loop freeze the app?". It freezes the JavaScript thread, so taps and state updates stop responding, while a native scroll or a native animation (running on the UI thread with the native driver) keeps moving. That is why animation tools offer useNativeDriver, and why heavy work belongs in a background worker or native module rather than in a render. JavaScript itself is single-threaded: setTimeout and promises give concurrency, not parallelism.

With the New Architecture the same threads exist, but JSI lets JavaScript call native code directly (no JSON, and synchronous when needed), and TurboModules load lazily, as the sections above explain.

Bridgeless mode

With the New Architecture there is no longer any need for the legacy bridge at all. Bridgeless mode means the app starts without it: JSI connects everything, and TurboModules and Fabric replace the old modules and renderer. In current React Native versions this is the default for new apps, and the old architecture has been removed or is on its way out. Your app code seldom changes, but older native libraries must be updated to support it, which is why checking library compatibility matters when you upgrade.

Why this matters: a thread hand-off demo

A practical consequence: a slow JavaScript thread does not freeze the native UI, but it does delay anything that needs JavaScript, such as handling a tap in onPress or running your reducer. The next stand-in measures that effect with a simulated busy loop.

A blocked JS thread delays JS work

The tap arrives at 10 ms but the handler cannot start until the heavy loop finishes at 120 ms. Solutions include doing less work, chunking it, moving it to a native module, or running animations on the UI thread (see Reanimated and Gesture Handler).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which engine runs your JavaScript in a modern React Native app?

    Hermes is the default engine, built for mobile. In release builds it runs precompiled bytecode for faster startup.
  2. 2. In which order do Fabric's phases run for one update?

    Render builds the shadow tree on the JS thread, commit computes layout and the diff, and mount applies the changes to real native views on the UI thread.
  3. 3. What did JSI change compared with the old bridge?

    JSI is a C++ interface that gives JavaScript direct references to native host objects, allowing synchronous calls and no JSON overhead.
  4. 4. A heavy loop is blocking the JavaScript thread. What is the most likely visible effect?

    Native scrolling may continue because the UI thread is free, but anything that needs the JavaScript thread (press handlers, re-renders) waits.

Summary

  • Your code runs in Hermes on the JavaScript thread; real views live on the UI thread; layout is computed on a background thread.
  • JSI lets JavaScript call native C++ objects directly, with no JSON bridge.
  • TurboModules are lazy, typed native modules generated through Codegen.
  • Fabric updates the screen in three phases: render (shadow tree), commit (layout and diff) and mount (native views).
  • Bridgeless mode is the default; keep the JS and UI threads light to keep the app responsive.

Chapter one is complete. Continue with styling in Styling with StyleSheet.