One line of spaces, dead on launch: the JSX whitespace crash
The build launched and died in under a second: SIGABRT, no JavaScript exception in the device log, nothing useful in the crash report. The cause was a run of spaces sitting between two closing tags on the same line. Every check in the repo said the code was fine.
Whitespace-only JSX text nodes are the one class of React Native crash that tooling actively hides. They are invisible in a diff, legal to TypeScript, and filtered out by the obvious lint rule. If your app aborts on the first frame with an invariant about text strings and you cannot find the string, start here.
The crash pointed at the wrong layer
Sequence from the device: process starts, splash appears, abort at roughly 0.7 seconds. No redbox on the TestFlight build, and the system log carried no JS message — only the abort. A native crash with no JS frame sends you into the build system, so the first attempts were reverts and dependency swaps. Five builds went out that way, each one a guess.
What finally surfaced it was a fatal-error boundary that prints the JS message and component stack on screen instead of a black view. The message was React Native's own invariant:
Error: Text strings must be rendered within a <Text> component.
Something was handing a raw string to a <View>. The component in the stack renders on the first frame of every launch, which is why nothing ever painted.
Why a single line of spaces becomes a string child
JSX drops whitespace between elements only when that whitespace contains a newline. Whitespace that lives entirely on one line — including the padding an editor leaves between two closing tags — is preserved as a literal string child:
<View>
<TouchableOpacity>...</TouchableOpacity> </View>
// compiles to:
createElement(View, null, child, " ")
React Native's renderer rejects string children outside <Text>, so the throw is deterministic. It is not a race and not device-specific; it fires on the frame that mounts the tree.
Here a tab reorder joined two closing tags onto one line; the spaces came from the editor, not from typing. A second instance sat several hundred lines away, latent because that view only mounts after a tab press.
Reproduce it in six lines
export default function Bad() {
return (
<View>
<Text>hello</Text> </View>
);
}
Mount it. On a release build you get the invariant; in development the redbox points at the parent element, because the whitespace child carries no source location of its own.
The one-line check
One pattern across every TSX file, and the result must be zero lines:
rg -n --glob '*.tsx' --glob '!node_modules' '/>[ \t]+</' .
BSD grep on macOS has no -P, so the portable version is Perl:
find . -name '*.tsx' -not -path '*/node_modules/*' \
-exec perl -ne 'print "$ARGV:$.: $_" if m{/>[ \t]+<}' {} +
Then make it a gate instead of a habit. This script exits non-zero and lists every offending line, so packaging cannot proceed past it:
// scripts/check-jsx-whitespace.mjs
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
const bad = [];
(function walk(dir) {
for (const e of readdirSync(dir, { withFileTypes: true })) {
if (e.name === 'node_modules' || e.name === '.git') continue;
const p = join(dir, e.name);
if (e.isDirectory()) walk(p);
else if (p.endsWith('.tsx'))
readFileSync(p, 'utf8').split('\n').forEach((l, i) => {
if (/\/>[ \t]+</.test(l)) bad.push(`${p}:${i + 1}`);
});
}
})('.');
if (bad.length) {
console.error('whitespace-only JSX text:\n' + bad.join('\n'));
process.exit(1);
}
console.log('jsx whitespace: clean');
Why the obvious detectors miss it
- tsc: the JSX is type-valid. A string child is legal in the AST and illegal at runtime.
- unit tests: they exercise logic, and none of them mount the tab bar.
- AST lint rules that filter
text.trim() !== '': these nodes trim to empty, so a rule written that way skips exactly the case you need. - diff review: whitespace-ignoring diffs hide the change, and a joined line reads as a formatting nit.
The fix
Put the closing tags on separate lines. That reintroduces the newline, and the compiler strips the whitespace child entirely — no prop change, no runtime code involved:
- </TouchableOpacity> </View>
+ </TouchableOpacity>
+ </View>
Then verify on a device before uploading. A clean type-check and a green test suite do not prove the frame renders, because the failure happens at mount, not at build.
Add the gate to the release checklist next to the type-check and the test run. It takes under a second, and it is the difference between a crashed launch and a caught line.
Related: build gates that fail instead of shipping blank screens, the iOS 27 UIScene crash, and the pre-upload rejection checklist.
Get new posts
One email when a new post ships. No spam.