@solidnative-dev/fabric-host 0.0.0-stage → 0.1.0-alpha.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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -2
  3. package/dist/fatal-error-handler.d.ts +27 -0
  4. package/dist/fatal-error-handler.d.ts.map +1 -0
  5. package/dist/fatal-error-handler.js +106 -0
  6. package/dist/fatal-error-handler.js.map +1 -0
  7. package/dist/index.d.ts +7 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +7 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/native-binding.d.ts +183 -0
  12. package/dist/native-binding.d.ts.map +1 -0
  13. package/dist/native-binding.js +554 -0
  14. package/dist/native-binding.js.map +1 -0
  15. package/dist/native-fabric-host.d.ts +32 -0
  16. package/dist/native-fabric-host.d.ts.map +1 -0
  17. package/dist/native-fabric-host.js +275 -0
  18. package/dist/native-fabric-host.js.map +1 -0
  19. package/dist/native-transaction.d.ts +17 -0
  20. package/dist/native-transaction.d.ts.map +1 -0
  21. package/dist/native-transaction.js +124 -0
  22. package/dist/native-transaction.js.map +1 -0
  23. package/dist/react-native-0.87.d.ts +61 -0
  24. package/dist/react-native-0.87.d.ts.map +1 -0
  25. package/dist/react-native-0.87.js +77 -0
  26. package/dist/react-native-0.87.js.map +1 -0
  27. package/dist/react-native-0.88.d.ts +77 -0
  28. package/dist/react-native-0.88.d.ts.map +1 -0
  29. package/dist/react-native-0.88.js +79 -0
  30. package/dist/react-native-0.88.js.map +1 -0
  31. package/dist/surface-readiness.d.ts +18 -0
  32. package/dist/surface-readiness.d.ts.map +1 -0
  33. package/dist/surface-readiness.js +43 -0
  34. package/dist/surface-readiness.js.map +1 -0
  35. package/native/README.md +502 -0
  36. package/native/SolidNativeFabric.podspec +84 -0
  37. package/native/android/SolidNativeBindingsInstaller.cpp +4218 -0
  38. package/native/android/SolidNativeBindingsInstaller.h +8 -0
  39. package/native/android/SolidNativeRuntime.cmake +61 -0
  40. package/native/android/java/dev/solidnative/runtime/SolidNativeBindingsInstaller.kt +239 -0
  41. package/native/android/java/dev/solidnative/runtime/SolidNativeDebugModule.kt +191 -0
  42. package/native/android/java/dev/solidnative/runtime/SolidNativePackage.kt +43 -0
  43. package/native/android/java/dev/solidnative/runtime/SolidNativePlatformModule.kt +81 -0
  44. package/native/android/java/dev/solidnative/runtime/SolidNativeStartupFailureView.kt +93 -0
  45. package/native/android/java/dev/solidnative/runtime/SolidNativeSurface.kt +423 -0
  46. package/native/android/solid-native.gradle +90 -0
  47. package/native/apple/SolidNativeDebugRequest.mm +421 -0
  48. package/native/fabric/SolidNativeDebugRequest.h +12 -0
  49. package/native/fabric/SolidNativeDirtyNodes.h +26 -0
  50. package/native/fabric/SolidNativeFabricApi.cpp +224 -0
  51. package/native/fabric/SolidNativeFabricApi.h +107 -0
  52. package/native/fabric/SolidNativeFabricApplication.h +32 -0
  53. package/native/fabric/SolidNativeFabricApplication.mm +373 -0
  54. package/native/fabric/SolidNativeFabricJSIBinding.h +43 -0
  55. package/native/fabric/SolidNativeFabricJSIBinding.mm +4491 -0
  56. package/native/fabric/SolidNativeFabricSmokeApplication.h +26 -0
  57. package/native/fabric/SolidNativeFabricSmokeApplication.mm +331 -0
  58. package/native/fabric/SolidNativeFabricSurface.h +63 -0
  59. package/native/fabric/SolidNativeFabricSurface.mm +549 -0
  60. package/native/fabric/SolidNativeFabricTransactionCoordinator.cpp +1275 -0
  61. package/native/fabric/SolidNativeFabricTransactionCoordinator.h +90 -0
  62. package/native/fabric/SolidNativeFabricTransactionCoordinatorApple.mm +97 -0
  63. package/native/fabric/SolidNativeRootViewController.h +20 -0
  64. package/native/fabric/SolidNativeRootViewController.mm +83 -0
  65. package/native/fabric/SolidNativeStagedNodeMap.h +104 -0
  66. package/native/fabric/SolidNativeStartupFailureView.h +17 -0
  67. package/native/fabric/SolidNativeStartupFailureView.mm +77 -0
  68. package/native/react-native-boundary.json +106 -0
  69. package/native/worklets/SolidNativeUIWorklet.cpp +1080 -0
  70. package/native/worklets/SolidNativeUIWorklet.h +245 -0
  71. package/package.json +41 -3
  72. package/scripts/verify-react-native-boundary.mjs +282 -0
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+
3
+ #import <UIKit/UIKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ typedef void (^SolidNativeFabricSmokeStatusHandler)(
8
+ NSString *status,
9
+ NSError *_Nullable error);
10
+
11
+ // Owns the disposable React Native host used by the native smoke proof. The
12
+ // factory parameter is intentionally `id` so Swift callers do not need to
13
+ // import React Native's Objective-C++ RCTHost declaration.
14
+ @interface SolidNativeFabricSmokeApplication : NSObject
15
+
16
+ + (instancetype)startWithFactory:(id)factory
17
+ containerView:(UIView *)containerView
18
+ launchOptions:(nullable NSDictionary *)launchOptions
19
+ statusHandler:
20
+ (SolidNativeFabricSmokeStatusHandler)statusHandler;
21
+
22
+ - (void)stop;
23
+
24
+ @end
25
+
26
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,331 @@
1
+ #import "SolidNativeFabricSmokeApplication.h"
2
+
3
+ #import <React/RCTBridge.h>
4
+ #import <React/RCTReactNativeFactory.h>
5
+ #import <React/RCTRootViewFactory.h>
6
+ #import <React/RCTSurfacePresenter.h>
7
+ #import <ReactCommon/RCTHost.h>
8
+ #import <React_RCTAppDelegate/RCTJSRuntimeConfiguratorProtocol.h>
9
+
10
+ #include <react/runtime/JSRuntimeFactoryCAPI.h>
11
+
12
+ #include <stdexcept>
13
+
14
+ #import "SolidNativeFabricJSIBinding.h"
15
+ #import "SolidNativeFabricSurface.h"
16
+
17
+ namespace {
18
+
19
+ constexpr NSInteger MaxHostStartAttempts = 500;
20
+ constexpr int64_t HostStartRetryNanoseconds = 10 * NSEC_PER_MSEC;
21
+ constexpr NSInteger MaxJSICommitAttempts = 500;
22
+ constexpr NSInteger MaxJSIEventCommitAttempts = 3000;
23
+ constexpr int64_t JSICommitRetryNanoseconds = 10 * NSEC_PER_MSEC;
24
+
25
+ NSError *hostStartError(void) {
26
+ return [NSError
27
+ errorWithDomain:@"SolidNativeFabricSmokeApplication"
28
+ code:1
29
+ userInfo:@{
30
+ NSLocalizedDescriptionKey :
31
+ @"The React Native host did not expose its Fabric scheduler within five seconds."
32
+ }];
33
+ }
34
+
35
+ NSError *jsiCommitError(void) {
36
+ return [NSError
37
+ errorWithDomain:@"SolidNativeFabricSmokeApplication"
38
+ code:3
39
+ userInfo:@{
40
+ NSLocalizedDescriptionKey :
41
+ @"The JavaScript bundle did not commit transaction sequence 1 within five seconds."
42
+ }];
43
+ }
44
+
45
+ NSError *jsiEventCommitError(void) {
46
+ return [NSError
47
+ errorWithDomain:@"SolidNativeFabricSmokeApplication"
48
+ code:5
49
+ userInfo:@{
50
+ NSLocalizedDescriptionKey :
51
+ @"The AppState event did not commit transaction sequence 2 within thirty seconds."
52
+ }];
53
+ }
54
+
55
+ } // namespace
56
+
57
+ @interface SolidNativeFabricSmokeApplication () <RCTHostDelegate>
58
+ - (void)waitForJSIEventCommitWithAttempt:(NSInteger)attempt;
59
+ @end
60
+
61
+ @implementation SolidNativeFabricSmokeApplication {
62
+ RCTReactNativeFactory *_factory;
63
+ id<RCTReactNativeFactoryDelegate> _factoryDelegate;
64
+ RCTHost *_host;
65
+ UIView *_containerView;
66
+ SolidNativeFabricSurface *_surface;
67
+ SolidNativeFabricJSIBinding *_binding;
68
+ SolidNativeFabricSmokeStatusHandler _statusHandler;
69
+ }
70
+
71
+ + (instancetype)startWithFactory:(id)factory
72
+ containerView:(UIView *)containerView
73
+ launchOptions:(NSDictionary *)launchOptions
74
+ statusHandler:
75
+ (SolidNativeFabricSmokeStatusHandler)statusHandler {
76
+ return [[self alloc] initWithFactory:factory
77
+ containerView:containerView
78
+ launchOptions:launchOptions
79
+ statusHandler:statusHandler];
80
+ }
81
+
82
+ - (instancetype)initWithFactory:(RCTReactNativeFactory *)factory
83
+ containerView:(UIView *)containerView
84
+ launchOptions:(NSDictionary *)launchOptions
85
+ statusHandler:
86
+ (SolidNativeFabricSmokeStatusHandler)statusHandler {
87
+ if (self = [super init]) {
88
+ NSAssert(NSThread.isMainThread, @"The smoke application must start on the main thread.");
89
+ _factory = factory;
90
+ _factoryDelegate = factory.delegate;
91
+ _containerView = containerView;
92
+ _statusHandler = [statusHandler copy];
93
+ _binding = [[SolidNativeFabricJSIBinding alloc] init];
94
+
95
+ #ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
96
+ RCTEnableTurboModuleInterop(YES);
97
+ #endif
98
+
99
+ __weak id<RCTReactNativeFactoryDelegate> weakFactoryDelegate =
100
+ _factoryDelegate;
101
+ _host = [[RCTHost alloc]
102
+ initWithBundleURLProvider:^NSURL *() {
103
+ return [weakFactoryDelegate bundleURL];
104
+ }
105
+ hostDelegate:self
106
+ turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)_factory
107
+ jsEngineProvider:
108
+ ^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
109
+ auto factoryRef =
110
+ [weakFactoryDelegate createJSRuntimeFactory];
111
+ if (factoryRef == nullptr) {
112
+ throw std::runtime_error(
113
+ "The React Native factory did not create a JavaScript runtime factory.");
114
+ }
115
+ return std::shared_ptr<facebook::react::JSRuntimeFactory>(
116
+ reinterpret_cast<facebook::react::JSRuntimeFactory *>(
117
+ factoryRef),
118
+ [](facebook::react::JSRuntimeFactory *runtimeFactory) {
119
+ js_runtime_factory_destroy(
120
+ reinterpret_cast<JSRuntimeFactoryRef>(runtimeFactory));
121
+ });
122
+ }
123
+ launchOptions:launchOptions
124
+ bundleConfiguration:_factory.bundleConfiguration
125
+ devMenuConfiguration:_factory.devMenuConfiguration];
126
+ _factory.rootViewFactory.reactHost = _host;
127
+ [_host start];
128
+ [self waitForHostWithAttempt:0];
129
+ }
130
+ return self;
131
+ }
132
+
133
+ - (void)hostDidStart:(RCTHost *)host {
134
+ [(id<RCTHostDelegate>)_factory hostDidStart:host];
135
+ }
136
+
137
+ - (void)host:(RCTHost *)host
138
+ didInitializeRuntime:(facebook::jsi::Runtime &)runtime {
139
+ try {
140
+ [_binding installIntoRuntime:runtime];
141
+ [self reportStatus:@"jsi-installed" error:nil];
142
+ } catch (const std::exception &exception) {
143
+ auto message = [NSString stringWithUTF8String:exception.what()];
144
+ [self reportStatus:
145
+ @"jsi-failed"
146
+ error:[NSError
147
+ errorWithDomain:
148
+ @"SolidNativeFabricSmokeApplication"
149
+ code:4
150
+ userInfo:@{
151
+ NSLocalizedDescriptionKey : message
152
+ }]];
153
+ throw;
154
+ }
155
+ }
156
+
157
+ - (BOOL)respondsToSelector:(SEL)selector {
158
+ return [super respondsToSelector:selector] ||
159
+ [_factory respondsToSelector:selector];
160
+ }
161
+
162
+ - (id)forwardingTargetForSelector:(SEL)selector {
163
+ if ([_factory respondsToSelector:selector]) return _factory;
164
+ return [super forwardingTargetForSelector:selector];
165
+ }
166
+
167
+ - (void)waitForHostWithAttempt:(NSInteger)attempt {
168
+ if (_host.surfacePresenter.scheduler != nil) {
169
+ [self mountSmokeSurface];
170
+ return;
171
+ }
172
+ if (attempt >= MaxHostStartAttempts) {
173
+ [self reportStatus:@"host-failed" error:hostStartError()];
174
+ return;
175
+ }
176
+
177
+ __weak SolidNativeFabricSmokeApplication *weakSelf = self;
178
+ dispatch_after(
179
+ dispatch_time(DISPATCH_TIME_NOW, HostStartRetryNanoseconds),
180
+ dispatch_get_main_queue(),
181
+ ^{
182
+ [weakSelf waitForHostWithAttempt:attempt + 1];
183
+ });
184
+ }
185
+
186
+ - (void)mountSmokeSurface {
187
+ [self reportStatus:@"host-started" error:nil];
188
+ _surface = [[SolidNativeFabricSurface alloc]
189
+ initWithHost:_host
190
+ size:_containerView.bounds.size];
191
+ [_binding publishSurface:_surface];
192
+ _surface.view.frame = _containerView.bounds;
193
+ [_containerView addSubview:_surface.view];
194
+
195
+ __weak SolidNativeFabricSmokeApplication *weakSelf = self;
196
+ [_surface mountText:@"Solid Native direct Fabric mount"
197
+ completion:^(NSError *error) {
198
+ SolidNativeFabricSmokeApplication *strongSelf = weakSelf;
199
+ if (strongSelf == nil) {
200
+ return;
201
+ }
202
+ [strongSelf
203
+ reportStatus:
204
+ error == nil ? @"mount-succeeded" : @"mount-failed"
205
+ error:error];
206
+ if (error != nil) {
207
+ return;
208
+ }
209
+
210
+ NSDictionary<NSString *, id> *invalidTransaction = @{
211
+ @"contractVersion" : @1,
212
+ @"surface" : @(strongSelf->_surface.surfaceId),
213
+ @"sequence" : @2,
214
+ @"priority" : @"normal",
215
+ @"mutations" : @[
216
+ @{
217
+ @"type" : @"update-text",
218
+ @"node" : @3,
219
+ @"text" : @"This staged text must roll back"
220
+ },
221
+ @{
222
+ @"type" : @"insert-child",
223
+ @"parent" : @2,
224
+ @"child" : @2
225
+ }
226
+ ]
227
+ };
228
+ [strongSelf->_surface
229
+ applyTransaction:invalidTransaction
230
+ completion:^(NSDictionary<NSString *, id> *result,
231
+ NSError *rollbackError) {
232
+ [strongSelf
233
+ reportStatus:
234
+ rollbackError != nil
235
+ ? @"rollback-succeeded"
236
+ : @"rollback-failed"
237
+ error:rollbackError == nil
238
+ ? [NSError
239
+ errorWithDomain:
240
+ @"SolidNativeFabricSmokeApplication"
241
+ code:2
242
+ userInfo:@{
243
+ NSLocalizedDescriptionKey :
244
+ @"The invalid transaction was accepted."
245
+ }]
246
+ : nil];
247
+ if (rollbackError == nil) {
248
+ return;
249
+ }
250
+ [strongSelf->_surface
251
+ prepareForJSIOwnershipWithCompletion:
252
+ ^(NSError *ownershipError) {
253
+ [strongSelf
254
+ reportStatus:
255
+ ownershipError == nil
256
+ ? @"jsi-ownership-ready"
257
+ : @"jsi-ownership-failed"
258
+ error:ownershipError];
259
+ if (ownershipError != nil) return;
260
+ [strongSelf->_binding markSurfaceReady];
261
+ [strongSelf
262
+ reportStatus:@"jsi-surface-ready"
263
+ error:nil];
264
+ [strongSelf
265
+ waitForJSICommitWithAttempt:0];
266
+ }];
267
+ }];
268
+ }];
269
+ }
270
+
271
+ - (void)waitForJSICommitWithAttempt:(NSInteger)attempt {
272
+ if (_surface.lastSequence >= 1) {
273
+ [self reportStatus:@"jsi-update-succeeded" error:nil];
274
+ [self waitForJSIEventCommitWithAttempt:0];
275
+ return;
276
+ }
277
+ if (attempt >= MaxJSICommitAttempts) {
278
+ [self reportStatus:@"jsi-update-failed" error:jsiCommitError()];
279
+ return;
280
+ }
281
+ __weak SolidNativeFabricSmokeApplication *weakSelf = self;
282
+ dispatch_after(
283
+ dispatch_time(DISPATCH_TIME_NOW, JSICommitRetryNanoseconds),
284
+ dispatch_get_main_queue(),
285
+ ^{
286
+ [weakSelf waitForJSICommitWithAttempt:attempt + 1];
287
+ });
288
+ }
289
+
290
+ - (void)waitForJSIEventCommitWithAttempt:(NSInteger)attempt {
291
+ if (_surface.lastSequence >= 2) {
292
+ [self reportStatus:@"jsi-event-update-succeeded" error:nil];
293
+ return;
294
+ }
295
+ if (attempt >= MaxJSIEventCommitAttempts) {
296
+ [self reportStatus:@"jsi-event-update-failed" error:jsiEventCommitError()];
297
+ return;
298
+ }
299
+ __weak SolidNativeFabricSmokeApplication *weakSelf = self;
300
+ dispatch_after(
301
+ dispatch_time(DISPATCH_TIME_NOW, JSICommitRetryNanoseconds),
302
+ dispatch_get_main_queue(),
303
+ ^{
304
+ [weakSelf waitForJSIEventCommitWithAttempt:attempt + 1];
305
+ });
306
+ }
307
+
308
+ - (void)reportStatus:(NSString *)status error:(NSError *)error {
309
+ auto handler = _statusHandler;
310
+ if (handler == nil) return;
311
+ if (NSThread.isMainThread) {
312
+ handler(status, error);
313
+ return;
314
+ }
315
+ dispatch_async(dispatch_get_main_queue(), ^{
316
+ handler(status, error);
317
+ });
318
+ }
319
+
320
+ - (void)stop {
321
+ [_binding invalidate];
322
+ [_surface stop];
323
+ [_surface.view removeFromSuperview];
324
+ _surface = nil;
325
+ }
326
+
327
+ - (void)dealloc {
328
+ [self stop];
329
+ }
330
+
331
+ @end
@@ -0,0 +1,63 @@
1
+ #pragma once
2
+
3
+ #import <UIKit/UIKit.h>
4
+
5
+ @class RCTHost;
6
+
7
+ NS_ASSUME_NONNULL_BEGIN
8
+
9
+ typedef void (^SolidNativeFabricCompletion)(NSError *_Nullable error);
10
+ typedef void (^SolidNativeFabricTransactionCompletion)(
11
+ NSDictionary<NSString *, id> *_Nullable result,
12
+ NSError *_Nullable error);
13
+
14
+ // Owns the empty Fabric surface used by the production application and the
15
+ // native-only feasibility harness. Application transactions arrive through the
16
+ // versioned JSI envelope; the text helpers exist only for the retained proof.
17
+ @interface SolidNativeFabricSurface : NSObject
18
+
19
+ - (instancetype)initWithHost:(RCTHost *)host size:(CGSize)size;
20
+
21
+ @property(nonatomic, strong, readonly) UIView *view;
22
+ @property(nonatomic, assign, readonly) NSInteger surfaceId;
23
+ @property(nonatomic, assign, readonly) int64_t lastSequence;
24
+
25
+ - (nullable NSDictionary<NSString *, id> *)
26
+ applyTransactionSynchronously:(NSDictionary<NSString *, id> *)transaction
27
+ error:(NSError *_Nullable *_Nullable)error;
28
+
29
+ - (void)applyTransaction:(NSDictionary<NSString *, id> *)transaction
30
+ completion:(SolidNativeFabricTransactionCompletion)completion;
31
+
32
+ - (void)mountText:(NSString *)text
33
+ completion:(SolidNativeFabricCompletion)completion;
34
+
35
+ - (void)updateText:(NSString *)text
36
+ completion:(SolidNativeFabricCompletion)completion;
37
+
38
+ // Publishes one empty Fabric revision, then resets the native coordinator so
39
+ // JavaScript owns node allocation and starts at commit sequence 1.
40
+ - (void)prepareEmptySurfaceForJSIOwnershipWithCompletion:
41
+ (SolidNativeFabricCompletion)completion;
42
+
43
+ // React Native owns the platform surface across a development runtime reload.
44
+ // Drop only the coordinator identities inherited from the retired JS runtime;
45
+ // the replacement runtime will begin again at node and commit sequence 1.
46
+ - (void)resetForJSRuntimeReload;
47
+
48
+ // RCTHost only rebinds surfaces created through its AppRegistry-oriented
49
+ // factory. This host creates its empty surface directly so it can start before
50
+ // the JavaScript bundle completes; explicitly attach it to the replacement
51
+ // presenter after a runtime reload.
52
+ - (void)rebindToCurrentHostAfterJSRuntimeReload;
53
+
54
+ // Removes the native-only proof tree and resets the transaction sequence so
55
+ // the installed JSI runtime owns node allocation and commit sequence 1.
56
+ - (void)prepareForJSIOwnershipWithCompletion:
57
+ (SolidNativeFabricCompletion)completion;
58
+
59
+ - (void)stop;
60
+
61
+ @end
62
+
63
+ NS_ASSUME_NONNULL_END