[TIMOB-24811] LiveView causes multiple instances of same module when requiring using different paths
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2017-09-18T22:54:43.000+0000 |
Affected Version/s | Release 6.1.0 |
Fix Version/s | n/a |
Components | n/a |
Labels | liveview, titanium |
Reporter | Brenton House |
Assignee | Feon Sua Xin Miao |
Created | 2017-06-06T22:33:08.000+0000 |
Updated | 2017-09-21T06:42:59.000+0000 |
Description
When requiring a module nodejs style, using index as default, requiring the same file using different paths results in different modules.
_i.e. require('/test') vs require('/test/index')_
*Steps to recreate:*
1. Create a new Titanium app using the CLI
2. Create a new file: /lib/test/index.js
var test = {};
module.exports = test;
test.x = 1;
3. Open the file controllers/index.js
4. Add the following lines:
var test = require('/test');
console.error('test.x: ' + test.x);
5. Run app: appc ti build --platform ios --target simulator --log-level trace --liveview
6. App should start successfully.
7. The following should show in console log: test.x: 1
8. Change the file: /lib/test/index.js
var test = {};
module.exports = test;
test.x = 2;
9. The following should show in console log: test.x: 2
but instead the output is the same as before: test.x: 1
If you use the following in /controllers/index.js, it works as expected:
var test = require('/test/index');
console.error('test.x: ' + test.x);
*Another test that fails (and doesn't require a recompile or restart) is this:*
var test1 = require('/test');
console.log('test1.x: ' + test1.x);
test1.x = 2;
var test2 = require('/test/index');
console.log('test2.x: ' + test2.x);
The output of this with LiveView off is:
test.x: 1
test.x: 2
But with LiveView on, the output is this:
test.x: 1
test.x: 1
This issue should be resolved using cached version of required module. In SDK 5.X.X the second call of require to the same module returns cached module. I'm sure that this will fix it:
PR: https://github.com/appcelerator/liveview/pull/105
Fixed in liveview@1.2.1.
Update PR: https://github.com/appcelerator/liveview/pull/108
[~fmiao]Hey Feon do we know when live view 1.2.1 will be released?
PR merged.
[~vvazquezmontero], it'll be shipped with Studio 4.10.0
Thank you [~fmiao] do we have an expected ship that for that?
[~kkolipaka] ^^
[~vvazquezmontero] Studio 4.10.0 RC would be next week.