Skip to content

FlatList onScroll corner case bug: contentOffset undefined  #15725

@peacechen

Description

@peacechen

Environment

  1. react-native -v: 0.45.1
  2. node -v: 7.0
  3. npm -v: 3.10
  • Target Platform: iOS 10.2

  • Development Operating System: OSX 10.12

  • Build tools: react-native & Xcode

Steps to Reproduce

This is a corner case bug that happens sporadically in a production build. It hasn't happened yet in a debug build. In the onScroll callback for FlatList, the argument passed in is incomplete. event.nativeEvent.contentOffset is undefined. The crash report came from NewRelic:

RCTFatalException: Unhandled JS Exception: undefined is not an object (evaluating 'e.y')
in 0x1000f3ea0 0 + 4295966368
Unhandled JS Exception: undefined is not an object (evaluating 'e.y'), stack: value@304:8561 value@304:6956 u@94:142 invokeGuardedCallbackAndCatchFirstError@94:580 c@110:365 a@110:567 v@154:502 i@157:95 processEventQueue@154:1433 s@165:88 handleTopLevel@165:174 <unknown>@164:574 perform@185:596 u@108:150 _receiveRootNodeIDEvent@164:546 receiveEvent@164:656 value@22:2893 <unknown>@22:832 value@22:2294 value@22:804

There is only one line in our app that references a .y key:

	onScroll(event) {
		let newScrollOffset = event.nativeEvent.contentOffset.y;
		// ...
	}

FlatList is instantiated as:

	<FlatList
		keyboardShouldPersistTaps={'handled'}
		removeClippedSubviews={true}
		data={this.state.listData}
		extraData={this.state.dataFilter}
		renderItem={this.renderSomething}
		keyExtractor={(item, index) => item.id}
		ListHeaderComponent={this.renderHeader(this.state.headerState)}
		onScroll={this.onScroll.bind(this)}
		scrollEventThrottle={100}
		onRefresh={this.renderRefresh}
		refreshing={this.state.refreshing}
	/>

Expected Behavior

contentOffset should be a valid object.

Actual Behavior

contentOffset is undefined. Is it possible for contentOffset to be undefined in the event parameter?

Reproducible Demo

Won't reproduce in a debugger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions