React native different behaviour between debug mode and normal mode

守給你的承諾、 提交于 2021-01-27 13:00:47

问题


hi I have a really complicated problem. So I created a new repo for this problem at github. So you can clone it and see what the problem is.

https://github.com/guitar9/hafas-client-example

I am using https://github.com/public-transport/hafas-client in this project to get train and railway station informations.

client.journeys(münchenHbf, münchenPassing)
.then((response)=>{
  console.log('===============response=====================');
  console.log(response);
  console.log('====================================');
})
.catch(console.error)

the request is in

node_modules/hafas-client/lib/request

Problem is in debug mode everything works fine (shake phone and start remote JS Debugging), but when i stop JS Debugging i get Error 'PARSE'.

So i looked up in request.js and logged out request and response in debug mode and not in debug mode.

Request Debug Mode

{
    "method": "post",
    "body": "{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"20180614\",\"outTime\":\"174837\",\"ctxScr\":null,\"getPasslist\":false,\"maxChg\":5,\"minChgTime\":0,\"depLocL\":[{\"lid\":\"A=1@L=008000261@\"}],\"viaLocL\":null,\"arrLocL\":[{\"lid\":\"A=1@L=008004158@\"}],\"jnyFltrL\":[{\"type\":\"PROD\",\"mode\":\"INC\",\"value\":\"1023\"},{\"type\":\"META\",\"mode\":\"INC\",\"meta\":\"notBarrierfree\"}],\"getTariff\":false,\"outFrwd\":true,\"getPT\":true,\"getIV\":false,\"getPolyline\":false,\"numF\":5,\"trfReq\":{\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\",\"redtnCard\":null}],\"cType\":\"PK\"}}}],\"client\":{\"id\":\"DB\",\"v\":\"16040000\",\"type\":\"IPH\",\"name\":\"DB Navigator\"},\"ext\":\"DB.R15.12.a\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"n91dB8Z77MLdoR0K\"}}",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "user-agent": "https://github.com/public-transport/hafas-client"
    },
    "query": {
        "checksum": "6af3b74db20e14c7f94012e3de55dce6"
    }
}

Response Debug Mode

all informations. everything okay.

Request not in debug mode

{
    "method": "post",
    "body": "{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"Invalid DateTime\",\"outTime\":\"Invalid DateTime\",\"ctxScr\":null,\"getPasslist\":false,\"maxChg\":5,\"minChgTime\":0,\"depLocL\":[{\"lid\":\"A=1@L=008000261@\"}],\"viaLocL\":null,\"arrLocL\":[{\"lid\":\"A=1@L=008004158@\"}],\"jnyFltrL\":[{\"type\":\"PROD\",\"mode\":\"INC\",\"value\":\"1023\"},{\"type\":\"META\",\"mode\":\"INC\",\"meta\":\"notBarrierfree\"}],\"getTariff\":false,\"outFrwd\":true,\"getPT\":true,\"getIV\":false,\"getPolyline\":false,\"numF\":5,\"trfReq\":{\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\",\"redtnCard\":null}],\"cType\":\"PK\"}}}],\"client\":{\"id\":\"DB\",\"v\":\"16040000\",\"type\":\"IPH\",\"name\":\"DB Navigator\"},\"ext\":\"DB.R15.12.a\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"n91dB8Z77MLdoR0K\"}}",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "user-agent": "https://github.com/public-transport/hafas-client"
    },
    "query": {
        "checksum": "0d8186da7b06f9cc094075a2a6e21b00"
    }
}

Response not in debug mode

{
    "ver": "1.16",
    "ext": "DB.R15.12.a",
    "lang": "eng",
    "id": "",
    "err": "PARSE",
    "svcResL": []
}

I have compared the requests. Here you can see the difference between the two request. https://www.diffnow.com/?report=pvuq7 The problem is outDate, outTime and checksum. Somebody can help me?


回答1:


The problem is the usage of the Luxon library within hafas-client library. You will see that your code provided in the repo runs fine on iOS and on android only with remote debugging enabled. Why?

When remote debugging is enabled the code does not run in your phone but in the V8 engine of your chrome browser. When the remote debugging is disabled, code runs on your phone, where in case of android, it runs on a JavaScriptCore (JSC) engine from late 2014 that was compiled with custom setup for react native - that can, potentially, deliver different results.

As the luxon docs point out, support for react native on android is limited.

On iOS, react native uses the JSC available from the OS, which also includes intl features. The reason JSC on android does not have int support is that JSC is bundled together with the apk, and compiling it with intl support would increase the apk size by several MB.

With a bit of cutomizations (forking the hafas client) and working around the date problems, I believe you should be able to fix this. You may also use this but beware that you may run into other sorts of issues that may be hard to get help with (for a while, the Expo client used to use the JSC compiled from this repo but they had to stop using the custom build because of some problems).

Alternatively, you may try using intl polyfill

How did I find out? here you'll see that the error object contains a bunch of extra information. When you were logging the error, you were just getting the description field, but if you log the request field, you'll see that it contains "outDate": "Invalid DateTime". There it is!




回答2:


Author of hafas-client here. Posting as an answer for visibility and because I don't have the reputation to comment.

As I have documented in https://github.com/public-transport/hafas-client/issues/56#issuecomment-399915315, I managed to use hafas-client@3.0.0-alpha.9 out-of-the-box in react-native, after I had added the node-libs-react-native shims. Please try this.

There might of course be another issue related to luxon (as discussed in https://stackoverflow.com/a/51005700), but at least querying data without EPARSE errors or undecoded response payloads are not related to luxon and apparently solved.



来源:https://stackoverflow.com/questions/50861731/react-native-different-behaviour-between-debug-mode-and-normal-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!