NathanaelA / nativescript-dom

NativeScript DOM emulation methods
MIT License
42 stars 23 forks source link

NativeScript 3.0: 't' is undefined on iOS #12

Closed AdamDenoon closed 7 years ago

AdamDenoon commented 7 years ago

Affected Platforms

This only seems to be an issue on iOS.

Versions

Please tell us how to recreate the issue in as much detail as possible.

add require("nativescript-dom"); to main app.js

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

The offending line is 105 in dom.js:

105: t.cssClasses.forEach(function (item) {
106:            self.push(item);
107:        });

JS ERROR TypeError: undefined is not an object (evaluating 't.cssClasses.forEach')

Adding console.dir(t) as Line 104 in dom.js (like this):

// We need to zero our length; so that we can re-add anything that exists in the parent class
            this.length = 0;
            var self = this;
                        console.dir(t);
            t.cssClasses.forEach(function (item) {
                self.push(item);
            });

produces the following output:

CONSOLE LOG file:///app/tns_modules/nativescript-dom/dom.js:104:18: View(undefined)

AdamDenoon commented 7 years ago

I've updated the issue to reflect my findings (the undefined issue is based on t, not cssClasses)

NathanaelA commented 7 years ago

@AdamDenoon - I need a example to duplicate this. As I said in #4376 -- I ran the NativeScript-Dom inside the demo app (which is in the repo) on both iOS and Android and had no issues using NS 3.x t is defined properly at that point. So if you can give me a example where this fails I would appreciate it...

AdamDenoon commented 7 years ago

@NathanaelA - Here is my app.js at the point I was getting the error:

var application = require("application");

require("nativescript-dom");
require("nativescript-orientation");

var fIcon = require('nativescript-fonticon');
var TNSFontIcon = fIcon.TNSFontIcon;
var fonticon = fIcon.fonticon;

TNSFontIcon.paths = {
'fa': 'font-awesome.css'
};
TNSFontIcon.loadCss();

application.setResources(fonticon);

application.start({ moduleName: "views/login/login" });

I managed to fix it by switching the two plugin requires:

require("nativescript-orientation");
require("nativescript-dom");

So it seems this is an issue with the nativescript-orientation plugin. I'm using nativescript-orientation 1.6.1. After reading the documenation on their repo, it seems they're not compatible with {N} 3.0 yet.

AdamDenoon commented 7 years ago

The issue seems to be that nativescript-orientation is calling nativescript-dom in its own orientation.js (line 26), and calling it twice gives the error of this thread.

Since I need a local variable for the orientation in only a single view controller, and since I need nativescript-dom from my app's init, I was able to hack/fix this for myself by commenting out line 26 in orientation.js:

//require('nativescript-dom');

I've opened the issue with nativescript-orientation, and you can follow it here: https://github.com/NathanaelA/nativescript-orientation/issues/19