Out of memory error using debug() in an Animated.FlatList with a ref
See original GitHub issueDescribe the bug
I’m implementing a test in a component that renders an Animated.FlatList
, when I use debug the test hangs and eventually throws a JavaScript heap out of memory error.
I found out that If I remove the ref I’m passing to the Animated.FlatList
everything works fine.
It also works with a regular FlatList
.
Expected behavior
Test shouldn’t hang and debug() output should be visible in the console.
Steps to Reproduce
Run this test:
function MyFlatList() {
const ref = useRef();
return (
<Animated.FlatList
ref={ref}
data={[1, 2, 3]}
renderItem={({ item }) => <Text>{item}</Text>}
/>
);
}
test('FlatList', () => {
const { debug } = render(<MyFlatList />);
debug();
expect(true).toBe(true);
});
The test will hang and throw this error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Versions
@testing-library/react-native: 7.0.2 => 7.0.2
react: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
react-test-renderer: ^16.13.1 => 16.13.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Can I test to animated component in react-native with jest?
FlatList >. ( just ) So, This test code has success ! It shows me the result of debug(). How can i test...
Read more >FlatList - React Native
A performant interface for rendering basic, flat lists, supporting the most handy features:
Read more >Solving Memory Leaks with React Native - Enquero
An app provided to help reproduce the issue turned out to be leaking components via Animated loop that has been started in componentDidMount...
Read more >TS animated Flatlist type error : r/reactnative - Reddit
createAnimatedComponent (FlatList); interface IArr { id: string; ... rNav]} /> </View> ) }; export default function App() { const translateX ...
Read more >File System API — Emscripten 3.1.26-git (dev) documentation
All files exist strictly in-memory, and any data written to them is lost when the ... registerDevice() , a device node can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, we’ve faced a similar issue. It looks as if when using a ref on an
Animated
component, the snapshot becomes huge.As an example, you can run:
And see that the snaphsot is nearly 3,000 lines long. If you use an
Animated.ScrollView
instead ofAnimated.View
, the snapshot is more than 30,000 lines long!Also this might be linked to https://github.com/facebook/jest/issues/8109
Seems like the root issue is related to the actual size of component tree generated by using
Animated
wrappers. If so then the you can work around the issue by:jest
instance using approach described by @raimonkhAnimated
implementation as described by @scrungrth, preferably usingjest
features instead ofObject.defineProperty