feat(Worklets): read iOS dev bundle from file - #10181
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughReact Native dependencies now use local Yarn patches across workspace packages and examples. Apple worklets now load an existing downloaded remote bundle when available and fall back to downloading it. ChangesReact Native patch and bundle loading
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WorkletsModule
participant ScriptLoader
participant DownloadedBundle
WorkletsModule->>ScriptLoader: getScript(bundleURL, downloadedBundleFileURL)
ScriptLoader->>DownloadedBundle: Check cached bundle URL and path
DownloadedBundle-->>ScriptLoader: Return cached bundle when valid
ScriptLoader->>ScriptLoader: Download remote script when cache is unavailable
ScriptLoader-->>WorkletsModule: Return loaded script
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/react-native-worklets/apple/worklets/apple/ScriptLoader.mm`:
- Around line 110-119: Update loadRemoteScript to require a valid
downloadedBundleFileURL, attempt loadScriptFromFile directly, and catch read
failures so downloadScript(url) is used when the cached bundle cannot be read.
Preserve the existing remote-download behavior when no cached URL is provided.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 4845cb60-f560-4f56-ba92-addcdc898b03
⛔ Files ignored due to path filters (3)
.yarn/patches/react-native-npm-0.87.0-rc.4-5c97bcefe3.patchis excluded by!**/.yarn/**apps/fabric-example/ios/Podfile.lockis excluded by!**/*.lockyarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (15)
apps/common-app/package.jsonapps/fabric-example/ios/PrivacyInfo.xcprivacyapps/fabric-example/package.jsonapps/macos-example/package.jsonapps/next-example/package.jsonapps/tvos-example/package.jsonapps/web-example/package.jsondocs/docs-reanimated/package.jsondocs/docs-worklets/package.jsonpackage.jsonpackages/react-native-reanimated/package.jsonpackages/react-native-worklets/apple/worklets/apple/ScriptLoader.hpackages/react-native-worklets/apple/worklets/apple/ScriptLoader.mmpackages/react-native-worklets/apple/worklets/apple/WorkletsModule.mmpackages/react-native-worklets/package.json
| NSData *loadRemoteScript(NSURL *url, NSURL *downloadedBundleFileURL) | ||
| { | ||
| if (downloadedBundleFileURL != nil && | ||
| [[NSFileManager defaultManager] fileExistsAtPath:downloadedBundleFileURL.path]) { | ||
| return loadScriptFromFile(downloadedBundleFileURL); | ||
| } | ||
| return downloadScript(url); | ||
| } | ||
|
|
||
| std::shared_ptr<const ScriptBuffer> getScript(NSURL *url, NSURL *downloadedBundleFileURL) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Fall back to downloading when the cached bundle cannot be read.
fileExistsAtPath: only proves that a path entry exists. If the cached file is truncated, unreadable, or removed after the check, loadScriptFromFile throws and downloadScript is never called. Require a file URL, attempt the read, and download the remote bundle when the cached read fails.
Proposed fallback
NSData *loadRemoteScript(NSURL *url, NSURL *downloadedBundleFileURL)
{
- if (downloadedBundleFileURL != nil &&
+ if (downloadedBundleFileURL != nil && [downloadedBundleFileURL isFileURL] &&
[[NSFileManager defaultManager] fileExistsAtPath:downloadedBundleFileURL.path]) {
- return loadScriptFromFile(downloadedBundleFileURL);
+ try {
+ return loadScriptFromFile(downloadedBundleFileURL);
+ } catch (const std::runtime_error &error) {
+ NSLog(@"[Worklets] Ignoring cached bundle %@: %s", downloadedBundleFileURL.path, error.what());
+ }
}
return downloadScript(url);
}Also applies to: 129-129
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/react-native-worklets/apple/worklets/apple/ScriptLoader.mm` around
lines 110 - 119, Update loadRemoteScript to require a valid
downloadedBundleFileURL, attempt loadScriptFromFile directly, and catch read
failures so downloadScript(url) is used when the cached bundle cannot be read.
Preserve the existing remote-download behavior when no cached URL is provided.
Summary
do not merge
do not review
this PR waits until react/react-native#57751 hits mainstream
Test plan
do not test