-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
FlatList declares a local variable for "props" #42623
Comments
|
|
It is possible that several other FlatList bugs are related to this un-initialized props variable. Please take a look even though there is no reproducer. |
The same code exists in the latest version, so this problem still exists in the latest version. |
Without a reproducer we can't check what's going on here. |
This happens due to misconfigured Babel config. Some combination of transforms seems to turn this code into something invalid. Has been observed when folks add the transform for private members and functions, which RN now supports out of the box. Have you customized the config you are using beyond the Metro preset? |
Somebody in Discord pointed me to issue #36828 and so I compared my Babel config to the Babel config that should fix the issue. I tried a couple of fixes in 36828 and both of those failed. If you read the discussion in 36828, it seems to me that the fixes are not consistent: one fix works for one person and another for another person. I think this is symptomatic of an uninitialized var or prop. I don't believe that the call super(props) initializes this.props - I have been looking for documentation on this and I can't find any that says super() is able to initialize props declared in the derived class. If it were true that super(props) does initialize this.props, then it should still work for you if you initialize the declaration in line 306: props: Props = null; On the other hand, if it now fails for you, then we would have proven that super() does not initialize this.props |
The best way to fix this bug is here: |
It's not possible for users like me to fix this by modifying FlatList.js directly because subsequent EAS builds would simply erase the fix. We need the react-native team to fix it. |
I'm having the same issue. "Fixed" it by adding that |
Thanks for the hint. Didn't know about patch-package. |
This has been fixed in 0.74-rc1_ In case that you cannot upgrade, you can do this: #34783 (comment) Can you confirm its working for you and close the issue @ctapang ? |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Description
I have tried to repro the issue, but it won't repro because of the nature of the bug. The bug is about an un-initialized local variable in the FlatList class declaration ("props") that shouldn't be there. As it is, this props declaration is never initialized. In the constructor, it is referenced as follows:
In my case, an exception occurs in _checkProps because this.props is undefined. The "props" parameter in the constructor (line 421) declares a "props" local object by default, but this declaration is hidden by the other props declaration in line 306, which is not initialized.
Note: I am using both Expo and Metro, but this does not seem to be relevant to the issue. Expo and Metro would only be relevant in terms of how props gets initialized, but I don't think either Expo or Metro could prevent initialization of a local variable in a react-native component, especially in this case.
The repro app I did was not reproducing the issue, but I think that's only because the uninitialized var props happens to have a viable viable value in this case.
Steps to reproduce
Expected: app runs with no issues.
Actual: app crashes with following error:
ERROR TypeError: Cannot read property 'getItem' of undefined
This error is located at:
in FlatList
in RCTView (created by View)
in View (created by ScreenWithoutScrolling)
in RCTView (created by View)
in View (created by KeyboardAvoidingView)
in KeyboardAvoidingView (created by ScreenWithoutScrolling)
in ScreenWithoutScrolling (created by Screen)
in Screen
in RCTView (created by View)
in View
React Native Version
0.72.6
Affected Platforms
Runtime - Android
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/does/not/repro
Screenshots and Videos
The text was updated successfully, but these errors were encountered: