Cannot save changes to imported creations
Meta info
- Is this a bug or suggestion?: bug
- Version (click on help icon in footer): 6.4.0
- Context - Web app, Chrome extension or both?: Web app
While I am logged out, if I import a creation that I had previously exported while logged in, then I cannot save changes to that creation (Save button is not visible).
Use case: I wanted to keep working and save changes to creations while logged out (e.g. I want to work offline because my Internet connection is spotty). So I exported my creations to JSON, then logged out. Now I can work offline and save creations to local storage instead of the cloud. The problem is, if I want to work on my previously-exported creation, then I can import that creation, but I cannot save changes to it. This is due to the isNotMine boolean which is declared here.
It seems the purpose of the isNotMine flag is to prevent users from trying to save or share other users' public creations? I can think of a couple ways to fix this issue:
- Reassign (if logged in) the item's
createdByproperty when importing it, (or delete the property if not logged in?) - Re-think the
isNotMineand public sharing logic. If you open a public creation from a URL, shouldn't you be able to fork that creation and work on it within your own workspace? Actually now that I'm looking at this deeper, it appears the app completely breaks when opening a publicly-shared creation (e.g. in a different browser, or in incognito mode). Perhaps I should file that as a separate issue?
@nhogle Will have a look at this. Though one question - The web app currently has a bug (#563) where it doesn't work in offline state. How are you able to use the web app without Internet? Also, assuming the web app was working in offline state, you don't need to export and logout to be able to work offline. Even in logged in state you can simply work on your creations, without Internet. Your changes sync to the database next time when you come online.
@chinchang : You're right, I just went back to check, and it looks like I can't run the creations while offline. I was, however, able to import my previously-exported creations (while logged out), and make changes to the code. That was when I discovered that I couldn't save changes. My internet later came back online, so I was able to run the creation again (but still unable to save) so I didn't realize that the offline state was preventing running the creation.
As for saving while offline (and logged in): I see that this works if you do the following:
- Open a creation while online and logged in.
- Go offline (disconnect wifi)
- Make some changes
- Click the "Save" button (I have my auto-save set to "off"). Save button is now disabled with a spinner.
- Go back online
- The save button is re-enanabled and the spinner goes away. (And presumably the creation is saved).
However, if you make multiple sets of changes while offline, and you try saving between those changes, then we run into problems:
- Open a creation while online and logged in.
- Go offline (disconnect wifi)
- Make some changes
- Click the "Save" button. Save button is now disabled with a spinner.
- Make some more changes
- Try clicking the "Save" button again - you cannot.
- Go back online
- The save button is re-enanabled and the spinner goes away. But! if you switch to another creation, and back to the first creation, then only the first set of changes was persisted.
I didn't test this while logged out. Does this help?
Update: I created issue #575 to document the crash issue that I'm noticing when I tried loading the publicly-shared creation in a fresh browser.
Open a creation while online and logged in. Go offline (disconnect wifi) Make some changes Click the "Save" button (I have my auto-save set to "off"). Save button is now disabled with a spinner. Go back online The save button is re-enanabled and the spinner goes away. (And presumably the creation is saved).
These steps you are noticing on your end seem different from the expected behaviour. In offline state, if you press save button, the creation should still save with a message - "Item saved locally. Will save to account when you are online".
Don't you see this message on saving in offline state?
@chinchang : I finally have had a chance to dig into this further, and I see how the app is supposed to show the "saved locally" message if the browser is offline. In my case, the browser's navigator.onLine property is returning true, even though my Wi-Fi connection is disconnected. I believe this is actually pretty common, since many people have virtual network adaptors due to VPN or other virtualized networking that they may have set up on their machines.
From the MDN docs:
Browsers implement this property differently. In Chrome and Safari, if the browser is not able to connect to a local area network (LAN) or a router, it is offline; all other conditions return true. So while you can assume that the browser is offline when it returns a false value, you cannot assume that a true value necessarily means that the browser can access the internet. You could be getting false positives, such as in cases where the computer is running a virtualization software that has virtual ethernet adapters that are always "connected." Therefore, if you really want to determine the online status of the browser, you should develop additional means for checking
So in this case, in ItemService#setItem(), the Firestore's setDoc's promise never resolves, and also navigator.onLine check fails to return a short-circuit promise here. This meansitemService.setItem()'s promise never resolves, which means the onSaveComplete() function doesn't get called and the UI remains in the "saving" state, i.e. the Save button remains disabled and we don't see any message about the item being saved locally or non-locally.
So if navigator.onLine isn't reliable, then it looks like we would need an entirely different approach to saving while offline... Here is a StackOverflow issue with someone else complaining about this very issue with Firestore.
Had been quite occupied since last few days. Will take a look at this again.