Skip to content

feat(Worklets): read iOS dev bundle from file - #10181

Draft
tjzel wants to merge 1 commit into
mainfrom
@tjzel/worklets/ios-bundle-from-file
Draft

feat(Worklets): read iOS dev bundle from file#10181
tjzel wants to merge 1 commit into
mainfrom
@tjzel/worklets/ios-bundle-from-file

Conversation

@tjzel

@tjzel tjzel commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

do not merge
do not review

this PR waits until react/react-native#57751 hits mainstream

Test plan

do not test

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved loading of remote scripts on Apple platforms by using an existing downloaded bundle when available.
    • Preserved direct loading behavior for local script files.
  • Maintenance

    • Updated example apps and development tooling to use the patched React Native release consistently.
    • Updated the macOS and tvOS examples to align with the patched React Native version.
    • Reordered privacy API declarations without changing their contents.

Walkthrough

React 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.

Changes

React Native patch and bundle loading

Layer / File(s) Summary
Patched React Native references
apps/*/package.json, docs/*/package.json, package.json, packages/*/package.json, apps/fabric-example/ios/PrivacyInfo.xcprivacy
React Native references now target patched 0.87.0-rc.4 packages. The Fabric privacy declarations were reordered without changing their values.
Apple cached bundle loading
packages/react-native-worklets/apple/worklets/apple/ScriptLoader.h, packages/react-native-worklets/apple/worklets/apple/ScriptLoader.mm, packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm
getScript accepts a downloaded bundle URL. Remote script loading uses the cached bundle when its URL and path are valid, and otherwise downloads the script. Bundle-mode installation passes the cached URL.

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
Loading

Possibly related PRs

Suggested reviewers: tomekzaw

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main Worklets change: reading the iOS development bundle from a file.
Description check ✅ Passed The description identifies the Worklets feature and explains its dependency on React Native pull request #57751.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch @tjzel/worklets/ios-bundle-from-file

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d10808b and b450c73.

⛔ Files ignored due to path filters (3)
  • .yarn/patches/react-native-npm-0.87.0-rc.4-5c97bcefe3.patch is excluded by !**/.yarn/**
  • apps/fabric-example/ios/Podfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • apps/common-app/package.json
  • apps/fabric-example/ios/PrivacyInfo.xcprivacy
  • apps/fabric-example/package.json
  • apps/macos-example/package.json
  • apps/next-example/package.json
  • apps/tvos-example/package.json
  • apps/web-example/package.json
  • docs/docs-reanimated/package.json
  • docs/docs-worklets/package.json
  • package.json
  • packages/react-native-reanimated/package.json
  • packages/react-native-worklets/apple/worklets/apple/ScriptLoader.h
  • packages/react-native-worklets/apple/worklets/apple/ScriptLoader.mm
  • packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm
  • packages/react-native-worklets/package.json

Comment on lines +110 to +119
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant