Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: migrate repack native modules to turbo modules #344

Closed
wants to merge 31 commits into from

Conversation

teneeto
Copy link

@teneeto teneeto commented Apr 17, 2023

Summary

This PR aims to enable newArch and make re.pack native modules to turbo modules while ensuring newArch is implemented with backward compatibility.

re.pack current implementation directly uses RN native modules, but with this change, there is a SPEC implementation that allows for more efficient communication between native and JavaScript. This change allows for both old and new architecture.

Test plan

  • Make sure you are currently using the newArch and the setup conforms to React Native Doc directives which also means you're on RN>=0.68.0

NOTE: TesterApp currently meets this requirement if you're using repack TesterApp.

For Android

  • You will only need to update your android/gradle.properties file as follows:
    newArchEnabled=true

  • and then yarn TesterApp:start

For iOS

  • Run pod install with the flags:
    RCT_NEW_ARCH_ENABLED=1 pod install

  • and then yarn TesterApp:start

Screen Records

  • newArch - iOS

Screen.Recording.2023-04-17.at.13.00.01.mov

  • oldArch - iOS

Screen.Recording.2023-04-17.at.13.13.11.mov

  • newArch - Android

Screen.Recording.2023-04-17.at.13.39.30.mov

  • oldArch - android

Screen.Recording.2023-04-17.at.13.26.39.mov

@changeset-bot
Copy link

changeset-bot bot commented Apr 17, 2023

⚠️ No Changeset found

Latest commit: 5f77968

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@teneeto teneeto force-pushed the chore/migrate-repack-to-turbo-modules branch from 4ed60f4 to 742f9fb Compare April 17, 2023 10:19
@troZee troZee self-requested a review April 21, 2023 10:38
README.md Show resolved Hide resolved
packages/repack/ios/ScriptManager.mm Outdated Show resolved Hide resolved
packages/repack/js/index.ts Show resolved Hide resolved
packages/repack/js/NativeScriptManager.ts Outdated Show resolved Hide resolved
packages/repack/js/NativeScriptManager.ts Show resolved Hide resolved
packages/repack/js/NativeScriptManager.ts Show resolved Hide resolved
packages/repack/js/NativeScriptManager.ts Outdated Show resolved Hide resolved
packages/repack/tsconfig.json Outdated Show resolved Hide resolved
@troZee
Copy link
Member

troZee commented Apr 21, 2023

Overall it looks good 🎉 I have added a few comments

cc @thymikee @jbinda


}

fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise, remoteLoader: RemoteScriptLoader, fileSystemLoader: FileSystemScriptLoader) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@RafikiTiki RafikiTiki left a comment

Choose a reason for hiding this comment

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

I don't have much experience when it comes to New Architecture so if @troZee says it's looking good from the configuration perspective I trust his judgment :)

However, one thing that I don't like is that the native implementation of the prefetchScript, loadScript, and invalidateScripts methods is duplicated, thus making the maintenance cost higher in the future. Is this expected when writing backward-compatible modules? That would be a weird design TBH.

ScriptManagerModuleImpl.NAME, // name
ScriptManagerModuleImpl.NAME, // className
false, // canOverrideExistingModule
false, // needsEagerInit
Copy link
Member

Choose a reason for hiding this comment

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

I don't know what exactly needsEagerInit means, but I'd say Repack should be initialized & available as soon as possible, especially in the Module Federation architecture we're now treating as a recommended one.

Take a look at the Super App Showcase Host App – https://github.com/callstack/super-app-showcase/blob/main/packages/host/index.js ScriptManager is used before the App component is registered.

Of course, what I'm saying here might be completely wrong since I'm not that familiar with the New Arch – if that's the case, sorry for the confusion :)

Copy link
Author

Choose a reason for hiding this comment

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

On repack side, i'm not sure how eager it needs to be initialised (even though i feel it's still initialised and available), however this is the default spec from docs and i'm sure it can be set to Eagerly initialise.

README.md Outdated Show resolved Hide resolved
@teneeto
Copy link
Author

teneeto commented Aug 16, 2023

I don't have much experience when it comes to New Architecture so if @troZee says it's looking good from the configuration perspective I trust his judgment :)

However, one thing that I don't like is that the native implementation of the prefetchScript, loadScript, and invalidateScripts methods is duplicated, thus making the maintenance cost higher in the future. Is this expected when writing backward-compatible modules? That would be a weird design TBH.

Yes, that's the implementation for backward compatibility. There's a common module with the actual implementation of prefetchScript, loadScript, and invalidateScripts within the ChunkManagerModuleImpl.kt file. The only difference between the old and new arch is how these methods are exposed, where the new arch uses override for methods, the old arch uses the @ReactMethod. And that's the only time we use the old or new arch files.

Copy link

This pull request has been marked as stale because it has been inactive for 60 days. Please update this pull request or it will be automatically closed in 14 days.

@github-actions github-actions bot added the Stale label Dec 22, 2023
@karimb11
Copy link

karimb11 commented Jan 6, 2024

Hi, any ETA on this improvement? Thanks!

@github-actions github-actions bot removed the Stale label Jan 7, 2024
@jbroma
Copy link
Member

jbroma commented Feb 1, 2024

Closing in favour of #495

@jbroma jbroma closed this Feb 1, 2024
@jbroma
Copy link
Member

jbroma commented Feb 1, 2024

Thank you @teneeto for your all work on this PR 🙏

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.

Support new React Native new architecture (TurboModules/Fabric)
6 participants