Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Livesync hangs when modifying App_Resources in before-prepare hook #3251

Open
lfabreges opened this issue Dec 9, 2017 · 4 comments
Open
Labels
run Describes issues related to run command to-be-checked Issues that might be resolved in a previous release and need to be tested or clarified further

Comments

@lfabreges
Copy link

lfabreges commented Dec 9, 2017

Tell us about the problem

When using nativescript-localize with "tns run ios", it tries to sync Localizable.strings without rebuilding the app.

Which platform(s) does your issue occur on?

iOS, haven't tried on Android

Please provide the following version numbers that your issue occurs with:

  • CLI: 3.3.1
  • Cross-platform modules: 3.3.0
  • Runtime(s): 3.3.0
  • Plugin(s): nativescript-localize (2.0.5)
  • iOS 11 on iPhone X emulator

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

git clone --depth 1 --branch v2.0.5 https://github.com/lfabreges/nativescript-localize.git
cd nativescript-localize
npm install
npm run compile
cd demo
npm install
tns run ios

Then make a change in the app/i18n/en.default.js file, change "Hello World !" to "Hello" for example.

Executing before-prepare hook from /Users/lfabreges/Documents/Developpement/nativescript-localize/demo/hooks/before-prepare/nativescript-localize.js
Preparing project...
Project successfully prepared (iOS)
Successfully transferred en.default.js.
Refreshing application...
Successfully synced application org.nativescript.demo.javascript on device ED5FEB43-DDA2-43FD-B693-4E07FD78CB1C.
Skipping prepare.
Successfully transferred Localizable.strings.
Refreshing application...
Successfully synced application org.nativescript.demo.javascript on device ED5FEB43-DDA2-43FD-B693-4E07FD78CB1C.

More

I think the problem occurs because :

  • The plugin modifies Localizable.strings in the App_Resources
  • Prepare is done and savePrepareInfo save the .nsprepareinfo file with a modified time greater that Localizable.strings modified time
  • The watcher detects that a change has been made to the Localizable.strings and add it to the queue
  • Prepared is skipped because no change is detected, appResourcesChanged is not set to true because containsNewerFiles returns false because Localizable.strings has been modified before .nsprepareinfo file is written to disk
  • Localizable.strings is synced but without a rebuild and the app hangs, I need to stop tns run, remove the platforms directory and fully rebuild and resinstall the app to make it work again

I tried to hook into the process but did not find a way to fix it, I triggered a build by modifying appResourcesChanged directly into the plugin, it works but Localizable.strings is stilled synced afterwards, so it hangs again.

I'm the author of the plugin, so I can change it if needed. I definitly need some help on it.

Regards.

@lfabreges
Copy link
Author

Hi,

I have the same problem using NS 3.4. As I understand it, files under the App_Resources shouldn't be transferred when the application is not rebuilt, otherwise it crashs under iOS (at least when using the emulator) when refreshing the application.

Regards.

@lfabreges lfabreges changed the title Livesync fails when using a plugin that modifies App_Resources Livesync hangs, localize plugin is unusable Dec 29, 2017
@lfabreges lfabreges changed the title Livesync hangs, localize plugin is unusable Livesync hangs when modifying App_Resources in before-prepare hook Dec 30, 2017
@lfabreges
Copy link
Author

I manage to fix my plugin by unwatching localization files:

if (liveSyncService &&
    liveSyncService.liveSyncProcessesInfo[projectData.projectDir] &&
    liveSyncService.liveSyncProcessesInfo[projectData.projectDir].watcherInfo &&
    liveSyncService.liveSyncProcessesInfo[projectData.projectDir].watcherInfo.watcher
) {
  const watcherInfo = liveSyncService.liveSyncProcessesInfo[projectData.projectDir].watcherInfo;
  if (!watcherInfo._isLocalizePluginHackInstalledForPlatform) {
    watcherInfo._isLocalizePluginHackInstalledForPlatform = {};
  }
  if (!watcherInfo._isLocalizePluginHackInstalledForPlatform[platformName]) {
    converter.livesyncExclusionPatterns().forEach(pattern => {
      watcherInfo.watcher.unwatch(path.relative(projectData.projectDir, pattern));
    });
    watcherInfo._isLocalizePluginHackInstalledForPlatform[platformName] = true;
  }
}

But that's a HACK, I'm not using the public API.

Regards.

@Fatme
Copy link
Contributor

Fatme commented Apr 5, 2018

Hi @lfabreges,

Thank you for your detailed description and providing the workaround.

You're absolutely correct about the reasons to have this issue. It is hard to reproduce but is a valid scenario. Also you're correct that build is mandatory when some change occurs in App_Resources folder.

We're working on improving this behaviour and providing a fix. Your issue should be resolved, after implementing this feature #3404.

@lfabreges
Copy link
Author

Hi @Fatme,

It wasn't working correctly, even with the #3404 feature. I now use the before-checkForChanges hook, it's better but still not satisfying. When using vue for example, it takes multiple builds before the new strings resources are taken into account. It still feels like I'm hacking the thing, haven't found a way to properly modify, add or delete application resources using a plugin.

Regards.

@rosen-vladimirov rosen-vladimirov added run Describes issues related to run command to-be-checked Issues that might be resolved in a previous release and need to be tested or clarified further labels May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run Describes issues related to run command to-be-checked Issues that might be resolved in a previous release and need to be tested or clarified further
Projects
None yet
Development

No branches or pull requests

3 participants