expo-modules-core 58.0.23 → 58.0.24

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 58.0.24
4
+
5
+ ### Patch Changes
6
+
7
+ - [iOS] Reduce the overhead of creating shared objects in JavaScript and of returning them from native functions. ([#51730](https://github.com/expo/expo/pull/51730) by [@tsapeta](https://github.com/tsapeta))
8
+ - [iOS] Fix shared objects that native code returns to JavaScript again after their earlier JavaScript object was garbage-collected. Their members could throw "Unable to find the native shared object associated with given JavaScript object", or the returned object could belong to another shared object. ([#51854](https://github.com/expo/expo/pull/51854) by [@tsapeta](https://github.com/tsapeta))
9
+ - [iOS] Update `expo-modules-macros` to 0.22.0. `@Record` types now read and write their JavaScript properties with less overhead. The new `@JS` option `.withAsync("name")` also binds a synchronous function under that name, as a function that returns a promise and runs on the concurrent thread pool. A `@Record` can now be a `final class`, and a class that isn't `final` or has an inheritance clause gets a build error that says how to fix it. A `@JS init` now reports an argument type that can't be converted from JavaScript at the initializer. ([#51905](https://github.com/expo/expo/pull/51905) by [@tsapeta](https://github.com/tsapeta))
10
+ - [iOS] Fix a SwiftUI `Host` that mounts during a repeated modal presentation having no safe area. ([#51923](https://github.com/expo/expo/pull/51923) by [@expo-tuft](https://github.com/apps/expo-tuft))
11
+ - [iOS] Fix hosted React Native content going blank or keeping a stale size after its child view is remounted, for example by a `key` change in an `RNHostView`. ([#51906](https://github.com/expo/expo/pull/51906) by [@expo-tuft](https://github.com/apps/expo-tuft))
12
+ - Updated dependencies. ([#51588](https://github.com/expo/expo/pull/51588), [#51835](https://github.com/expo/expo/pull/51835), [#51905](https://github.com/expo/expo/pull/51905))
13
+ - expo-modules-jsi@58.0.17
14
+
3
15
  ## 58.0.23
4
16
 
5
17
  ### Patch Changes
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
46
46
  }
47
47
 
48
48
  group = 'host.exp.exponent'
49
- version = '58.0.23'
49
+ version = '58.0.24'
50
50
 
51
51
  def isExpoModulesCoreTests = {
52
52
  Gradle gradle = getGradle()
@@ -175,7 +175,7 @@ android {
175
175
  defaultConfig {
176
176
  consumerProguardFiles 'proguard-rules.pro'
177
177
  versionCode 1
178
- versionName "58.0.23"
178
+ versionName "58.0.24"
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-10-19T12:37:31.850362445Z"
19
+ "createdAt": "2026-10-21T17:10:44.785915196Z"
20
20
  }
Binary file
@@ -235,19 +235,14 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
235
235
  /// Perhaps it should be kept by the `ModuleHolder`.
236
236
  internal let classRegistry = ClassRegistry()
237
237
 
238
- /**
239
- Creates a new JavaScript object with the class prototype associated with the given native class.
240
- - ToDo: Move this to `ModuleHolder` along the `classRegistry` property.
241
- */
238
+ /// Creates a new JavaScript object with the class prototype associated with the given native class.
239
+ /// Returns `nil` when no JavaScript class is registered for the native class.
240
+ /// - ToDo: Move this to `ModuleHolder` along the `classRegistry` property.
242
241
  internal func newObject(nativeClassId: ObjectIdentifier) throws -> JavaScriptObject? {
243
242
  let runtime = try self.runtime
244
- let object = classRegistry.withPrototype(nativeClassId: nativeClassId) { (prototype: borrowing JavaScriptObject) in
243
+ return classRegistry.withPrototype(nativeClassId: nativeClassId) { (prototype: borrowing JavaScriptObject) in
245
244
  return runtime.createObject(prototype: prototype)
246
245
  }
247
- guard let object else {
248
- throw JavaScriptClassNotFoundException()
249
- }
250
- return object
251
246
  }
252
247
 
253
248
  // MARK: - Legacy modules
@@ -71,7 +71,7 @@ internal struct DynamicSharedObjectType: AnyDynamicType {
71
71
  if let jsObject = sharedObject.getJavaScriptObject() {
72
72
  return jsObject.asValue()
73
73
  }
74
- guard let jsObject = (try? appContext.newObject(nativeClassId: typeIdentifier)) ?? (try? newBaseSharedObject(appContext, nativeType: innerType)) else {
74
+ guard let jsObject = (try? appContext.newObject(nativeClassId: typeIdentifier)) ?? (try? newBaseSharedObject(appContext, isSharedRef: sharedObject.sharedRefType != nil)) else {
75
75
  // Throwing is not possible here due to swift-objC interop.
76
76
  log.warn("Unable to create a JS object for \(description)")
77
77
  return JavaScriptValue.undefined()
@@ -86,8 +86,7 @@ internal struct DynamicSharedObjectType: AnyDynamicType {
86
86
  }
87
87
  }
88
88
 
89
- private func newBaseSharedObject(_ appContext: AppContext, nativeType: AnySharedObject.Type) throws -> JavaScriptObject? {
90
- let isSharedRef = nativeType is AnySharedRef.Type
89
+ private func newBaseSharedObject(_ appContext: AppContext, isSharedRef: Bool) throws -> JavaScriptObject? {
91
90
  return try JavaScriptActor.assumeIsolated {
92
91
  return try appContext.runtime.createBaseSharedObject(isSharedRef: isSharedRef)
93
92
  }
@@ -36,6 +36,16 @@ public enum JSOptions {
36
36
  /// The call sends the module or shared object off the JavaScript thread, so in Swift 6 language
37
37
  /// mode the enclosing class must be `Sendable`.
38
38
  case concurrent
39
+
40
+ /// Binds a synchronous function a second time under the given JavaScript name, as a function that
41
+ /// returns a promise and runs the body on the concurrent thread pool, for example
42
+ /// `@JS("textSync", .withAsync("text"))`. The body must be safe to run on any thread, since the
43
+ /// variant isn't isolated to the JavaScript thread. Only valid on a synchronous function that isn't
44
+ /// isolated to a global actor, and the name must be a string literal.
45
+ ///
46
+ /// The variant sends the module or shared object off the JavaScript thread, so in Swift 6 language
47
+ /// mode the enclosing class must be `Sendable`.
48
+ case withAsync(String)
39
49
  }
40
50
 
41
51
  /// Marker macro applied to module / shared-object members that should be exposed to JavaScript.
@@ -59,6 +69,9 @@ public enum JSOptions {
59
69
  /// @JS("doWork", .concurrent)
60
70
  /// func performHeavyWork() async throws { ... }
61
71
  ///
72
+ /// @JS("textSync", .withAsync("text"))
73
+ /// func text(path: String) throws -> String { ... }
74
+ ///
62
75
  /// Also emits a never-called `_assertTypesConformance_<member>` peer that statically asserts every
63
76
  /// type crossing the JS boundary conforms to the JS-convertible protocol, so a non-conforming type
64
77
  /// fails to compile on the user's declaration. The peer name embeds the member name, hence
@@ -183,7 +196,7 @@ public macro SharedObject(_ name: String? = nil) =
183
196
  @attached(
184
197
  member,
185
198
  names: named(init), named(from), named(toDictionary), named(toObject), named(decode), named(encode),
186
- named(_assertTypesConformance))
199
+ named(_assertTypesConformance), named(_PropNames))
187
200
  @attached(extension, conformances: Record)
188
201
  public macro Record() =
189
202
  #externalMacro(module: "ExpoModulesMacros", type: "RecordMacro")
@@ -26,14 +26,13 @@ public class ExpoRuntime: JavaScriptRuntime, @unchecked Sendable {
26
26
  /// The prototypes of both classes are looked up once per runtime and cached.
27
27
  @JavaScriptActor
28
28
  internal func createBaseSharedObject(isSharedRef: Bool) throws -> JavaScriptObject {
29
- let key = isSharedRef ? sharedRefPrototypeKey : sharedObjectPrototypeKey
30
- let makePrototype = {
31
- let baseClass = try isSharedRef ? self.getSharedRefClass() : self.getSharedObjectClass()
32
- return try baseClass.asObject().getPropertyAsObject("prototype")
29
+ let prototypes = try cached(baseSharedObjectPrototypesKey) {
30
+ return try BaseSharedObjectPrototypes(in: self)
33
31
  }
34
- return try withCached(key, makePrototype) { (prototype: borrowing JavaScriptObject) in
35
- return createObject(prototype: prototype)
32
+ if isSharedRef {
33
+ return createObject(prototype: prototypes.sharedRef)
36
34
  }
35
+ return createObject(prototype: prototypes.sharedObject)
37
36
  }
38
37
 
39
38
  @JavaScriptActor
@@ -57,6 +56,17 @@ public class ExpoRuntime: JavaScriptRuntime, @unchecked Sendable {
57
56
  }
58
57
  }
59
58
 
60
- /// Keys of the base `SharedObject` and `SharedRef` prototypes in each runtime's cache.
61
- private let sharedObjectPrototypeKey = JavaScriptRuntime.Cache.Key<JavaScriptObject.Ref>()
62
- private let sharedRefPrototypeKey = JavaScriptRuntime.Cache.Key<JavaScriptObject.Ref>()
59
+ /// The prototypes of the base `SharedObject` and `SharedRef` classes.
60
+ private final class BaseSharedObjectPrototypes {
61
+ let sharedObject: JavaScriptObject
62
+ let sharedRef: JavaScriptObject
63
+
64
+ @JavaScriptActor
65
+ init(in runtime: ExpoRuntime) throws {
66
+ sharedObject = try runtime.getSharedObjectClass().asObject().getPropertyAsObject("prototype")
67
+ sharedRef = try runtime.getSharedRefClass().asObject().getPropertyAsObject("prototype")
68
+ }
69
+ }
70
+
71
+ /// Key of the base shared object prototypes in each runtime's cache.
72
+ private let baseSharedObjectPrototypesKey = JavaScriptRuntime.Cache.Key<BaseSharedObjectPrototypes>()
@@ -36,6 +36,12 @@ open class SharedObject: AnySharedObject {
36
36
  */
37
37
  public init() {}
38
38
 
39
+ /// The value of `nativeRefType` on the JavaScript object, or `nil` when the object does not conform to
40
+ /// `AnySharedRef`.
41
+ internal var sharedRefType: String? {
42
+ return (self as? AnySharedRef)?.nativeRefType
43
+ }
44
+
39
45
  /**
40
46
  A function that will be called before the object is removed from the registry.
41
47
  */
@@ -23,7 +23,9 @@ public final class SharedObjectRegistry: Sendable {
23
23
 
24
24
  // `@unchecked` because `SharedObjectNativeState` isn't `Sendable` (its JSI base class isn't), yet a
25
25
  // value escapes `withLock` whenever `get`/the lookups return it. Access is always serialized through
26
- // `state`'s `Mutex` and the callers run on `JavaScriptActor`, so the unchecked assertion is sound.
26
+ // `state`'s `Mutex`. `delete(_:)` can run on the thread that destroys a C++ native state, such as a
27
+ // garbage collector thread, so it and `add` change the native object's ID and native state only under
28
+ // the lock.
27
29
  internal struct State: @unchecked Sendable {
28
30
  /**
29
31
  Maps each shared object id to the native object's `SharedObjectNativeState`, which carries the
@@ -93,23 +95,25 @@ public final class SharedObjectRegistry: Sendable {
93
95
  */
94
96
  @discardableResult
95
97
  internal func add(native nativeObject: SharedObject, javaScript jsObject: borrowing JavaScriptObject) -> SharedObjectId {
96
- // A native object that already carries a native state was paired in an earlier runtime. Reuse its
97
- // id rather than minting a new one: the C++ `NativeState.objectId` is immutable and drives the
98
- // releaser/`delete`, so a fresh id would disagree with it and leak this object's registry entry.
99
- let existingNativeState = unreleasedNativeState(of: nativeObject)
98
+ // Reuse the native state, and with it the ID, only while a live JS object in this runtime holds it.
99
+ // That JS object keeps the C++ native state alive until `setNativeState` attaches it to `jsObject`.
100
+ // Otherwise the C++ native state can be in destruction on another thread, and its release must not
101
+ // apply to `jsObject`, so the native object gets a new native state and ID.
102
+ let pairedObject = pairedObjectHoldingNativeState(of: nativeObject)
103
+ let existingNativeState = pairedObject != nil ? nativeObject.nativeState : nil
100
104
  let id = existingNativeState != nil ? nativeObject.sharedObjectId : pullNextId()
101
105
 
102
- // Assign the ID and the app context to the object.
103
- nativeObject.sharedObjectId = id
106
+ // Assign the app context to the object.
104
107
  nativeObject.appContext = appContext
105
108
 
106
109
  // This property should be deprecated, but it's still used when passing as a view prop.
107
110
  // It's already defined in the JS base SharedObject class prototype,
108
111
  // but with the current implementation it's possible to use a raw object for registration.
109
- jsObject.defineProperty(sharedObjectIdPropertyName, value: id, options: [.writable])
112
+ // No option set literals here: they build the set through a generic initializer on every call.
113
+ jsObject.defineProperty(sharedObjectIdPropertyName, value: id, options: .writable)
110
114
 
111
- if let sharedRef = nativeObject as? AnySharedRef {
112
- jsObject.defineProperty("nativeRefType", value: sharedRef.nativeRefType, options: [])
115
+ if let sharedRefType = nativeObject.sharedRefType {
116
+ jsObject.defineProperty("nativeRefType", value: sharedRefType, options: JavaScriptObject.PropertyOptions())
113
117
  }
114
118
 
115
119
  let memoryPressure = nativeObject.getAdditionalMemoryPressure()
@@ -120,11 +124,6 @@ public final class SharedObjectRegistry: Sendable {
120
124
  // Attach the C++ shared-object native state. Because `expo::SharedObject::NativeState`
121
125
  // inherits from `expo::EventEmitter::NativeState`, later `addListener` calls see an
122
126
  // existing native state (via the inheritance check) and don't overwrite it.
123
- //
124
- // A native object may already carry a native state from a previous pairing in another runtime.
125
- // Reuse it so all runtimes share one native state (and one underlying C++ pointee, via
126
- // `acquireShared`); a fresh state per runtime would leave `nativeObject.nativeState` pointing at
127
- // whichever ran last and lose the earlier runtimes' pairings.
128
127
  let nativeState = existingNativeState ?? {
129
128
  let releaser: ObjectReleaser = { [weak self] id in
130
129
  self?.delete(id)
@@ -137,21 +136,24 @@ public final class SharedObjectRegistry: Sendable {
137
136
  contextDeallocator: deallocator
138
137
  )
139
138
  }
140
- nativeObject.nativeState = state
141
139
  return state
142
140
  }()
143
141
 
144
- // Index the native state by id. One entry per native object: re-pairing in another runtime stores
145
- // the same state under the same id (idempotent); the per-runtime JS counterparts live on the state.
142
+ // Index the native state by ID. `delete(_:)` reads the native object's ID and native state on any
143
+ // thread, so they change under the same lock.
146
144
  state.withLock { state in
147
145
  state.pairs[id] = nativeState
146
+ nativeObject.sharedObjectId = id
147
+ nativeObject.nativeState = nativeState
148
148
  }
149
149
 
150
150
  // setNativeState calls acquireShared() synchronously, which retains `nativeState`
151
151
  // via Unmanaged.passRetained. That's the wrapper's only strong reference — once
152
152
  // the C++ pointee dies, the contextDeallocator releases it. Reattaching the same
153
153
  // native state to another runtime's JS object reuses that same C++ pointee.
154
- jsObject.setNativeState(nativeState)
154
+ withExtendedLifetime(pairedObject) {
155
+ jsObject.setNativeState(nativeState)
156
+ }
155
157
 
156
158
  // The registry is scoped to its app context, so the JS object being paired here lives in that
157
159
  // context's runtime. Record the pairing under that runtime so the native object can recover this
@@ -171,12 +173,18 @@ public final class SharedObjectRegistry: Sendable {
171
173
  if let nativeState = state.pairs[id] {
172
174
  let native = nativeState.native
173
175
  nativeState.markReleased()
174
- native.sharedObjectWillRelease()
175
- // Reset an ID on the object.
176
- native.sharedObjectId = 0
177
176
 
178
177
  // Delete the entry from the dictionary.
179
178
  state.pairs[id] = nil
179
+
180
+ // A native object that was paired again after its JS object died has a new native state and ID,
181
+ // and stays paired.
182
+ guard native.nativeState === nativeState else {
183
+ return
184
+ }
185
+ native.sharedObjectWillRelease()
186
+ // Reset an ID on the object.
187
+ native.sharedObjectId = 0
180
188
  native.sharedObjectDidRelease()
181
189
  }
182
190
  }
@@ -229,13 +237,7 @@ public final class SharedObjectRegistry: Sendable {
229
237
  guard let runtime = try? appContext?.runtime else {
230
238
  return nil
231
239
  }
232
- // The id table and the native object both resolve to the same `SharedObjectNativeState`, which
233
- // owns the per-runtime JS counterparts, so a single lookup serves both. Prefer the native object's
234
- // own back-pointer and fall back to the id table for objects whose back-pointer was cleared.
235
- let nativeState = unreleasedNativeState(of: nativeObject) ?? state.withLock { state in
236
- return state.pairs[nativeObject.sharedObjectId]
237
- }
238
- return nativeState?.javaScriptObject(in: runtime)
240
+ return unreleasedNativeState(of: nativeObject)?.javaScriptObject(in: runtime)
239
241
  }
240
242
 
241
243
  /// Returns the native object's native state, or `nil` if it was released. A released native state can
@@ -247,6 +249,19 @@ public final class SharedObjectRegistry: Sendable {
247
249
  return nativeState
248
250
  }
249
251
 
252
+ /// Returns the JS object paired with the native object in this registry's runtime, if it is alive and
253
+ /// still holds the native object's native state.
254
+ private func pairedObjectHoldingNativeState(of nativeObject: SharedObject) -> JavaScriptObject? {
255
+ guard let runtime = try? appContext?.runtime,
256
+ let nativeState = unreleasedNativeState(of: nativeObject),
257
+ let pairedObject = nativeState.javaScriptObject(in: runtime),
258
+ pairedObject.getNativeState(as: SharedObjectNativeState.self) === nativeState
259
+ else {
260
+ return nil
261
+ }
262
+ return pairedObject
263
+ }
264
+
250
265
  /**
251
266
  Creates a plain JS object and pairs it with a given native object.
252
267
  */
@@ -16,6 +16,10 @@ open class SharedRef<RefType>: SharedObject, AnySharedRef {
16
16
  "unknown"
17
17
  }
18
18
 
19
+ internal override var sharedRefType: String? {
20
+ return nativeRefType
21
+ }
22
+
19
23
  @available(*, deprecated, renamed: "ref", message: "it has been renamed to 'ref' in Expo SDK 52")
20
24
  public var pointer: RefType {
21
25
  return ref
@@ -67,7 +67,11 @@ extension ExpoSwiftUI {
67
67
  self.contentView = ContentView(props: props)
68
68
  let rootView = AnyView(contentView)
69
69
  self.props = props
70
+ #if os(iOS) || os(tvOS)
71
+ let controller: UIHostingController<AnyView> = AppearanceTrackingHostingController(rootView: rootView)
72
+ #else
70
73
  let controller = UIHostingController(rootView: rootView)
74
+ #endif
71
75
 
72
76
  if #available(iOS 16.0, tvOS 16.0, macOS 13.0, *) {
73
77
  controller.sizingOptions = [.intrinsicContentSize]
@@ -259,10 +263,27 @@ extension ExpoSwiftUI {
259
263
  addSubview(hostingController.view)
260
264
  #if os(iOS) || os(tvOS)
261
265
  hostingController.didMove(toParent: parentController)
266
+ forwardAppearanceIfMissed(parentController: parentController)
262
267
  #endif
263
268
  setupHostingViewConstraints()
264
269
  }
265
270
 
271
+ #if os(iOS) || os(tvOS)
272
+ // A child added during a transition after its parent appeared never appears, so it gets no safe area (#51288).
273
+ // TODO: Workaround for https://github.com/software-mansion/react-native-screens/pull/4997, remove once it ships.
274
+ private func forwardAppearanceIfMissed(parentController: UIViewController) {
275
+ guard
276
+ parentController.transitionCoordinator != nil,
277
+ let controller = hostingController as? AppearanceTrackingHostingController,
278
+ !controller.isAppearing
279
+ else {
280
+ return
281
+ }
282
+ controller.beginAppearanceTransition(true, animated: false)
283
+ controller.endAppearanceTransition()
284
+ }
285
+ #endif
286
+
266
287
  #if os(macOS)
267
288
  public override func reactViewController() -> NSViewController? {
268
289
  var currentView: NSView? = self
@@ -278,6 +299,23 @@ extension ExpoSwiftUI {
278
299
  }
279
300
  }
280
301
 
302
+ #if os(iOS) || os(tvOS)
303
+ // Records whether UIKit forwarded appearance, so `HostingView` can forward it when UIKit misses it.
304
+ private final class AppearanceTrackingHostingController: UIHostingController<AnyView> {
305
+ private(set) var isAppearing = false
306
+
307
+ override func viewWillAppear(_ animated: Bool) {
308
+ super.viewWillAppear(animated)
309
+ isAppearing = true
310
+ }
311
+
312
+ override func viewDidDisappear(_ animated: Bool) {
313
+ super.viewDidDisappear(animated)
314
+ isAppearing = false
315
+ }
316
+ }
317
+ #endif
318
+
281
319
  extension UIHostingController {
282
320
  /// Applies the `ignoreSafeArea` mode reactively, restoring the default safe area when `nil` so
283
321
  /// clearing the prop re-enables the safe area without an app reload.
@@ -8,6 +8,8 @@ extension ExpoSwiftUI {
8
8
  */
9
9
  struct UIViewHost: UIViewRepresentable, AnyChild {
10
10
  let view: UIView
11
+ // Fabric can mount a recycled view again; a new identity per mount gives it a new container.
12
+ private let mountToken = MountToken()
11
13
 
12
14
  // MARK: - UIViewRepresentable implementations
13
15
 
@@ -64,8 +66,14 @@ extension ExpoSwiftUI {
64
66
  var uiView: UIView? {
65
67
  view
66
68
  }
69
+
70
+ var childIdentity: ExpoSwiftUI.ChildIdentity {
71
+ .object(ObjectIdentifier(mountToken))
72
+ }
67
73
  }
68
74
 
75
+ private final class MountToken {}
76
+
69
77
  #if !os(macOS)
70
78
  /**
71
79
  Disposable UIView handed to SwiftUI in place of the React-managed view —
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "58.0.23",
3
+ "version": "58.0.24",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "keywords": [
6
6
  "expo",
@@ -66,12 +66,12 @@
66
66
  "./package.json": "./package.json"
67
67
  },
68
68
  "dependencies": {
69
- "expo-modules-jsi": "~58.0.16",
70
- "expo-modules-macros": "0.21.0",
69
+ "expo-modules-jsi": "~58.0.17",
70
+ "expo-modules-macros": "0.22.0",
71
71
  "invariant": "^2.2.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@expo/internal-scripts": "58.0.3",
74
+ "@expo/internal-scripts": "58.0.4",
75
75
  "@testing-library/react-native": "^14.0.1",
76
76
  "@types/invariant": "^2.2.33",
77
77
  "@types/react": "~19.3.0",