dexie-encrypted icon indicating copy to clipboard operation
dexie-encrypted copied to clipboard

one field of type object is not updated properly

Open lifter035 opened this issue 5 years ago • 10 comments

In my table I have saved contact object that has one of the properties named "icon" of type object. I have it encrypted and Inoticed that icon was not updated properly on record update. So I added that field into whitelist to see if that would fix it.

So before i update contact object looks like this: { etag: "" firstName: "" icon: { direct-uri: "https://domain/icon/1576169325909" etag: "1576169325909" uri: "https://domain/icon" } inTrash: 0 isFavorite: 0 ..... and so on }

after i update full contact with response from server it ends up like this even though "icon" is in whitelist

{ etag: "" firstName: "" icon: { direct-uri: "" etag: "" uri: "https://domain/icon" } inTrash: 0 isFavorite: 0 ..... and so on }

not sure what is going on but it seems that parts are still encrypted.

If I disable encryption update works perfectly ok. So it seems that something with nested objects does not work properly when updating?

BTW if I have "icon" object encrypted, when I update the contact with new data after updating icon on the server, data seems to be stale, when data is loaded from the database old "direct-uri" is decrypted.

So just to repeat, without "dexie-encrypted" update of the record works ok, when using "dexie-encrypted", "icon" object doesn't get updated properly, and even if I whitelist "icon" some of it's props are "emptied" on update

lifter035 avatar Dec 12 '19 17:12 lifter035

Ok one thing I noticed is that if I check disable cache in Chrome dev tools images loaded for icons are correct and it seems that icon url is correct in db. So the weird thing is that browser is showing stale cached images for icons, but only if encryption is on for database. If I remove encryption, images shown are correct. Bizarre behaviour. Also it happens in all the browsers not only in Chrome. For some reason if encryption is on, browsers are loading stale icon images even though image urls are correct in db

lifter035 avatar Dec 16 '19 10:12 lifter035

Actually looking at what is fetched back from database after the record is updated for some reason "icon" object is not updated but server still returns new image even if the "direct-uri" has old timestamp at the end of url. That's why disabling cache in dev tools helped. I'm not sure why is this happening only for "icon" part of the contact json. Some other object type fields in contact record are updated properly. I will try and make reproducible code for you

lifter035 avatar Dec 16 '19 16:12 lifter035

Here you go: https://stackblitz.com/edit/typescript-aukskv?file=index.ts

lifter035 avatar Dec 16 '19 16:12 lifter035

Just to add all other types in contact are number, string, boolean or arrays of objects and they are updated correctly. "icon" field which is the object on the first level doesn't seem to be updated. Here's another stackblitz that shows array of objects ('devices' field) successfully updated but 'icon' field which is root level object prop does not get updated: https://stackblitz.com/edit/typescript-xx2vcy?file=index.ts

lifter035 avatar Dec 17 '19 09:12 lifter035

Hi @lifter035 ,

I have also been having trouble with Dexie and when working through your example, I have noticed that Dexie.table.put does not encrypt data, while Dexie.table.bulkPut does.

I wonder if this is your issue?

jaetask avatar Dec 17 '19 11:12 jaetask

Hi @jaetask ,

in my app I use bulkPut exclusively and in this example upsertFriend uses put and required data is encrypted if you check indexeddb in developer tools, so no i don't have issue with encryption, only with some part of my record not being updated.

But there is some issue with updates of root level object types, when encrypted and when they are in the whitelist as well and expected not to be encrypted

lifter035 avatar Dec 17 '19 13:12 lifter035

Sorry, I didn't see this until just now.

The modifications object that Dexie hooks provide does not look like I expected for objects. The paths are stringified, which means that fixing this would mean breaking keys with dots in them. However, I'm not certain that would work in Dexie at all right now.

image

I'll get a fix out this week.

stutrek avatar Jan 08 '20 16:01 stutrek

It appears to stem from a bug in Dexie, I have opened a ticket over there.

For now, you can use this branch and your code will work, but any keys you have with dots in them will also create a corresponding object structure.

https://github.com/mark43/dexie-encrypted/tree/fix-child-objects

stutrek avatar Jan 08 '20 22:01 stutrek

Hey thanks, luckily in my case icon was the only root level object type and our backend would still serve updated icon if cache buster was added to the url, which is not the greatest solution but it works for now. Will wait for Dexie hook fix to update our libraries. Thanks again

lifter035 avatar Jan 09 '20 10:01 lifter035

I merged the fix that makes nested objects appear as both nested objects and dots in the path. I don't have a better answer right now.

Leaving open because it's not really fixed.

stutrek avatar Mar 25 '20 14:03 stutrek