Skip to content

Fix new codegen API disabling behaviour of the old one #51867

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

Closed
wants to merge 4 commits into from

Conversation

kkafar
Copy link
Contributor

@kkafar kkafar commented Jun 6, 2025

Summary:

Hey, I'm bumping react-native-screens to 0.80.0-rc.4 right now & noticed that codegen does not work as expected. It crawls whole library, file by file (when working on a library it also includes nodemodules etc), despite componentProvider field being defined in codegenConfig in package.json.

Namely #49941 introduced a regression for libraries that stick to the old codegen config format due to compatibility reasons. Take a look at this code. We first do a pass for "old API", removing libraries with componentProvider in their codegen config from librariesToCrawl, just to later add ALL libraries that do not support new codegen config format back again to librariesToCrawl.

This PR improves the filtering condition, to parse codegen annotations only for libraries that have defined any of the fields from the new config format (opted in for new system).

I want to emphasise that this is a significant regression, because it ruins experience of library maintenance, vastly increasing pods installation time.

Changelog:

[IOS] [FIXED] - Fix codegen crawling all library code with componentProvider defined in config

Test Plan:

  1. Setup an application with any third party library, that uses "old" codegen config format, e.g. [email protected]
  2. cd ios && bundle exec pod install
  3. Observe the codegen logs - it crawles the library instead of using provided information.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jun 6, 2025
@kkafar kkafar marked this pull request as draft June 6, 2025 08:32
@cortinico
Copy link
Contributor

I believe this same issue is already addressed by reactwg/react-native-releases#974 (and linked PR). RC5 should fix this issue for react-native-screens

@kkafar
Copy link
Contributor Author

kkafar commented Jun 6, 2025

That's great then, thanks for the heads up

@kkafar
Copy link
Contributor Author

kkafar commented Jun 6, 2025

Edit: just checked the PR you linked - I believe these to be separate issues

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

Yeah, those are separate issues. I think the code makes sense.

If you can fix the js_test red signal and set it as ready to be reviewed, I can import and land it.

@kkafar
Copy link
Contributor Author

kkafar commented Jun 6, 2025

I'm not convinced of this code yet, I've opened the PR a bit prematurely.

At the moment I've managed to work around this issue (prevent codegen from crawling) by duplicating component descriptions in my codegen config

This PR in current state not only fixes the issue of overeager crawling, but also changes the behaviour. If this is merged then the library can either use old API or new API - they can not be mixed. Current implementation allows for mixing these two APIs (exactly what I've done in the commit ☝️)

The ability to mix these is kinda nice, because it'll allow us to keep the backward compat a bit longer in case the "old config" is removed in 0.81 or 0.82

The golden solution here would be to allow for mixing, but also avoid crawling.

So my proposal is as follows:

  1. detect whether new API is in usage, is so ignore "old" fields if present,
  2. if there are no new API fields in usage, try to look for "old" fields
  3. if there are no "old" & no "new" fields - only then crawl.

I'll rewrite this in couple of minutes

@cipolleschi
Copy link
Contributor

cipolleschi commented Jun 6, 2025

thanks for being thorough.

At the moment I've managed to work around this issue (prevent codegen from crawling) by duplicating component descriptions in my codegen config

This is actually the right fix, with the new API and the proper way to declare which native components the library exposes.

But to keep backward compatibility, we should fix codegen.

If the componentLibrary uses new api & or does not specify anything it
is processed in a new way.

Otherwise (when it specifies only old API fields) it is considered to
use old API.
@kkafar
Copy link
Contributor Author

kkafar commented Jun 6, 2025

@cipolleschi I've updated the code & snapshots

Now:

👉🏻 If the componentLibrary uses new api or does not specify anything it
is processed in a new way.

👉🏻 Otherwise (when it specifies only old API fields) it is considered to
use old API.

@kkafar kkafar marked this pull request as ready for review June 6, 2025 10:27
@cipolleschi
Copy link
Contributor

amazing, thanks for fixing this and also for working on the tests!

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 9, 2025
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 65aa819.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @kkafar in 65aa819

When will my fix make it into a release? | How to file a pick request?

react-native-bot pushed a commit that referenced this pull request Jun 9, 2025
Summary:
Hey, I'm bumping `react-native-screens` to 0.80.0-rc.4 right now & noticed that codegen does not work as expected. It crawls whole library, file by file (when working on a library it also includes nodemodules etc), despite `componentProvider` field being defined in `codegenConfig` in `package.json`.

Namely #49941 introduced a regression for libraries that stick to the old codegen config format due to compatibility reasons. Take a look at [this code](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L60-L103). We first do a pass for "old API", [removing libraries with `componentProvider` in their codegen config from `librariesToCrawl`](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L66-L75), just to later [add **ALL** libraries](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L86-L89) that do not support new codegen config format back again to `librariesToCrawl`.

This PR improves the filtering condition, to parse codegen annotations only for libraries that have defined any of the fields from the new config format (opted in for new system).

I want to emphasise that this is a significant regression, because it ruins experience of library maintenance, vastly increasing pods installation time.

## Changelog:

[IOS] [FIXED] - Fix codegen crawling all library code with `componentProvider` defined in config

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #51867

Test Plan:
1. Setup an application with any third party library, that uses "old" codegen config format, e.g. `[email protected]`
2. `cd ios && bundle exec pod install`
3. Observe the codegen logs - it crawles the library instead of using provided information.

Reviewed By: cortinico

Differential Revision: D76126649

Pulled By: cipolleschi

fbshipit-source-id: 6f9c9dffcdca7204a78b4b55db10249240146141
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @kkafar in 4b65d0e

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants