Commit 9ef28ea
committed
[Android] Fix BundleDownloader Content-Type matching for Metro's "application/javascript; charset=UTF-8"
Regression introduced in the streaming refactor (e9e200a).
Metro actually serves the JS bundle chunk with
Content-Type: application/javascript; charset=UTF-8
not the bare `application/javascript` my refactor was matching against.
With strict equality, `onChunkHeader` returned null (so the streaming
sink was never opened), the body was buffered into the in-memory
accumulator, and `onChunkComplete` hit the `else -> Unit` branch and
silently dropped it. Symptoms in dev on the RNTester emulator: heap
spiked to ~200 MB during the download, then dropped back, but the dev
loading view sat at "Bundling 99%" forever because callback.onSuccess()
was never fired.
Fix: parse Content-Type properly. New private helper `mediaType(...)`
strips the parameter portion (`; charset=...`) and lower-cases the
result, and the two routing predicates (`isJsBundleChunk` and
`isProgressChunk`) compare against the parsed media type. Also: the
else branch now logs a warning instead of silently dropping, so a
future Metro change that introduces yet another Content-Type variant
will be visible in logcat rather than stranding the user at 99%.
Updated `LargeMultipartSource` to emit the real Metro Content-Type
(`application/javascript; charset=UTF-8`) so the perf tests guard
against this exact regression class going forward. The perf tests pass
unchanged \u2014 the streaming path is still taken, output-size still equals
payloadBytes, and peak heap is still bounded.
Verified against a live Metro dev server: with the synthetic source
now matching production, `BundleDownloaderPerfTest` would have caught
this bug. `MultipartStreamReaderTest` (the 4 existing correctness
cases) is unaffected and still green.1 parent c869a8d commit 9ef28ea
3 files changed
Lines changed: 28 additions & 7 deletions
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/devsupport
- test/java/com/facebook/react/devsupport
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/BundleDownloader.kt
Lines changed: 23 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
269 | | - | |
| 268 | + | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
284 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
| |||
339 | 343 | | |
340 | 344 | | |
341 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
342 | 360 | | |
343 | 361 | | |
344 | 362 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| |||
0 commit comments