github jpudysz/react-native-unistyles v3.9.0
Release v3.9.0

2 hours ago

What's Changed

A minor release with no breaking changes. The Babel plugin is now deprecated and will be removed in Unistyles 4.0. Re.Pack, Rspack and Rsbuild get UnistylesPlugin, an experimental integration that works without the Babel plugin, like withUnistylesConfig does for Metro. Fixes cover views that keep the previous theme after a freeze, a concurrent render, or a React Compiler memo, Reanimated fades that end at the wrong opacity, and props a theme sets to undefined. On Android, rt.insets.top is correct with a hidden status bar below Android 11 and in desktop windows. Unistyles also builds against React Native nightlies again.

๐Ÿ“ฃ Deprecation: Babel plugin

  • The Babel plugin (react-native-unistyles/plugin) is deprecated and will be removed in Unistyles 4.0. It works the same as before in 3.x, so you don't have to change anything to upgrade to 3.9.0. Where your bundler has a replacement, you can switch now:
Bundler Replacement Guide
Metro (Expo, bare RN) withUnistylesConfig in metro.config.js Metro
Re.Pack, Rspack, Rsbuild UnistylesPlugin in your Rspack config (new, see below) Re.Pack
Vite, Next.js and others none yet, keep the Babel plugin in 3.x Babel plugin
  • Both integrations replace the Babel plugin, they don't run next to it. Remove react-native-unistyles/plugin from babel.config.js, Unistyles throws an error if both are set up
  • styles.useVariants() no longer changes styles, use the styles it returns. The codemod converts your components:
npx jscodeshift --parser=tsx --extensions=tsx,ts,jsx,js -t node_modules/react-native-unistyles/codemods/use-variants.js src
  • Jest needs no changes
  • RepackUnistylePlugin and BASE_REPACK_EXCLUDE_PATHS from react-native-unistyles/repack-plugin are deprecated too and will be removed in 4.0. RepackUnistylePlugin still works and prints a warning. Replace it with UnistylesPlugin, or add react-native-unistyles/plugin to your babel.config.js (see Usage with Re.Pack) (#1371)

โœจ New

  • Experimental Re.Pack, Rspack and Rsbuild integration. UnistylesPlugin runs the resolver of the Metro integration inside Rspack, so it swaps the same imports and StyleSheets record their dependencies while they run, without the Babel plugin. It takes no options (no root, autoProcessImports or autoProcessPaths) and requires @rspack/core 1.7.5 or newer (#1371 by @whydidoo, docs)
// rspack.config.mjs
import * as Repack from '@callstack/repack'
import { UnistylesPlugin } from 'react-native-unistyles/repack-plugin'

export default {
    // other config
    plugins: [
        new Repack.RepackPlugin(),
        new UnistylesPlugin()
    ]
}
  • On the web, add it to tools.rspack in Rsbuild, or to plugins of your rspack.config.mjs, and resolve react-native to React Native Web. The guide has full configs for both
  • The swap runs before Module Federation decides what is shared, so the host and every remote use one copy of the swapped components. Share react-native, react-native-unistyles and react-native-unistyles/ in every container
  • Libraries in node_modules get the swap too. A second copy of Unistyles (e.g. nested in a library's node_modules) prints a warning, because its styles won't update
  • Tested with Re.Pack's Rspack setup, not its webpack setup. Restart Re.Pack with --reset-cache after switching

๐ŸŽจ Themes and styles

  • Views in a frozen subtree (react-freeze, React Navigation's freezeOnBlur) now show the new theme when they come back, also when they don't re-render (React.memo, bailed-out list cells). Before, a theme change made while they were frozen was lost. Views whose styles didn't change are still restored without a commit (#1389, closes #1379)
  • <ScopedTheme> no longer leaks its theme to views outside the scope when a concurrent render (startTransition, Suspense) yields inside it. Unistyles now reads each view's theme from its scope instead of a global value set during render (#1392, closes #1381)
  • A view faded with Reanimated no longer ends at a mid-animation opacity (e.g. 0.5) after a theme change and an unrelated React commit. After its own commits, Unistyles gave React's node the props Reanimated had applied during the animation. React's node now keeps its own props plus the Unistyles values (#1393, closes #1380)
  • A view that first mounts after a theme change from an element kept by the React Compiler (or a useMemo) now shows the new theme. Before, it kept the style object made under the old theme. Each style now records the revision it was made at, and Unistyles commits the current values when a view mounts with an older one (#1394, closes #1386)
  • Props that a theme sets to undefined are now reset after a theme change. Before, the view kept the previous theme's value, e.g. backgroundColor: isLight ? 'red' : undefined stayed red in the dark theme. Unistyles now sends null, like React does. Props the new style leaves out entirely aren't reset yet (#1395)

๐Ÿค– Android

  • Below Android 11, rt.insets.top is now 0 when the status bar is hidden through WindowInsetsControllerCompat, e.g. React Native's StatusBar with edge-to-edge, SystemBars from react-native-edge-to-edge or react-native-keyboard-controller. Before, it kept the status bar height (#1390, closes #1384)
  • In Android 15 desktop windowing, rt.insets.top now includes the caption bar the system draws over the top of the app. Before, it was 0, so content was drawn under the caption bar. The top inset now takes the larger of the status bar and the caption bar (#1391, closes #1385)

๐ŸŒ Web

  • CSS rules are no longer deleted while elements that aren't attached to the document yet still use them, e.g. content in a portal whose container a map appends to its pane later. Before, the rule came back only on a later render of the style (#1398 by @erickreutz, closes #1397)

๐Ÿ—๏ธ React Native nightlies

  • Unistyles builds against React Native nightlies again on iOS and Android. React Native changed ShadowNodeFamily::nativeProps_DEPRECATED to a struct (react/react-native#59624). Unistyles detects the type at compile time, so it builds against both released versions and nightlies (#1388 by @Abbondanzo)

๐Ÿงช Internal

  • New e2e scenarios: status-bar, safe-area (compares rt.insets with react-native-safe-area-context), undefined-reset, a Reanimated fade after a theme change, and elements kept across a theme change (#1390, #1391, #1393, #1394, #1395)
  • The e2e host runs on an Android API 29 emulator too, can launch a run in a desktop window (--window desktop) and skip scenarios (--skip) (#1390, #1391)

โค๏ธ Contributors

Thanks to everyone who sent a PR for this release:

And to those whose reports shaped the fixes:

Full Changelog: v3.8.2...v3.9.0

Don't miss a new react-native-unistyles release

NewReleases is sending notifications on new releases.