fix: initial sync on Preview app (Android) leads to loop #3963
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
tns preview
command is executed and the QR code is scanned with Android device, the Preview app on this device asks for initial sync of the files. At this point CLI starts preparing the project and once the files are prepared, it sends them to device.However, this operation may take some time, especially for code sharing projects, which have a lot of dependencies and webpack is used. Meanwhile the Preview app on device sees that it had not received the files within 10 seconds and sends a new message to get the initial files.
So CLI starts another process of preparation and trying to sync the changes. Based on the time required, this may become an indefinite loop.
Fix this by caching the promise for initial sync and in case device asks again, CLI will use the already pending promise.
Also fix the case where another device from the same platform is used to scan the QR code at some point. Currently we've not passed device identifier to pubnub and the initial sync was sending the files to all devices in the mentioned scenario.
PR Checklist
What is the current behavior?
When trying to execute
tns preview --bundle
for this app on a slower Hard Drive, the operation takes more than 10 seconds to prepare the project and LiveSync to Preview app creates an indefinite loop of preparation and syncing.What is the new behavior?
The app can be synced.