Patches
Nitro UI Brownfield is a preview. Nitro UI 0.3.0 lacks two things this library needs: several hosts and Activities with React alive in one Android process, and a way to close a root and release it. So the library does not run on stock Nitro UI. When you install it, bun run nuib patches install applies patch files to some Nitro UI packages inside your own node_modules. This page says what changes, which changes can affect code that does not use this library, how to read the patches, how to remove them, and what to do when the step fails.
Read this before you adopt the preview
Section titled “Read this before you adopt the preview”- The patches change the copies of Nitro UI that your whole app uses, not only the surfaces this library mounts. Anything in your app that already uses a patched package runs the patched code.
- The patches support Nitro UI 0.3.0, exactly. Any other version is refused, not tried.
- The patch step works with Bun only. Bun applies the patches when it installs your dependencies.
- Most of the changes are Android changes, and each one says so. The root handle, root release and synchronous first render are in the shared JavaScript.
- This is independent work. It is not made, sponsored or endorsed by Margelo.
What changes, by package
Section titled “What changes, by package”The shipped patch set touches five Nitro UI packages. The other Nitro UI packages are not touched.
| Package | What changes, in user terms | Why this library needs it |
|---|---|---|
nitro-ui-renderer |
renderRoot hands back a handle to the root it created. A root can be updated, unmounted and released, and an unmounted root releases its reconciler instead of staying alive. The first render can optionally run synchronously. The first rendered root no longer sits in React’s hooks dispatcher. |
The library mounts, updates and closes one root per surface, so it needs a root it can close. Without the handle, the library does not typecheck against renderRoot, and unmounted roots stay alive. |
nitro-ui-renderer (Android) |
The single process-wide Android host is replaced by one NitroHost per host. A second Activity can have React at the same time as the first. The old AndroidHost.context stays as a deprecated shim that returns the context of the host attached last. The keyboard dismissal object is created only while a dismissal runs. |
Stock Nitro UI throws when a second Activity starts React. The shim keeps nitro-ui-glass compiling. The lazy dismissal object keeps each mounted surface from inserting a view into your app’s content view. |
nitro-ui-navigation (Android) |
Navigation screens, stacks, tabs, splits and shared elements find their host from their own view, not from the process-wide host. | A navigation tree has to follow its own host once there is more than one. |
nitro-ui-runtime (Android) |
The NitroActivity host is kept in its retained session. |
The same several-hosts change, applied to Nitro UI’s own Activity. |
nitro-ui-dev (Android) |
The development tools open over the current host and do nothing while no host is attached. The development sheet is wrapped in a Material 3 theme, so it opens in a host whose theme is not a Material theme. The sheet change is the one of margelo/nitro-ui#948, applied as it is. | The tools need to find the right host. The sheet change stops a debug-build crash in hosts without a Material theme. |
nitro-ui-bundler |
The dev server terminal lists the connected apps. A host can tell the dev client which app and device it is. The terminal says when the tool that started it is opening an app. | Convenience for the development loop. Nothing in the library’s function depends on it. |
Each row is a sum of small changes. bun run nuib patches verify prints, for each patched package, the npm tarball the patch was made against (its dist.integrity, the same string Bun writes for that package in bun.lock). The patch set names no commit of any repository.
Which changes affect code that does not use this library
Section titled “Which changes affect code that does not use this library”Because the packages are patched in place, these changes are visible to the rest of your app. The first rows are the ones to read twice: they change what every Nitro UI user of the project sees, not only the library’s surfaces.
| Change | Kind | Who notices |
|---|---|---|
| Dev server terminal shows connected apps, app and device names, and an “opening app” line | Behavior change | Everyone who runs the Nitro UI dev server in this project. It changes what the terminal prints. |
| Development tools open over the current host, and do nothing while no host is attached | Behavior change | Android debug builds that use the Nitro UI development tools. |
Process-wide Android host replaced by one host per NitroHost, with a deprecated AndroidHost.context shim |
Behavior change | Android code that reads AndroidHost.context. With several Activities alive it returns the context of the host attached last. |
| Keyboard dismissal object created only while dismissing | Behavior change | Android code that calls Keyboard.dismiss(). See Known limits. |
renderRoot returns a root handle, optional synchronous first render |
Addition | Code that calls renderRoot directly. Existing calls keep working. |
| Unmounted roots release their reconciler | Fix to stock behavior | Anyone who unmounts roots. In stock Nitro UI an unmounted root stays alive. |
| Development sheet is wrapped in a Material 3 theme, so it opens in hosts without a Material theme (the change of upstream #948, still open) | Fix to stock behavior | Android debug builds whose theme is not a Material theme. The app’s own sheet theme no longer reaches that dialog. |
Copying the attached hosts in NitroHost no longer throws NoSuchElementException when a weak key was cleared |
Fix inside the per-host class above | Android apps with several hosts. See Upstream. |
See exactly what changes
Section titled “See exactly what changes”The patch files ship inside the nitro-ui-brownfield-cli package, in src/patches/set/, next to a manifest.json. There is one patch file per package, named <package>@<version>.patch. They are plain git diff output against the unpacked npm tarballs of that Nitro UI version, so you can read them in any editor or apply them yourself with git apply. The manifest records the SHA-256 of each patch file, the hash of every file before and after patching, and the npm tarball each patch was made against.
To see what an install would do without changing anything, run it with --dry-run:
bun run nuib patches install --dry-runIt prints nuib patches install --dry-run: would change:, then the package.json entries it would add, the files it would create or replace, and the state file, then Nothing was changed.
Install, check and status
Section titled “Install, check and status”bun run nuib patches install # check versions, write the entries, run bun install, verifybun run nuib patches verify # read-only check, exit 0 when every patched file matchesbun run nuib patches status # the same report, always exit 0bun run nuib patches --help prints this:
nuib patches <install|verify|undo|status> [options]
Applies the Nitro UI patch set this nuib ships to the app, through Bun's patchedDependencies: the patch files go topatches/nuib/, package.json gets one patchedDependencies entry per patched package, and bun install applies them.
install check that every patched package is installed at exactly the supported version (nothing is written otherwise), add the patch files and entries, run bun install, verify the patched filesverify check package.json, patches/nuib/ and the patched files in node_modules; exit codes: 0 installed and verified, 3 not installed, 4 partially applied or not applied, 5 wrong version, 6 package.json and patches/nuib/state.json disagree, 7 run nitro-ui prepare --cleanundo remove exactly what install added, run bun install, verify the packages are originalstatus print the same report as verify, always exit 0
After install or undo run: nitro-ui prepare --clean
Options:--app <dir> the app root with package.json and bun.lock (default: the current directory)--dry-run install, undo: print what would change and change nothing--no-install install, undo: do not run bun install; say to run it-h, --help this textinstall does five things, in this order:
- It reads the
package.jsonof every patched package innode_modulesand stops, writing nothing, if one is not at exactly the supported version. - It refuses on conflicts: a
patchedDependenciesentry of yours for the same package version, or a file of yours where a patch file goes. - It writes a state file, copies the patch files into
patches/nuib/, and adds only the missingpatchedDependenciesentries topackage.json. Every other byte ofpackage.jsonstays as it was: key order, indentation, line endings and the trailing newline. - It runs
bun install. With--no-installit tells you to run it yourself. - It verifies the patched files by hash, then prints
Nitro UI 0.3.0 patches installed and verified.and aNext:line that asks you to runnitro-ui prepare --cleanand to commitpackage.json,bun.lockandpatches/nuib/.
The options are --app <dir>, to name the project root when you are not in it, --dry-run and --no-install. --dry-run and --no-install apply to install and undo only.
After install or undo, run bun run nitro-ui prepare --clean. Nitro UI copies Package.swift into .nitro/native/ instead of linking it, and it keeps native build caches that --clean removes. Commit package.json, bun.lock and patches/nuib/.
Undo and reinstall
Section titled “Undo and reinstall”bun run nuib patches undo --dry-run # print what would change, change nothingbun run nuib patches undobun run nitro-ui prepare --cleanundo removes exactly what install added:
- It removes only the
patchedDependenciesentries and the files thatinstalladded. Your own entries and patch files stay, and so does any change you made topackage.jsonafterinstall. - It runs
bun install. - It checks that the patched files are back to their original content.
- It removes the state file.
It also works from a partial state: an interrupted install, missing entries or files, or a missing state file. A second undo does nothing and exits with 0.
Reinstalling. Running install a second time changes nothing and does not run bun install; it prints Nothing was changed. after reporting that the patches are already installed and verified. Because the entries live in package.json and the patch files are committed, a fresh bun install (a teammate’s checkout, or rm -rf node_modules && bun install) applies the same patches again without running nuib. If an install or an undo stops partway, run the same command again: it resumes from the state file.
Supported version
Section titled “Supported version”The patches support exactly Nitro UI 0.3.0. If any patched package is at another version, install writes nothing, names the version it found, and prints the bun add --exact command that fixes it. A newer release can be on npm while this library still supports only Nitro UI 0.3.0, so an unpinned install can land on a version the patch step refuses: pin the exact version.
Upstream
Section titled “Upstream”Nitro UI Brownfield is a third-party library, so the patches only exist until Nitro UI has what the library needs. This is where the related upstream work stands.
- margelo/nitro-ui#726, “Multiple react roots issues”, is the upstream issue about the missing pieces. It is open. This library makes no promise about whether or when it is resolved.
- margelo/nitro-ui#886, “fix(android): avoid NoSuchElementException when copying weak keys”, is a pull request that is merged. It is included in Nitro UI 0.3.0, the version this library supports, for Nitro UI's own files. It fixes a crash that comes from copying the keys of a
WeakHashMapwithtoList(), in several places of Nitro UI on Android.NitroHost.ktexists only in this library’s patch, so the patch carries the same fix for it. - margelo/nitro-ui#948, “fix(dev): open the Android dev menu in apps with an AppCompat theme”, is a pull request that is open. It fixes a crash when the development sheet opens in an Android app whose theme is not a Material theme. The patch set carries that change as it is, until a Nitro UI release includes it.
Changed since 0.2.0
Section titled “Changed since 0.2.0”- The patch set is for Nitro UI 0.3.0 only. There are no 0.2.0 patch files. A state file written by another version of this CLI is refused with exit 6 and a message that names
nuib patches undo, thennuib patches install. - Upstream #886 is now in Nitro UI itself. The patch keeps its own copy of the fix only for
NitroHost.kt. - The development sheet change is now upstream’s own (#948), applied as it is. The earlier limit about a host whose sheet theme has no shape appearance is gone, because the dialog is always wrapped in a Material 3 theme.
- The manifest records the npm tarball checksums of each patch and no commit of any repository, and
verifyprints the tarball integrity instead of a source commit.
Independence
Section titled “Independence”Nitro UI Brownfield is independent work. It is not made, sponsored or endorsed by Margelo. “Nitro UI” and “Margelo” are used only to say what this library works with.
The patch files contain lines of Nitro UI source as context, so they are distributed under the Nitro UI license. The NOTICE file of the repository says what derives from Nitro UI and reproduces the license that requires it. The link works once the repository is public.
Troubleshooting the patch step
Section titled “Troubleshooting the patch step”Every expected failure prints one message that says what to do, without a stack trace, and exits with a code. Messages start with nuib patches:. In the messages below, <name>, <path> and similar words in angle brackets stand for text that depends on your project.
| Exit code | Meaning |
|---|---|
| 0 | Installed, and every patched file matches |
| 1 | Error: no or damaged patch set, unreadable package.json, missing node_modules, Bun not on PATH, another package manager, a workspace member, or a failed bun install |
| 2 | Usage error |
| 3 | Not installed |
| 4 | Partially applied, or the entries are in package.json but not applied |
| 5 | Wrong Nitro UI version |
| 6 | package.json, the patch directory and the state file disagree |
| 7 | A copy in .nitro/native/ is older than the patches |
install also uses 5 for a wrong version, 8 for a conflict with a patch of yours, and 6 for a state left by another version of this CLI or by an unfinished undo.
A Nitro UI package is not at the supported version
Section titled “A Nitro UI package is not at the supported version”install writes nothing and exits with 5. verify also exits with 5. status prints the same message and exits with 0.
nuib patches: this release of nuib supports Nitro UI 0.3.0 only. These packages are not at the supported version:nitro-ui-renderer: installed <found>, supported 0.3.0Nothing was changed. Install the supported versions with this one command (a dev dependency stays a dev dependency):bun add --exact nitro-ui-renderer@0.3.0then run: nuib patches install- Every package that is not at the supported version gets one row, and one
bun add --exactcommand lists all of them.verifyandstatusprint the same message without the wordsNothing was changed.; the last line namesnuib patches verifyforverifyandnuib patches installforstatus. - A package that is missing reads
<name>: not installed, supported <version>. A package found in two versions readsinstalled <a> and <b>. bun addkeeps a package thatpackage.jsonlists underdevDependenciesthere, so one command is enough.- If
node_modulesdoes not exist, the message isnode_modules is missing in <app>. Run bun install first, then nuib patches install.and the exit code is 1.
Cause: the patches are made against one exact Nitro UI version. Bun does not refuse a mismatch on its own: with another version installed it leaves the package unpatched and exits with 0. The patch step checks the version before it writes anything, so you do not end up with an unpatched app that looks installed.
Fix: run the bun add --exact command the message prints, then the nuib patches command it names. A patched package that your project reaches only through another package (for example nitro-ui-bundler through nitro-ui-cli) is fixed by the same command only when that other package also asks for Nitro UI 0.3.0. Upgrade it too if verify still reports the wrong version.
A patch of your own for the same package
Section titled “A patch of your own for the same package”install exits with 8 and writes nothing.
nuib patches: package.json already patches <name>@0.3.0 with <path>. Bun allows one patch per package version, so the Nitro UI 0.3.0 patch cannot be added next to yours. Nothing was changed. Remove that entry from patchedDependencies (your patch file can stay), then run nuib patches install again.The same exit code appears when a file is already where a patch file goes:
nuib patches: patches/nuib/<file> already exists and is not the file nuib installs (its content differs and patches/nuib/state.json does not record it). Nothing was changed. Move that file elsewhere, then run nuib patches install again.Cause: Bun applies one patch per package version, so your entry and this library’s cannot both apply to the same package. The patch step never overwrites or deletes a file it did not put there.
Fix: remove your entry for that package from patchedDependencies; your patch file can stay on disk. Your patch and the library’s cannot both be active. For the file case, move the file somewhere else and run install again.
Partially patched packages
Section titled “Partially patched packages”verify exits with 4. The rows name the package and the files that differ.
nitro-ui-dev@0.3.0: PARTIAL, 1 of 7 files differ from the patched content: <file>nuib patches: the Nitro UI 0.3.0 patches are partially applied. Reinstall the packages with: rm -rf node_modules && bun installRelated messages with the same exit code:
<name>@0.3.0: not applied (the package has its original files)nuib patches: the patch entries are in package.json but not applied to node_modules. Run: bun installnuib patches: the Nitro UI 0.3.0 patches are not installed, but node_modules has patched files. Reinstall the packages with: rm -rf node_modules && bun installinstall can also end with exit 4 when Bun ran but the packages are not patched as expected:
nuib patches: bun install ran, but the packages are not patched as expected. Reinstall them with: rm -rf node_modules && bun install, then run nuib patches verify.Cause: files in node_modules do not match what the patches produce: a hand edit inside a patched package, an install that stopped halfway, or node_modules from before the entries were added. A plain bun install does not repair a file you edited by hand.
Fix: run the command the message gives. For “not applied” that is bun install. For every other case, delete node_modules and install again, then run bun run nuib patches verify.
An install or an undo that did not finish
Section titled “An install or an undo that did not finish”verify exits with 6 with one of these rows:
an nuib patches install did not finishan nuib patches undo did not finishinstall refuses to run after an unfinished undo:
nuib patches: an nuib patches undo did not finish. Run nuib patches undo first. Nothing was changed.If bun install fails during install or undo, the command exits with 1, prints bun install failed (exit N):, then the last 25 lines of Bun’s output, and one of these:
The patch entries are in place. Fix the problem and run bun install, then nuib patches verify; or remove them with nuib patches undo.The nuib entries are removed from package.json, but node_modules still has the patched files. Fix the problem and run nuib patches undo again.Cause: the state file records the step in progress while a command runs. If the command stops, for example on Ctrl+C or a failed bun install, the file keeps that step.
Fix: run the same command again; it resumes from the state file. To go back to the original packages instead, run bun run nuib patches undo. A failed undo keeps the state file, so the next undo finishes the job.
The state file, package.json and the patch files disagree
Section titled “The state file, package.json and the patch files disagree”verify exits with 6, lists what differs, and ends with this line:
nuib patches: package.json, patches/nuib/ and patches/nuib/state.json disagree. Restore them with nuib patches install, or remove them with nuib patches undo.The listed rows are any of these:
package.json has no patchedDependencies entry "<name>@0.3.0": "<path>" (patches/nuib/state.json records it)patches/nuib/<file> is missingpatches/nuib/<file> differs from the patch nuib installspatches/nuib/state.json is missing, but package.json or patches/nuib/ has nuib patch entriespatches/nuib/state.json records the <label> patch set installed by another nuib version, not this one (Nitro UI 0.3.0)install and undo can also stop with these, exit 6:
nuib patches: patches/nuib/state.json is not a state file this nuib can read. Restore it from version control, or delete it and run nuib patches undo.nuib patches: patches/nuib/state.json records the <label> patch set from another nuib version. Run nuib patches undo, then nuib patches install. Nothing was changed.Cause: one of the three places was edited, merged or reverted without the others: a merge that dropped the entry from package.json, a deleted patch file, or a state file from an older release of this CLI.
Fix: run bun run nuib patches install to restore the three places to the current patch set, or bun run nuib patches undo to remove them. If the state file comes from another version of this CLI, run undo and then install. Committing package.json, bun.lock and patches/nuib/ together prevents this on a teammate’s checkout.
nitro-ui prepare --clean is needed
Section titled “nitro-ui prepare --clean is needed”verify exits with 7:
nuib patches: .nitro/native/<package>/<file> is older than the installed patches. Run: nitro-ui prepare --cleanCause: Nitro UI links most native sources into .nitro/native/, so they follow node_modules. It copies Package.swift instead, and it keeps native build caches. After a patch is applied or removed, those copies are stale.
Fix: run bun run nitro-ui prepare --clean. The stale-copy check looks only at files that nitro-ui prepare copied. Whether SwiftPM, Gradle and CMake rebuild correctly after a patch change is not verified; --clean is the safe step.
Messages from undo
Section titled “Messages from undo”-
Done, exit 0:
nuib patches: the Nitro UI 0.3.0 patches are removed and the packages verified as original., then aNext:line that asks fornitro-ui prepare --clean. -
Nothing installed, exit 0:
nuib patches: nothing to undo: no Nitro UI 0.3.0 patches from nuib are installed. -
Packages still differ after the reinstall, exit 4, and the state file is kept:
nuib patches: bun install ran, but these packages still differ from the original. Reinstall them with: rm -rf node_modules && bun install, then run nuib patches undo again. -
With
--no-install:nuib patches: bun install was not run (--no-install). Run bun install, then nuib patches undo again to verify and remove patches/nuib/state.json. -
A state file that records another patch set:
nuib patches: the packages were not compared with their original files: <state file> records another patch set (<label>).
Other messages
Section titled “Other messages”| You see | Cause and fix |
|---|---|
nuib patches: this app has package-lock.json and no bun.lock. The Nitro UI patches are applied by Bun only (the Nitro UI CLI requires Bun). Nothing was changed. (exit 1; the file name can also be npm-shrinkwrap.json, yarn.lock or pnpm-lock.yaml) |
The patch step supports Bun only. Use Bun for this project, as the Nitro UI CLI does. |
nuib patches: <app> has no bun.lock but <dir> has: Bun reads patchedDependencies only from the root package.json. Run nuib patches with --app <dir>. Nothing was changed. (exit 1) |
You ran it in a workspace member. Run it from the workspace root, or pass --app <root>. |
nuib patches: no package.json in <app>. Run it from the app root (or pass --app <dir>). (exit 1) |
Run it in the directory that has package.json and bun.lock, or pass --app <dir>. |
nuib patches: cannot read package.json: <reason> at line <n>. Nothing was changed. (exit 1) |
Fix the syntax error of package.json at that line. |
nuib patches: this nuib build ships no Nitro UI patch set (<path> is missing). (exit 1) |
The installed CLI has no patch files. Reinstall the CLI. |
nuib patches: the patch set is damaged: <what>. Reinstall nuib. (exit 1) |
A shipped patch file or its manifest was changed after it was built. Reinstall the CLI. |
nuib patches: unknown subcommand "<x>". Use install, verify, undo or status (nuib patches --help). (exit 2) |
Use one of install, verify, undo, status. |
nuib patches: unknown option "<x>" (nuib patches --help). or nuib patches: --app needs a value (exit 2) |
Use only the options in the help text above. |
nuib patches: Bun is required (https://bun.sh): <sub> runs bun install so the Nitro UI packages are reinstalled with the patch set, and bun is not on PATH. Nothing was changed. (exit 1; without for undo) |
Install Bun, or put it on PATH. |
nuib patches: --dry-run applies to install and undo only (exit 2; the same for --no-install) |
Remove the option from verify or status. |
nuib patches: <sub> failed: <message> (exit 1) |
An error the patch step does not expect. Run it again, and report the message if it repeats. |
What the patch step does not cover
Section titled “What the patch step does not cover”- Bun only. The entries go to the root
package.json, because Bun ignorespatchedDependenciesin workspace members. verifyhashes the files the patches touch. It does not hash the rest of the package.- Nothing here builds native code. That the patched sources build is not checked by the patch step.
- Other package managers, Windows paths and file mode changes are not covered by the step’s tests.
- Two
nuib patchescommands run at the same time on the same app are not guarded against each other.