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

docs: Information about version compatibility and a note about expo in metro config docs #6743

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MatiPl01
Copy link
Member

@MatiPl01 MatiPl01 commented Nov 21, 2024

Summary

This PR adds version compatibility information to metro config docs. This change is motivated by the fact that I received a few messages from people who got stuck on this configuration step and wondered why it doesn't work.

I also noticed that this wrapper doesn't change anything if someone uses expo/metro-config instead of the default React Native @react-native/metro-config config (e.g. someone creates an Expo-managed project instead of a bare workflow). I added information about this to notes.

Example images

Getting Started

Screenshot 2024-11-21 at 18 29 55

Accurate Call Stacks

Added the Important note box and the Version Compatibility section

Screenshot 2024-11-21 at 18 30 51

Added these 2 remarks:

Screenshot 2024-11-21 at 18 30 27

@MatiPl01 MatiPl01 self-assigned this Nov 21, 2024
Comment on lines -32 to -36
const config = {
// Your existing Metro configuration options
};

module.exports = wrapWithReanimatedMetroConfig(config);
Copy link
Member Author

Choose a reason for hiding this comment

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

This also was confusing for some people who copied code from this example with the empty config and wondered why RN app doesn't start. I don't know how to best represent this in code, so I just removed config so that people can think for a while what this config should be before starting the app.

I think that the best way to represent this would be to show something similar to git diff but I don't know if we have this functionality already added in docs.

@MatiPl01 MatiPl01 marked this pull request as ready for review November 21, 2024 17:39
@MatiPl01 MatiPl01 requested a review from tjzel November 21, 2024 17:39
@hirbod
Copy link
Contributor

hirbod commented Nov 22, 2024

We're not using expo/metro-config, but getSentryExpoConfig, which is based on it.
Furthermore, we wrap withNativeWind.

Any insights what to do here? Should we wrap? Is the order important?

Right now, we export like so:

module.exports = wrapWithReanimatedMetroConfig(
  withNativeWind(config, {
    input: './global.css',
    inlineRem: 14,
  })
)

While config is

const config = getSentryExpoConfig(projectRoot)

I don't see any issues, but want to double check.

@MatiPl01
Copy link
Member Author

We're not using expo/metro-config, but getSentryExpoConfig, which is based on it.

I checked how getSentryExpoConfig is implemented and, basically, it extends the @expo/metro-config (see this function).

What @expo/metro-config does is very similar to what we do in reanimated. In general, it implements a custom symbolicator (see this line). The implementation of this function can be found in this file. When you scroll up, you can see the regex patterns array which excludes all stack frames from node_modules (here is this pattern). Thanks to this, user gets better errors/warnings, which point to their code instead of the library source code.

On the contrary, the default React Native metro config excludes only some paths from node_modules, so all errors thrown from third party libraries will show the internal library source code in stack traces. We wanted to tackle this problem by implementing our custom metro config wrapper, which does only one thing (similar to expo's config), it adds the custom symbolicator that filters out all frames from the stack trace that point to node_modules/react-native-reanimated. We don't filter out all frames from any package in node_modules like expo does, we only filter out these pointing to reanimated (you can see our simple implementation here)

Summing up, if you already use getSentryExpoConfig, which extends expo/metro-config, adding wrapWithReanimatedMetroConfig will make no changes as expo's config already filters out all stack frames from node_modules, so reanimated error/warning stack frames are also included.

tl;dr

You can safely remove wrapWithReanimatedMetroConfig from your metro config and everything will still work the same as it works now.

@MatiPl01
Copy link
Member Author

MatiPl01 commented Nov 22, 2024

@hirbod

If you want to make sure that you get readable errors with clean stack traces, you can purposely use reanimated's API in the wrong way. e.g. you can call the getViewProp method with invalid view tag, such as:

getViewProp(-1, "prop");

If you see error similar to this, that shows getViewProp call instead of reanimated internals, your metro config doesn't need the reanimated wrapper.

@hirbod
Copy link
Contributor

hirbod commented Nov 22, 2024

Thank you so much for the clarification. I'll test and report back

Copy link
Collaborator

@tjzel tjzel left a comment

Choose a reason for hiding this comment

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

Please DRY these changes as we discussed offline.

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