expo-modules-core 58.0.30 → 58.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/ExpoModulesCore.podspec +6 -8
  3. package/android/build.gradle +3 -3
  4. package/android/prebuilt/metadata.json +1 -1
  5. package/android/prebuilt/native-libs.tar.xz +0 -0
  6. package/android/src/main/java/expo/modules/adapters/react/apploader/RNHeadlessAppLoader.kt +2 -3
  7. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +4 -2
  8. package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +6 -2
  9. package/android/src/main/java/expo/modules/v2/AppExpoContext.kt +35 -0
  10. package/android/src/main/java/expo/modules/v2/ExpoModulesV2Host.kt +31 -14
  11. package/expo-module-gradle-plugin/build.gradle.kts +1 -1
  12. package/ios/Core/AppContext.swift +46 -4
  13. package/ios/Core/Arguments/Convertibles.swift +1 -24
  14. package/ios/Core/Coding/JavaScriptCodable+Color.swift +887 -0
  15. package/ios/Core/Coding/JavaScriptCodable+URL.swift +55 -0
  16. package/ios/Core/Convertibles/Convertibles+Color.swift +10 -686
  17. package/ios/Core/Events/EventEmitter.swift +194 -1
  18. package/ios/Core/ExpoModulesMacros.swift +32 -1
  19. package/ios/Core/ExpoPackage.swift +29 -0
  20. package/ios/Core/ModulesProvider.swift +19 -0
  21. package/ios/Core/SharedObjects/SharedObjectRegistry.swift +28 -16
  22. package/ios/Core/Views/SwiftUI/Convertibles+SwiftUI.swift +2 -67
  23. package/ios/Core/Views/SwiftUI/SwiftUIHostingView.swift +5 -1
  24. package/ios/Core/Views/SwiftUI/SwiftUIViewHost.swift +100 -39
  25. package/ios/Core/Views/SwiftUI/SwiftUIVirtualView.swift +1 -0
  26. package/package.json +3 -3
  27. package/prebuilds/output/debug/xcframeworks/ExpoModulesCore.tar.gz +0 -0
  28. package/prebuilds/output/debug/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
  29. package/prebuilds/output/headers/xcframeworks/ExpoModulesCoreHeaders.tar.gz +0 -0
  30. package/prebuilds/output/headers/xcframeworks/ExpoModulesWorkletsHeaders.tar.gz +0 -0
  31. package/prebuilds/output/release/xcframeworks/ExpoModulesCore.tar.gz +0 -0
  32. package/prebuilds/output/release/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
  33. package/spm.config.json +5 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 58.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [iOS] Ship an `ExpoModulesWorkletsHeaders.xcframework` with the iOS prebuilds. A module built from its checked-in Package.swift can depend on the `ExpoModulesWorkletsHeaders` product to compile against `ExpoModulesWorklets`. ([#53322](https://github.com/expo/expo/pull/53322) by [@chrfalch](https://github.com/chrfalch))
8
+ - [Android] Add the `legacyAppContext` and `legacyAppContextOrNull` extensions, which give an Expo Modules API 2.0 module or shared object the `AppContext` of the app. ([#53860](https://github.com/expo/expo/pull/53860) by [@lukmccall](https://github.com/lukmccall))
9
+
10
+ ### Patch Changes
11
+
12
+ - [Android] Fixed a race in `SharedObjectRegistry` where a live shared object passed to an async function could be reported as already released (`UsingReleasedSharedObjectException`) while another thread added or released a shared object. ([#50939](https://github.com/expo/expo/pull/50939) by [@edwardsmatt](https://github.com/edwardsmatt))
13
+ - [iOS] Fix a crash when several concurrent functions read `appContext.fileSystem` or `appContext.permissions` for the first time at once, such as parallel `openDatabaseAsync` calls in `expo-sqlite`. ([#54321](https://github.com/expo/expo/pull/54321) by [@intergalacticspacehighway](https://github.com/intergalacticspacehighway))
14
+ - [iOS] Fixed SwiftUI views (such as `@expo/ui`'s `Host`) rendering nothing when mounted outside any view controller, for example inside react-native-screens' `FullWindowOverlay`. ([#50966](https://github.com/expo/expo/pull/50966) by [@finn-pleo](https://github.com/finn-pleo))
15
+ - Updated dependencies. ([#54091](https://github.com/expo/expo/pull/54091))
16
+ - expo-modules-jsi@58.0.24
17
+
18
+ ## 58.1.0
19
+
20
+ ### Minor Changes
21
+
22
+ - [iOS] Add `JavaScriptDecodable` and `JavaScriptEncodable` conformances to `URL`, `UIColor`, `CGColor` and SwiftUI `Color`, so the Expo Modules API 2.0 macros accept them as arguments, return values, record fields and event payloads. ([#53085](https://github.com/expo/expo/pull/53085) by [@tsapeta](https://github.com/tsapeta))
23
+
24
+ ### Patch Changes
25
+
26
+ - [iOS] Add the `.inline` and `.blocking` options of `@Event` and the `emitInline` and `emitBlocking` methods of `EventEmitter` that they use. With `.inline`, the listeners run before the call returns when it is made on the JavaScript thread. With `.blocking`, they run before the call returns on any thread. ([#52712](https://github.com/expo/expo/pull/52712) by [@tsapeta](https://github.com/tsapeta))
27
+ - [iOS] Update `expo-modules-macros` to 0.31.0. `@ExpoModule` and `@SharedObject` warn when the class isn't `public`, and `@Event` takes the `.inline` and `.blocking` options. ([#52712](https://github.com/expo/expo/pull/52712) by [@tsapeta](https://github.com/tsapeta))
28
+ - [iOS] Update `expo-modules-macros` to 0.33.0. The `ExpoModulesMacrosPlugin` Swift package product no longer breaks iOS builds in Xcode. The macros report more mistakes as build errors: generic, `static` or misplaced `@JS` members, reserved JavaScript names, a `@SharedObject` class without a superclass, and invalid `@Record`, `@Event` and `@Union` declarations. A parenthesized optional type is treated as optional. ([#53026](https://github.com/expo/expo/pull/53026) by [@chrfalch](https://github.com/chrfalch))
29
+ - [iOS] Define `REACT_NATIVE_TARGET_VERSION` in the precompiled `ExpoModulesCore`, so it sends view size updates with `unstable_Immediate` and keeps the size-commit budget, like a source build. ([#52924](https://github.com/expo/expo/pull/52924) by [@intergalacticspacehighway](https://github.com/intergalacticspacehighway))
30
+ - On iOS, generated modules providers also list the modules declared with `@ExpoModule` (Expo Modules API 2.0) by npm package, as an `ExpoPackage` for each package, in the new `packages` property. Local modules and inline modules declared with `@ExpoModule` are in the `$local` package. The property is generated only when the installed `expo-modules-core` supports it. Module registration doesn't change: all modules stay in `getModuleClasses()`. ([#52647](https://github.com/expo/expo/pull/52647) by [@tsapeta](https://github.com/tsapeta))
31
+ - [Android] Fix `RNHeadlessAppLoader.isRunning` reporting an app as headless after an Activity took over its React host, for example when a background task event arrived during a cold start. `expo-task-manager` then skipped forwarding `onHostResume`, `onHostPause` and `onHostDestroy` to task consumers such as `expo-location`'s, which kept reporting locations as if the app were in the foreground or background. ([#51184](https://github.com/expo/expo/pull/51184) by [@retu2libc](https://github.com/retu2libc))
32
+ - [iOS] Fix app contexts that own their runtime, such as the ones in unit tests, never being deallocated. ([#53094](https://github.com/expo/expo/pull/53094) by [@tsapeta](https://github.com/tsapeta))
33
+ - [iOS] Declare the `ExpoModulesCore` source attributes unconditionally, so autolinking patches the prebuilt `ExpoModulesCore` like other precompiled modules. ([#50207](https://github.com/expo/expo/pull/50207) by [@cristunaranjo](https://github.com/cristunaranjo))
34
+ - [iOS] Fix React Native content in a SwiftUI `List` row going blank. When SwiftUI builds more than one instance of a row, the instance it displays now holds the hosted view. ([#52910](https://github.com/expo/expo/pull/52910) by [@intergalacticspacehighway](https://github.com/intergalacticspacehighway))
35
+ - Updated dependencies. ([#53050](https://github.com/expo/expo/pull/53050))
36
+ - expo-modules-jsi@58.0.23
37
+
3
38
  ## 58.0.30
4
39
 
5
40
  ### Patch Changes
@@ -115,14 +115,12 @@ Pod::Spec.new do |s|
115
115
 
116
116
  install_modules_dependencies(s)
117
117
 
118
- if (!Expo::PackagesConfig.instance.try_link_with_prebuilt_xcframework(s))
119
- s.static_framework = true
120
- s.header_dir = 'ExpoModulesCore'
121
- s.source_files = 'ios/**/*.{h,m,mm,swift,cpp}', 'common/cpp/**/*.{h,cpp}'
122
- s.exclude_files = ['ios/Tests', 'ios/Benchmarks', 'ios/Worklets', 'ios/WorkletsTests', 'ios/WorkletsAdapter']
123
- s.compiler_flags = compiler_flags
124
- s.private_header_files = ['ios/**/*+Private.h', 'ios/**/Swift.h']
125
- end
118
+ s.static_framework = true
119
+ s.header_dir = 'ExpoModulesCore'
120
+ s.source_files = 'ios/**/*.{h,m,mm,swift,cpp}', 'common/cpp/**/*.{h,cpp}'
121
+ s.exclude_files = ['ios/Tests', 'ios/Benchmarks', 'ios/Worklets', 'ios/WorkletsTests', 'ios/WorkletsAdapter']
122
+ s.compiler_flags = compiler_flags
123
+ s.private_header_files = ['ios/**/*+Private.h', 'ios/**/Swift.h']
126
124
 
127
125
  s.test_spec 'Tests' do |test_spec|
128
126
  test_spec.dependency 'ExpoModulesTestCore'
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
46
46
  }
47
47
 
48
48
  group = 'host.exp.exponent'
49
- version = '58.0.30'
49
+ version = '58.2.0'
50
50
 
51
51
  def isExpoModulesCoreTests = {
52
52
  Gradle gradle = getGradle()
@@ -97,7 +97,7 @@ if (workletsProject != null) {
97
97
 
98
98
  def reactNativeWorkletsRootDir = workletsProject?.projectDir?.parentFile
99
99
 
100
- def expoModulesV2Version = "0.2.7"
100
+ def expoModulesV2Version = "0.3.0"
101
101
 
102
102
  configurations {
103
103
  // Artifact-only: the C++ sources, not something to put on any classpath.
@@ -175,7 +175,7 @@ android {
175
175
  defaultConfig {
176
176
  consumerProguardFiles 'proguard-rules.pro'
177
177
  versionCode 1
178
- versionName "58.0.30"
178
+ versionName "58.2.0"
179
179
  buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
180
180
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
181
181
 
@@ -16,5 +16,5 @@
16
16
  "libexpo-modules-jsi.so"
17
17
  ],
18
18
  "stripped": true,
19
- "createdAt": "2026-11-03T15:13:40.407447Z"
19
+ "createdAt": "2026-11-26T16:09:04.450893554Z"
20
20
  }
Binary file
@@ -74,9 +74,8 @@ class RNHeadlessAppLoader @DoNotStrip constructor() : HeadlessAppLoader {
74
74
  }
75
75
 
76
76
  override fun isRunning(appScopeKey: String?): Boolean {
77
- // New architecture - We can return true since the fact that we have a reactContext
78
- // means that we've already called start on the reactHost
79
- return appRecords[appScopeKey] != null
77
+ val reactContext = appRecords[appScopeKey] ?: return false
78
+ return !reactContext.hasCurrentActivity()
80
79
  }
81
80
  //endregion HeadlessAppLoader
82
81
  }
@@ -100,6 +100,8 @@ class AppContext(
100
100
 
101
101
  val services = ServicesRegistry(this.weak())
102
102
 
103
+ private val expoModulesV2Host = ExpoModulesV2Host()
104
+
103
105
  internal var legacyModulesProxyHolder: WeakReference<NativeModulesProxy>? = null
104
106
 
105
107
  private val activityResultsManager = ActivityResultsManager(this)
@@ -154,7 +156,7 @@ class AppContext(
154
156
  */
155
157
  fun installJSIInterop() {
156
158
  runtime.install()
157
- runtime.reactContext?.let(ExpoModulesV2Host::install)
159
+ runtime.reactContext?.let { expoModulesV2Host.install(this, it) }
158
160
  }
159
161
 
160
162
  /**
@@ -286,7 +288,7 @@ class AppContext(
286
288
  mainQueue.cancel(ContextDestroyedException())
287
289
  backgroundCoroutineScope.cancel(ContextDestroyedException())
288
290
 
289
- ExpoModulesV2Host.uninstall()
291
+ expoModulesV2Host.uninstall()
290
292
 
291
293
  runtime.deallocate()
292
294
  if (uiRuntimeHolder.isInitialized()) {
@@ -108,7 +108,9 @@ class SharedObjectRegistry(runtime: Runtime) {
108
108
  }
109
109
 
110
110
  internal fun toNativeObject(id: SharedObjectId): SharedObject {
111
- val native = pairs[id.ensureWasNotRelease()]?.first
111
+ val native = synchronized(this) {
112
+ pairs[id.ensureWasNotRelease()]?.first
113
+ }
112
114
  return native ?: throw InvalidSharedObjectIdException()
113
115
  }
114
116
 
@@ -124,7 +126,9 @@ class SharedObjectRegistry(runtime: Runtime) {
124
126
  }
125
127
 
126
128
  val id = SharedObjectId(js.getProperty(sharedObjectIdPropertyName).getInt())
127
- return pairs[id]?.first
129
+ return synchronized(this) {
130
+ pairs[id]?.first
131
+ }
128
132
  }
129
133
 
130
134
  internal fun toJavaScriptObjectOrNull(native: SharedObject): JavaScriptObject? {
@@ -0,0 +1,35 @@
1
+ package expo.modules.v2
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import expo.modules.kotlin.AppContext
5
+ import expo.modules.kotlin.exception.Exceptions
6
+ import io.github.expo.modules.v2.ExpoObject
7
+ import io.github.expo.modules.v2.react.ReactExpoContext
8
+ import java.lang.ref.WeakReference
9
+
10
+ internal class AppExpoContext(
11
+ appContext: AppContext,
12
+ reactContext: ReactApplicationContext
13
+ ) : ReactExpoContext(reactContext) {
14
+ private val appContextHolder = WeakReference(appContext)
15
+
16
+ val appContext: AppContext?
17
+ get() = appContextHolder.get()
18
+ }
19
+
20
+ /**
21
+ * The [AppContext] of the app this module or shared object belongs to. Throws when the object has
22
+ * no context yet, when that context is closed, or when it was not created by `expo-modules-core`.
23
+ */
24
+ val ExpoObject.legacyAppContext: AppContext
25
+ get() {
26
+ val context = context
27
+ check(context is AppExpoContext) {
28
+ "${javaClass.name} belongs to a ${context.javaClass.name}, which has no AppContext"
29
+ }
30
+ return context.appContext ?: throw Exceptions.AppContextLost()
31
+ }
32
+
33
+ /** Like [legacyAppContext], but null instead of throwing. */
34
+ val ExpoObject.legacyAppContextOrNull: AppContext?
35
+ get() = (contextOrNull as? AppExpoContext)?.appContext
@@ -1,18 +1,17 @@
1
1
  package expo.modules.v2
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
+ import expo.modules.kotlin.AppContext
4
5
  import expo.modules.kotlin.logger
5
6
  import io.github.expo.modules.v2.Module
6
7
  import io.github.expo.modules.v2.react.ExpoModulesV2React
7
8
  import io.github.expo.modules.v2.react.ReactRuntime
8
9
  import java.lang.reflect.Modifier
9
10
 
10
- object ExpoModulesV2Host {
11
- private const val GENERATED_PROVIDER_CLASS = "expo.modules.ExpoModulesV2ModuleList"
12
-
11
+ class ExpoModulesV2Host {
13
12
  private var runtime: ReactRuntime? = null
14
13
 
15
- fun install(reactContext: ReactApplicationContext) =
14
+ fun install(appContext: AppContext, reactContext: ReactApplicationContext) =
16
15
  synchronized(this) {
17
16
  if (runtime != null) {
18
17
  logger.warn("⚠️ Expo Modules v2 was already installed")
@@ -34,27 +33,41 @@ object ExpoModulesV2Host {
34
33
  // Must run before `ReactRuntime` initializes. Its superclass, kolibri's `NativeObject`,
35
34
  // otherwise loads the native library under kolibri's default name, which does not exist.
36
35
  ExpoModulesV2React.ensureLoaded()
37
- // The runtime creates a context of its own, and serves the modules of that context.
38
- val attached = ReactRuntime.attach(reactContext)
39
- try {
40
- modules.forEach(attached.moduleRegistry::register)
41
- } catch (e: Throwable) {
42
- // Closing the runtime closes its context, so no module stays bound to it.
43
- attached.close()
44
- throw e
36
+ // The runtime does not own this context, so `close` below closes it too.
37
+ val context = AppExpoContext(appContext, reactContext)
38
+ val attached = ReactRuntime.attach(reactContext, context = context)
39
+ val registered = modules.count { module -> register(attached, module) }
40
+ if (registered == 0) {
41
+ close(attached)
42
+ return
45
43
  }
46
44
  runtime = attached
47
- logger.info("✅ Expo Modules v2 installed ${modules.size} module(s) on globalThis.expo.modules")
45
+ logger.info("✅ Expo Modules v2 installed $registered module(s) on globalThis.expo.modules")
48
46
  } catch (e: Throwable) {
49
47
  logger.error("❌ Cannot install Expo Modules v2: $e", e)
50
48
  }
51
49
  }
52
50
 
53
51
  fun uninstall() = synchronized(this) {
54
- runtime?.close()
52
+ runtime?.let(::close)
55
53
  runtime = null
56
54
  }
57
55
 
56
+ private fun register(runtime: ReactRuntime, module: Module): Boolean =
57
+ try {
58
+ runtime.moduleRegistry.register(module)
59
+ true
60
+ } catch (e: Throwable) {
61
+ logger.error("❌ Cannot register the Expo Modules v2 module ${module.javaClass.name}: $e", e)
62
+ false
63
+ }
64
+
65
+ private fun close(runtime: ReactRuntime) {
66
+ // The same order as a runtime that owns its context: the context first, then the runtime.
67
+ runtime.context.close()
68
+ runtime.close()
69
+ }
70
+
58
71
  private fun autolinkedModules(): List<Module> {
59
72
  val provider = try {
60
73
  Class.forName(GENERATED_PROVIDER_CLASS)
@@ -78,4 +91,8 @@ object ExpoModulesV2Host {
78
91
 
79
92
  return moduleClass.getDeclaredConstructor().apply { isAccessible = true }.newInstance()
80
93
  }
94
+
95
+ private companion object {
96
+ const val GENERATED_PROVIDER_CLASS = "expo.modules.ExpoModulesV2ModuleList"
97
+ }
81
98
  }
@@ -33,7 +33,7 @@ dependencies {
33
33
  implementation("com.facebook.react:react-native-gradle-plugin")
34
34
  implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
35
35
  implementation("io.github.expo.pika:pika-gradle:1.1.0")
36
- implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.2.7")
36
+ implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.3.0")
37
37
 
38
38
  if (isExpoAutolinkingSettingsPluginAvailable) {
39
39
  implementation("expo.modules:expo-autolinking-plugin-shared")
@@ -10,6 +10,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
10
10
  internal static func create() -> AppContext {
11
11
  let appContext = AppContext()
12
12
 
13
+ appContext.ownsRuntime = true
13
14
  appContext._runtime = ExpoRuntime()
14
15
  return appContext
15
16
  }
@@ -60,6 +61,18 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
60
61
  */
61
62
  private var hostWrapper: ExpoHostWrapper?
62
63
 
64
+ /**
65
+ Whether the app context owns its runtime, as the one from `create()` and `TestAppContext` do,
66
+ rather than React Native. The `global.expo` native state then doesn't pin the app context (see
67
+ ``NativeState``): nothing else tears that runtime down, so the pin would be a cycle that keeps
68
+ both alive forever. Set it before the runtime.
69
+ */
70
+ internal var ownsRuntime = false {
71
+ willSet {
72
+ assert(_runtime == nil, "Set ownsRuntime before the runtime: the global.expo native state reads it only once")
73
+ }
74
+ }
75
+
63
76
  /**
64
77
  Underlying JSI runtime of the running app.
65
78
  */
@@ -259,17 +272,32 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
259
272
  */
260
273
  public lazy var constants: EXConstantsInterface? = ConstantsProvider.shared
261
274
 
275
+ // Created on first access, like a `lazy var`, but under a lock: concurrent functions can read it on several threads at once.
276
+ private let fileSystemStorage = Mutex<FileSystemManager?>(nil)
277
+
262
278
  /**
263
279
  Provides access to the file system utilities. Can be overridden if the app should use different directories or file permissions.
264
280
  For instance, Expo Go uses sandboxed environment per project where the cache and document directories must be scoped.
265
281
  It's an optional type for historical reasons, for now let's keep it like this for backwards compatibility.
266
282
  */
267
- public lazy var fileSystem: FileSystemManager? = FileSystemManager(appGroupSharedDirectories: self.config.appGroupSharedDirectories)
283
+ public var fileSystem: FileSystemManager? {
284
+ get {
285
+ fileSystemStorage.withLock { stored in
286
+ if let stored {
287
+ return stored
288
+ }
289
+ let fileSystem = FileSystemManager(appGroupSharedDirectories: config.appGroupSharedDirectories)
290
+ stored = fileSystem
291
+ return fileSystem
292
+ }
293
+ }
294
+ set { fileSystemStorage.withLock { $0 = newValue } }
295
+ }
268
296
 
269
297
  /**
270
298
  Provides access to the permissions manager.
271
299
  */
272
- public lazy var permissions: EXPermissionsService? = EXPermissionsService()
300
+ public var permissions: EXPermissionsService? = EXPermissionsService()
273
301
 
274
302
  /**
275
303
  Provides access to the image loader from legacy module registry.
@@ -696,8 +724,15 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
696
724
  /// intentional: the cycle is broken only when the runtime is torn down (which frees the
697
725
  /// native state and fires its deallocator), which is exactly what defers the app context's
698
726
  /// release until the runtime is gone. The app context never holds the native state directly.
727
+ ///
728
+ /// An app context that owns its runtime (see ``ownsRuntime``) isn't pinned, as the cycle would
729
+ /// never break. The native state references it weakly and the app context tears the runtime
730
+ /// down in its own `deinit`.
699
731
  internal final class NativeState: JavaScriptNativeState {
700
- internal let appContext: AppContext
732
+ internal weak let appContext: AppContext?
733
+
734
+ /// The strong reference that pins the app context, or `nil` when it isn't pinned.
735
+ private let pinnedAppContext: AppContext?
701
736
 
702
737
  /// Whether releasing this native state should tear the app context down. Set only for the
703
738
  /// main runtime; subordinate runtimes pin the app context and enable recovery without
@@ -706,6 +741,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
706
741
 
707
742
  internal init(appContext: AppContext, ownsLifecycle: Bool) {
708
743
  self.appContext = appContext
744
+ self.pinnedAppContext = appContext.ownsRuntime ? nil : appContext
709
745
  self.ownsLifecycle = ownsLifecycle
710
746
  super.init()
711
747
  setDeallocator { nativeState in
@@ -718,7 +754,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
718
754
  // values. A future cross-runtime sharing path that could drop this state's last JSI slot
719
755
  // while the runtime still runs JavaScript (see `JavaScriptNativeState.acquireShared`)
720
756
  // would need to hop to the JS thread here first.
721
- nativeState.appContext.destroy()
757
+ nativeState.appContext?.destroy()
722
758
  }
723
759
  }
724
760
  }
@@ -742,6 +778,12 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
742
778
  deinit {
743
779
  NotificationCenter.default.removeObserver(self)
744
780
 
781
+ // Nothing pins an app context that owns its runtime, so the runtime outlives it only until its
782
+ // stored properties are released. Release the JavaScript objects before that.
783
+ if ownsRuntime && _runtime != nil {
784
+ destroy()
785
+ }
786
+
745
787
  // Post an event to the registry only if it was already created.
746
788
  // If we let it to lazy-load here, that would crash since the module registry
747
789
  // has a weak reference to the app context which is being deallocated.
@@ -18,24 +18,7 @@ extension URL: Convertible {
18
18
  }
19
19
  throw Conversions.ConvertingException<URL>(value)
20
20
  }
21
-
22
- // First we try to create a URL without extra encoding, as it came.
23
- if let url = convertToUrl(string: value) {
24
- return url
25
- }
26
-
27
- // File path doesn't need to be percent-encoded.
28
- if isFileUrlPath(value) {
29
- return URL(fileURLWithPath: value)
30
- }
31
-
32
- // If we get here, the string is not the file url and may require percent-encoding characters that are not URL-safe according to RFC 3986.
33
- if let encodedValue = percentEncodeUrlString(value), let url = convertToUrl(string: encodedValue) {
34
- return url
35
- }
36
-
37
- // If it still fails to create the URL object, the string possibly contains characters that must be explicitly percent-encoded beforehand.
38
- throw UrlContainsInvalidCharactersException()
21
+ return try urlFromString(value)
39
22
  }
40
23
 
41
24
  public static func convertResult(_ result: Any, appContext: AppContext) throws -> Any {
@@ -46,12 +29,6 @@ extension URL: Convertible {
46
29
  }
47
30
  }
48
31
 
49
- internal class UrlContainsInvalidCharactersException: Exception {
50
- override var reason: String {
51
- return "Unable to create a URL object from the given string, make sure to percent-encode these characters: \(urlAllowedCharacters)"
52
- }
53
- }
54
-
55
32
  // MARK: - CoreGraphics
56
33
 
57
34
  extension CGPoint: Convertible {