fix(resource-fetcher): avoid this in static fs field initializer - #1310
Merged
msluszniak merged 1 commit intoJul 17, 2026
Merged
Conversation
An async arrow inside the static 'fs' class-field initializer relies on 'this' binding to the class. When an app resolves the library through the "react-native": "src/index" entry, Metro compiles this TS source with the app's Babel config; under @react-native/babel-preset with unstable_transformProfile 'hermes-stable' or 'hermes-canary', the async transform hoists the arrow's 'this' capture (var _this = this) to module scope. ResourceFetcher.fs.readAsString then calls _this.getAdapter() on the module context and every LLM/model load fails with 'TypeError: undefined is not a function' right after download. Referencing the class by name sidesteps the transform entirely. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
|
Thank you for the PR, tested and works correctly |
msluszniak
approved these changes
Jul 17, 2026
msluszniak
added a commit
that referenced
this pull request
Aug 3, 2026
## Description Patch release **v0.9.3**. The bundleId/system telemetry change (#1311) is already merged into `release/0.9`. This PR cherry-picks the following bug fixes from `main` (chronological order, with `-x`) and bumps the core package version: - fix(resource-fetcher): avoid `this` in static `fs` field initializer (#1310) - fix(android): forward ExecuTorch consumer ProGuard rules (#1325) Bump `packages/react-native-executorch/package.json` to `0.9.3`. Adapter packages (`bare-resource-fetcher`, `expo-resource-fetcher`) untouched by the cherry-picks — versions not bumped. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) ### Tested on - [ ] iOS - [ ] Android ### Related issues #1310 #1325 ### Checklist - [x] I have performed a self-review of my code - [x] My changes generate no new warnings --------- Co-authored-by: Cuc Dan Mihai <danchily@gmail.com> Co-authored-by: Cuc Dan Mihai <dan-mihai.cuc@visma.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Injun Choi <80089617+injunchoi98@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ResourceFetcher.fs.readAsStringis an async arrow inside a static class-field initializer and relies onthisbinding to the class. Because the package resolves through the"react-native": "src/index"entry, Metro compiles this TypeScript source with the consuming app's Babel config. Under@react-native/babel-presetwithunstable_transformProfile: 'hermes-stable'(or'hermes-canary'), the async transform hoists the arrow'sthiscapture to module scope:_this.getAdapterisundefined, so every model load fails withTypeError: undefined is not a functioninsideLLMController.load, right after the download finishes — on both iOS and Android. Thedefaulttransform profile compiles it correctly, which is why this only bites apps that opt into the hermes profiles.Fix: reference the class by name instead of
this. One line, no behavior change.Introduces a breaking change?
Type of change
Tested on
Testing instructions
unstable_transformProfile: 'hermes-stable'on@react-native/babel-presetinbabel.config.js.useLLM({ model: GEMMA4_E2B }), on a physical device.TypeError: undefined is not a functionafter the download completes. With it: the model loads and generates.Reproducible without a device: run
@babel/coreonsrc/utils/ResourceFetcher.tswith the preset above and inspect the output — thevar _this = thishoist lands at module scope.Verified end-to-end on a physical iPhone 16 with
GEMMA4_E2B(MLX backend): download → load → generation all work with this patch (applied viayarn patchagainst 0.9.2).Screenshots
N/A
Related issues
N/A
Checklist
Additional notes
A repo-wide sweep found no other
thisusage inside static-field initializers, so this is the only affected site.🤖 Generated with Claude Code