Skip to content

(feat): add method to deallocate reactNativeFactory instance#301

Open
marcinszalski-callstack wants to merge 3 commits intocallstack:mainfrom
marcinszalski-callstack:feature/134_add_method_to_deallocate_reactnativefactory_instance
Open

(feat): add method to deallocate reactNativeFactory instance#301
marcinszalski-callstack wants to merge 3 commits intocallstack:mainfrom
marcinszalski-callstack:feature/134_add_method_to_deallocate_reactnativefactory_instance

Conversation

@marcinszalski-callstack
Copy link
Copy Markdown
Contributor

Summary

Address the Add method to deallocate reactNativeFactory instance #134 issue

Test plan

See the Test plan from the #134 issue

Comment on lines +69 to +72
#if !EXPO_SDK_GTE_55
guard let factory = reactNativeFactory else { return }
factory.bridge?.invalidate()
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This check is here because there is no bridge instance on Expo > 55?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment on lines +17 to +27
private var factory: RCTReactNativeFactory {
if let existingFactory = reactNativeFactory {
return existingFactory
}

delegate.dependencyProvider = RCTAppDependencyProvider()
let createdFactory = ExpoReactNativeFactory(delegate: delegate)
reactNativeFactory = createdFactory
return createdFactory
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We already create a factory instance in startReactNative and assign it as reactNativeFactory. So I believe we do not need to create another factory instance here. I know that it will only create a new instance if reactNativeFactory is nil BUT if we think about it, this instance will only be nil if startReactNative hasn't been called OR stopReactNative have been called already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hurali97 some duplicated code removed in my second commit, please check it again

Copy link
Copy Markdown
Member

@hurali97 hurali97 Apr 15, 2026

Choose a reason for hiding this comment

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

@marcinszalski-callstack - Why do we need to create a separate factory variable instance? Why we can't re-use the reactNativeFactory?

I think this factory change is unnecessary and you use reactNativeFactory to call in stopReactNative. Similarly, I suggest keeping the factory initialization in startReactNative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in the original PR, factory was responsible for making sure a valid instance is always provided, creating a new instance if necessary.
in a next commit that logic to be simplified, i.e. to get rid of the reactNativeFactory property

return reactNativeFactory?.rootViewFactory
}()

private var factory: RCTReactNativeFactory {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

likewise

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same here - please, @hurali97 , check my second commit


guard let factory = reactNativeFactory else { return }

factory.bridge?.invalidate()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe we can skip this invocation as we do not support old arch anymore? And if I recall correctly on newer versions of RN, this factory.bridge should always be nil?

Copy link
Copy Markdown
Collaborator

@artus9033 artus9033 Apr 13, 2026

Choose a reason for hiding this comment

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

I think we still do - we have a separate sourceset on Android.

Not all APIs support it (e.g. postMessage needs the New Arch).

I'd leave it as-is, unless you object?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I recall we did a few PRs to remove the old arch support, when react-native decided to drop it. For instance, here - we previously provided a way for old arch but that was removed.

As part of this - we dropped support for old arch on Android - #148

I see that we still have a few places with old arch, we can plan removing those now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Alright, I also recall this. Let's have this change dropped then + we'll follow up with decoupling of OA remainders later

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants