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

Fixed wrong usage of require when resolving supportsCodegenConfig in react-native.config.js #657

Conversation

chrfalch
Copy link
Contributor

@chrfalch chrfalch commented Oct 10, 2024

Summary:

When using the library in monorepo solutions or other non-standard types of projects the Slider will end up with a height of 0 and not work. (See #652)

Problem/fix:

When resolving the version inside react-native-config which is used by the autolinking gradle tasks, the wrong use of require was used.

This fix changes from using require.main.require -> require.

The difference is that require.main.require resolves from the entry point (main script), while require resolves from the location of the current file.
Fixes (partially) #652

Test Plan:

See #652 for reproduction and tests. We've tested in in our BareExpo project, in a regular project (where it also previously did work) and in a project using react-native-test-app (https://github.com/vonovak/react-native-slider/tree/fix/new-arch-issues/new-example)

When resolving the version inside `react-native-config` which is used by the autolinking gradle tasks, the wrong use of require was used.

This fix changes from using `require.main.require` -> `require`.

The difference is that require.main.require resolves from the entry point (main script), while require resolves from the location of the current file.

Closes callstack#652
@vonovak
Copy link
Contributor

vonovak commented Oct 10, 2024

Just to add a bit of context: the config output is used to generate android/app/build/generated/autolinking/src/main/jni/autolinking.cpp file. This file should contain:

void autolinking_registerProviders(std::shared_ptr<ComponentDescriptorProviderRegistry const> providerRegistry) {
providerRegistry->add(concreteComponentDescriptorProvider<RNCSliderComponentDescriptor>());
// more descriptors
  return;
}

but prior to this change, the providerRegistry->add(concreteComponentDescriptorProvider<RNCSliderComponentDescriptor>()); would not be present.

If I may, I'd even suggest the maintainers to remove the @react-native-community/cli-platform-android version check altogether, because we're at version 14 and version 9 is from 2 years ago 🙂 .

@szymonrybczak
Copy link

@vonovak agree! We support 3 latest versions, so version 9.x is not longer supported 👍

Copy link

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

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

Looks good, thank you! 👍

@chrfalch
Copy link
Contributor Author

All good - will you be merging and making a release, @szymonrybczak? Then we can update our Expo versions to the latest so this one is fixed :) Thanks in advance!

@szymonrybczak
Copy link

cc @BartoszKlonowski do you mind taking a look? 🤔

chrfalch added a commit to chrfalch/react-native-safe-area-context that referenced this pull request Oct 11, 2024
We've had some issue with monorepos when resolving the codegen config on Android in other libraries, and found that due to versions no longer in use we could now remove the version test in `react-native-config.js` and always return the component descriptor etc.

(The monorepo issue was with using `require.main.require` which will resolve to the calling script and not the module)

For reference, here is the same PR in @react-native-community/slider:

callstack/react-native-slider#657
Copy link
Member

@BartoszKlonowski BartoszKlonowski left a comment

Choose a reason for hiding this comment

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

I've got nothing here to complain about, good job, everyone 👍
Thank you, @chrfalch, for handling this!

(Sorry for the delay, but for such cases I'm available on Discord and Slack, wherever possible for one. Still, you managed this just great on your own, folks 💪)

@BartoszKlonowski BartoszKlonowski merged commit b528795 into callstack:main Oct 11, 2024
9 checks passed
@BartoszKlonowski
Copy link
Member

BartoszKlonowski commented Oct 11, 2024

Oh, one more thing: I don't know if I'll be able to 🚢 during the weekend, so if not, then please expect this released on Monday.

@chrfalch
Copy link
Contributor Author

Oh, one more things: I don't know if I'll be able to 🚢 during the weekend, so if not, then please expect this released on Monday.

All good - Monday will be more than good enough - thanks :)

janicduplessis pushed a commit to th3rdwave/react-native-safe-area-context that referenced this pull request Oct 16, 2024
* Removed a check that is no longer needed

We've had some issue with monorepos when resolving the codegen config on Android in other libraries, and found that due to versions no longer in use we could now remove the version test in `react-native-config.js` and always return the component descriptor etc.

(The monorepo issue was with using `require.main.require` which will resolve to the calling script and not the module)

For reference, here is the same PR in @react-native-community/slider:

callstack/react-native-slider#657

* cr: Reverted and simplified change after code review

Removed previous change and made the `supportsCodegenConfig` variable true initially

* revert: reverted commit - removed last line.
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.

4 participants