Closed manijak closed 4 years ago
Yeah this is not intended to run alongside livesync/hmr because any available appsync package will interfere with whatever hmr wants to sync. I did not anticipate anyone enabling appsync during development so didn't test that scenario either.
What should work though is having the plugin installed, but never calling AppSync.sync()
while developing. Is that a correct assumption?
I'll add a note to the readme once that's confirmed, and figure out a way to detect running with hmr available so the plugin can at least log a warning. Ideas welcome of course!.
Totally agree, took me a while to understand & debug that there was a conflict here, and it does make sense, there is no need to sync anything as I am sitting with the latest code.
Correct, disabling AppSync.sync()
does not interfere with hmr/livesync, the behavior was much better after turning it off.
The best way would be if it could detect a dev environment, but I read a bit about environment modes (dev/production) and could not find anything easy to use. Not without remembering to alter files/configs.
So I would guess a fast & easy way would be to just add a flag to the options that turns sync on or off. Similar to the sandbox mode on the firebase plugin. You still need to remember to turn it on before publishing, but perhaps give a warning in the console if you try to build with --release
or when using the appsync-cli: Appsync is not enabled! Check your config
something like that?
Thanks a bunch, this gives me something to think about!
I decided to detect "hmr" when running the app, and if it's the case AppSync.sync()
will no longer update the app. This behavior can be overridden by passing in enabledWhenUsingHmr: true
to that method.
Not sure if this is normal behavior or not, but didn't notice it the first time I added app-sync. It came to my intention after upgrading tns-cli from 6.0.4 to 6.1.2 and xcode to 11.
Environment
nativescript-app-sync (1.0.5)
Describe the bug It seems that there are some issues with hmr & app-sync if the app crashes due to a coding mistake. hmr stops reloading the app & applying new changes, and it shows the app from the last app-sync patch. Any new changes are not applied, and one has to stop the app & nuke the platforms folder and run again.
Using just
tns run ios
does not work, it just shows the app from the last patch and not applying any new changes.I did try stopping the app, doing first
tns build ios
and thentns run ios
. That worked, but stopping the app, and running again, made the issue reappear.If I disable app-sync, hmr works as expected.
EDIT: Also noticed both in iOS & Android, if I close the running app and re-open it. It just applies the latest patch, ignoring all local changes.
To Reproduce 1) Enable App-sync & run the app on iOS simulator. App-sync tells you the latest patch version, let's say: v5. 2) Do a change in app and save hmr refreshes app normally and the change is applied. *See Log nr 1 for details 3) Do another change in the app but that causes a crash, like invalid color value
color="#white"
App crashes and the log shows the error. 4) Fix the error in the app and save App loads but is showing the app in the v5-patch state, not showing any changes you made since then. *See Log nr 2 for details 5) Do another change and save App refreshes but still, showing only v5-patch version, change not applied.6) Stop the app (CTRL+C) and do
tns run build
thentns run ios
App runs and shows the latest changes. 7) Stop the app (CTRL+C) and dotns run ios
App runs but showing the app from v5-patch state. No changes applied.8) Stop the app (CTRL+C) and do
rm -rf platforms
thentns run ios
App runs normally and hmr applies new changesExpected behavior That hmr & app-sync play nice together. Or perhaps a flag to disable app-sync when in dev mode.
Workaround Disable App-sync in app.ts when developing. Enable it when ready for publish.
Additional context Here are loggs related to the reproduce-steps above.
Log nr 1 (reproduce step 2)
Log nr 2 (reproduce step 4)