react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

Unexplainable crash from certain combination of TextInput and TouchableHighlight

Open jmcginty opened this issue 10 years ago • 19 comments

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 avatar Sep 23 '16 12:09 jmcginty

@jmcginty Thanks for the repro, investigating now.

rozele avatar Sep 23 '16 16:09 rozele

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...

rozele avatar Sep 23 '16 17:09 rozele

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.

rozele avatar Sep 23 '16 17:09 rozele

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.

matthargett avatar Sep 23 '16 17:09 matthargett

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 avatar Sep 26 '16 09:09 jmcginty

@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

rozele avatar Oct 03 '16 18:10 rozele

We are using version 0.34, and have been keeping up to date with each new release.

jmcginty avatar Oct 03 '16 21:10 jmcginty

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.

jmcginty avatar Nov 03 '16 10:11 jmcginty

@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:

invalid dimensions

What I want to know is where are the invalid dimensions coming from?

jmcginty avatar Nov 25 '16 05:11 jmcginty

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.

KalKhera avatar Nov 29 '16 21:11 KalKhera

Awesome!!

jmcginty avatar Nov 29 '16 21:11 jmcginty

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.

KalKhera avatar Nov 29 '16 23:11 KalKhera

🙁

jmcginty avatar Nov 30 '16 09:11 jmcginty

Any news on this, got hit by this problem and can't seem to fix with flex fix..

lznt avatar Feb 15 '17 14:02 lznt

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.

jmcginty avatar Feb 15 '17 22:02 jmcginty

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.

lznt avatar Feb 16 '17 09:02 lznt

@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 avatar Feb 16 '17 17:02 rozele

@rozele ooh, that's exciting. I'll have a go next week.

jmcginty avatar Feb 16 '17 22:02 jmcginty

The switch to Facebook Yoga has fixed this problem. Closing this issue now.

jmcginty avatar Apr 03 '17 23:04 jmcginty