Commit 238419a
committed
fix: atomic-write generated CSS and dts files
Metro spawns multiple worker processes that each transform
`components/web/metro-injected.js` and the CSS entry file. Both
transforms call `buildCSS`, which writes
`node_modules/uniwind/uniwind.css` via `fs.writeFileSync`. That call
truncates the file before writing, so when one worker is mid-write
another worker can observe a partial file as Tailwind compiles
`@import 'uniwind'` from `generateCSSForThemes`/`compileVirtual`.
The partial read fails to parse and surfaces as cryptic errors like:
SyntaxError: .../metro-injected.js: Missing closing }
at &:not(:where(.light, .light *, .dark, .dark *, ...))
This is the long-standing flake in #341 and #427: it reproduces on
Linux CI (concurrent workers, low-overhead scheduling) and is
effectively invisible on macOS. Enabling
`EXPO_UNSTABLE_TREE_SHAKING=1` widens the race window by adding
transforms and surfaces it consistently.
Route both `buildCSS` and `buildDtsFile` through a new
`atomicWriteFileSync` helper that stages to a unique temp file in
the same directory and renames onto the target. POSIX `rename` is
atomic and Windows' `MoveFileEx` (used by Node's `fs.renameSync`)
does atomic replace, so concurrent readers always see either the
previous file or the complete new file.
Refs: #3411 parent a2406b8 commit 238419a
3 files changed
Lines changed: 26 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 31 | + | |
34 | 32 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
| 27 | + | |
27 | 28 | | |
0 commit comments