Unexplainable crash from certain combination of TextInput and TouchableHighlight
I have a problem in my project where adding a TextInput tag causes it to crash. I have managed to reduce it to the simplest example possible: If you create a brand new react-native app, and then modify the index.windows.js to be the following text, it just crashes (closes window) with no react error.
Steps to replicate: react-native init Crash cd Crash npm install --save-dev rnpm-plugin-windows react-native windows
edit index.windows.js and replace with the code below.
react-native run-windows !!Crash!!
import React, { Component } from 'react';
import { AppRegistry, Image, View, TextInput, TouchableHighlight, StyleSheet, } from 'react-native'
const styles = StyleSheet.create({
header: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
class Crash extends Component {
render() {
return (
<View style={styles.header}>
<TouchableHighlight>
<Image source={{ uri: 'https://github.com/ReactWindows/react-native-windows/blob/master/.github/hero.png'}} />
</TouchableHighlight>
<TextInput />
</View>
);
}
}
AppRegistry.registerComponent('Crash', () => Crash);
@jmcginty Thanks for the repro, investigating now.
Starting to look like a bug in the CSSLayout algorithm. It seems to be setting some width values to NaN. We're working on replacing the algorithm...
I think the problem is that there are no width/height bounds set on the image. Obviously the bigger issue is that it took so long to debug this and there was a cryptic error. Investigating what the behavior is on Android.
Yesterday when I was looking through ReSharpers warnings from a whole solution analysis, it noted at least a dozen places where equality of a double was being checked with operator== and causing a loss of precision. Just mentioning in case those are related somehow to the appearance of a NaN value.
Hi, I tried adding width={50} & height={50} to the image but it didn't work around the problem. Did you find a workaround? This issue is really blocking our development
@jmcginty, which version of react-native-windows are you on? @mpodwysocki is getting very close to finishing the work on the latest css-layout dependency, and we're hoping to get it into one of the next releases
We are using version 0.34, and have been keeping up to date with each new release.
I have updated the example slightly. I found the image url was not right, and added some dimensions to the image as suggested by @rozele . I have updated to react-native 0.36.1, but still get the same error.
import React, { Component } from 'react';
import { AppRegistry, Image, View, TextInput, TouchableHighlight, StyleSheet, } from 'react-native'
const styles = StyleSheet.create({
header: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
class Crash extends Component {
render() {
return (
<View style={styles.header}>
<TouchableHighlight>
<Image
style={{width: 50, height: 50}}
source={{ uri: 'https://github.com/ReactWindows/react-native-windows/blob/master/.github/hero.png?raw=true'}}
/>
</TouchableHighlight>
<TextInput />
</View>
);
}
}
AppRegistry.registerComponent('Crash', () => Crash);
Running in debug in x64, the exception is not very informative, it has no stack trace:
- e {Windows.UI.Xaml.UnhandledExceptionEventArgs} Windows.UI.Xaml.UnhandledExceptionEventArgs
- Exception {"Value does not fall within the expected range."} System.Exception {System.ArgumentException}
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HResult -2147024809 int
HelpLink null string
+ IPForWatsonBuckets {0} System.UIntPtr
+ InnerException null System.Exception
IsTransient false bool
Message "Value does not fall within the expected range." string
ParamName null string
RemoteStackTrace null string
Source null string
StackTrace null string
WatsonBuckets null object
I'm at a dead end here, and am looking for suggestions for
- some way to workaround this error
- debugging strategies - I've no idea where to start with this really.
@rozele @KalKhera Update: I have tracked this down to invalid dimensions being set on the TextInput. The text input is getting set to a dimensions object with values: Height 899 Width NaN X Nan Y 0
If I set Width to 100 and X to zero in the debugger, there is no crash.
This is happening in ReactTextInputManager.SetDimensions See attached screen dump and stack trace:

What I want to know is where are the invalid dimensions coming from?
Hello all, After some snake oil hackery, I found the following seems to fix the problem. I added style={{flex:1}} to the text input and no more crash. When in doubt flex.
Awesome!!
Unfortunately , TextInput still misbehaves on more complicated screens.
Red modal 'Value does not fall within the expected range' error being displayed from react native windows.
🙁
Any news on this, got hit by this problem and can't seem to fix with flex fix..
I have not found a fix yet. I think the bug is in the code that calculates the width & height for the textbox and other controls. In some cases, it is returning values that crash the XAML renderer, but I haven't been able to deep dive into it. I'm waiting for 0.41to be released before having another crack.
I was not able to catch the false values entering in setDimensions at least, but I reckon its better to wait for new version of rnw for now and disable TextInput for now.
@jmcginty @lznt @KalKhera I just tried the examples above on the latest bits. I do believe that the recent switch to Facebook.Yoga has resolved the issue. I've already posted release candidates for 0.40.0, 0.41.0, and 0.42.0. Please try upgrading to one of these versions (0.40.0-rc.2, 0.41.0-rc.1, 0.42.0-rc.2).
@rozele ooh, that's exciting. I'll have a go next week.
The switch to Facebook Yoga has fixed this problem. Closing this issue now.