[TIMOB-25785] iOS: Sending events that cannot be serialized fail on SDK 7.0.0+
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-04-23T19:38:56.000+0000 |
Affected Version/s | Release 7.0.0 |
Fix Version/s | Release 7.3.0 |
Components | iOS |
Labels | events, ios, json, regression |
Reporter | Guile |
Assignee | Hans Knöchel |
Created | 2018-02-16T12:54:35.000+0000 |
Updated | 2018-06-26T20:44:34.000+0000 |
Description
Here is a code :
alloy.js
Ti.Gesture.addEventListener('orientationchange', function (e) {
Ti.App.fireEvent('_customEvent', e);
});
Ti.App.addEventListener('_customEvent', function () {});
This triggers an error on orientation change
{noformat}
[ERROR] : Script Error {
[ERROR] : column = 19;
[ERROR] : line = 13;
[ERROR] : message = "Invalid type in JSON write (GestureModule)";
[ERROR] : sourceURL = "file:///Users/houra/Library/Developer/CoreSimulator/Devices/599E21F7-4A9F-4B60-8864-1CE1485B4360/data/Containers/Bundle/Application/F13B31FA-B6FE-4372-A3FF-AFC5B5E2F1F9/Clean.app/app.js";
[ERROR] : }
{noformat}
Hey there, did this work before 7? If so, it actually shouldn't, because you are passing a whole namespace to the event which is a) very very expensive in terms of performance and b) bad for your app scope. The underlaying reason is that an object cannot be stringified which is required to send over the event. *EDIT*: I just tested on 6.3.0 and it works, so we will fix it. Test-Case:
PR: https://github.com/appcelerator/titanium_mobile/pull/9856
I've seen your PR, there is something uncomfortable : you should assume the BC Break, as it exists right now in GA and not going back to your initial decision in the serialization of the event parameter. The fact is that I changed my code to make it work with 7.0.2 and I won't go back on it. So let's assume that TI.Gesture can not be stringify in JSON. Document it clearly. What do you think about it ?
Hey there! The PR fixes exactly that by restoring the old behavior. In addition, it now throws a warning if you still do. In case of your exact case, you are sending the whole event you receive for convenience, although not all properties of the event are required. The PR basically checks for unserializable object fragments and removes them + warns you in case it finds them. This was done before as well, but using a third party library that was removed in Titanium 7. Would you agree on the change? And again, if it really is such an issue, you can simply replace
with
A more elegant solution really would be to only pass the required info, e.g. the orientation, but thats fine. I will also document the general behavior.
The warning is fine, so the PR ;-) I've already fixed my code by not passing through the event object. Thank you !
Happy to hear, thank you! And sorry for causing this, this is properly unit-tested now as well :-).
*Closing ticket.* Verified fix can be seen in SDK Version:
7.3.0.v20180618182516
*FR (Passed) Test Steps:*Created an application with the code above in the comments
Ran the program
Application no longer errors out and the following warnings can be seen
*Test Environment*