Skip to content

Latest commit

 

History

History
162 lines (116 loc) · 6.6 KB

README.md

File metadata and controls

162 lines (116 loc) · 6.6 KB

Root Native Web logo

Root Native Web

npm version of @rootnative/web MIT license

@rootnative/web is a standalone web runtime for React Native apps. You write react-native. It runs in the browser as a real web app.

Status lists what ships today, and the changelog lists the changes in each release.

Docs: https://rootnative.github.io/web/

Why

react-native-web tracks React Native and stops there. This project starts from the browser and asks a different question: what does a React Native app need to be a good web app?

  • Parity first. Every react-native export that ships behaves as it does on iOS and Android.
  • Web second, behind the same API. Semantic HTML, SEO, server rendering, DOM events, logical CSS properties, and the browser features that native doesn't have.
  • Modern only. TypeScript, ESM, React 19. No Flow, no CommonJS, no findDOMNode, no forwardRef.

Install

Expo (Metro)

Install @rootnative/web-expo, and remove react-native-web:

npm install @rootnative/web-expo
npm uninstall react-native-web

Wrap your Metro config with withRootNative:

// metro.config.js
const { getDefaultConfig } = require('expo/metro-config')
const { withRootNative } = require('@rootnative/web-expo/metro.cjs')

module.exports = withRootNative(getDefaultConfig(__dirname))

Your app code doesn't change. Expo shows a setup with no Metro config, and what works.

React Native CLI (Metro)

For a React Native app with no Expo, on React Native 0.88:

npm install @rootnative/web-metro react-dom

Wrap your Metro config with withRootNative, and add an index.web.js that calls AppRegistry.runApplication. Then run npx react-native start, and open http://localhost:8081/index.html. npx rootnative-web build writes the production build. React Native CLI shows each step.

Vite

npm install @rootnative/web

React 19 and React DOM 19 are peer dependencies. Add the Vite plugin to vite.config.ts. It resolves react-native to the package:

import { rootnative } from '@rootnative/web/vite'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [react(), rootnative()],
})

Give TypeScript the same mapping in src/react-native.d.ts:

declare module 'react-native' {
  export * from '@rootnative/web'
}

Installation shows how to mount the app, so that flex: 1 fills the window.

Example

import { StyleSheet, Text, View } from 'react-native'

export function App() {
  return (
    <View role="main" style={styles.screen}>
      <Text role="heading" aria-level={1} style={styles.title}>
        Hello from React Native
      </Text>
      <Text href="/about">About</Text>
    </View>
  )
}

const styles = StyleSheet.create({
  screen: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 8 },
  title: { fontSize: 24 },
})

In the browser, this is a <main> with an <h1> and an <a href="/about">, styled with atomic CSS classes. The same code runs on iOS and Android.

Benchmarks

Three apps moved from react-native-web 0.21 to @rootnative/web. In each app, the script time at load is 8–20 % lower, and the JavaScript is 2–4 % smaller after gzip. With static output, the server HTML is 31–57 % smaller after gzip. Some interactions cost more style work. Benchmarks gives every number, also the worse ones.

Learn more

Development

pnpm install
pnpm --filter @rootnative/playground dev # one route per component
pnpm docs:dev # the docs site
pnpm test # Vitest in a real Chromium
pnpm lint
pnpm typecheck
pnpm build
pnpm preflight # every CI gate, in the order CI runs them

The monorepo uses pnpm, TypeScript 7, tsdown, Vitest 5 in browser mode with Playwright, oxlint, Prettier, and Docusaurus.

packages/
  web/          @rootnative/web
  web-expo/     @rootnative/web-expo, for an Expo app
  web-metro/    @rootnative/web-metro, for a React Native app with no Expo
  playground/   Vite app with one route per component
  expo-demo/    Expo app for check:expo
  metro-demo/   React Native CLI app for check:metro
docs/           the docs site
scripts/        the llms, brand, and check scripts

Each component lives in one folder with its types and its tests.

After you change a docs page, run pnpm build:llms. It writes docs/static/llms-full.txt and copies docs/static/llms.txt into the package. CI fails when they don't match the pages. After an API change, also edit docs/static/llms.txt, which is written by hand.

CI runs pnpm preflight, which includes three release checks. pnpm check:versions checks that the CHANGELOG and the Status page name the version in packages/web/package.json, and pnpm check:versions:fix repairs the link footer and the Status line. pnpm check:artifact runs after the build and checks that the npm tarball has each file that exports names. pnpm check:consumer puts that tarball into the small app in e2e/consumer, checks its types, builds it with the Vite plugin, and opens the page in Chromium.

License

MIT