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

Items are stringified and parsed twice on browser platform #114

Open
JeffBerman opened this issue Mar 23, 2018 · 11 comments
Open

Items are stringified and parsed twice on browser platform #114

JeffBerman opened this issue Mar 23, 2018 · 11 comments
Assignees

Comments

@JeffBerman
Copy link

When using NativeStorage.setItem() on the browser platform, the object is stringified twice. When using NativeStorage.getItem(), it is parsed twice. While odd, this doesn't actually hurt anything when using NativeStorage to do both actions.

It breaks, however, when using NativeStorage to retrieve an item that was originally written by window.localStorage. In my case, I'm upgrading our app, which previously used localStorage, to use NativeStorage. At app startup, the code uses NativeStorage to retrieve some data; if it exists, it knows it came from native storage and goes on its way. If it doesn't exist in native storage, then it converts it by retrieving it from local storage and writing it out to native storage. This works great on a phone, but fails when run in the browser because on a browser local storage is used behind the scenes, and the double-parse causes an error (because the data was originally written with only one stringify).

I left this as a comment on closed issue #47, but then thought it might have no visibility there.

@alokrajiv
Copy link
Collaborator

cc @GillesC

@alokrajiv
Copy link
Collaborator

@JeffBerman If this is still an issue I can look into it :)

@alokrajiv alokrajiv self-assigned this Sep 28, 2018
@alokrajiv
Copy link
Collaborator

I have pasted a wrong comment earlier, which I have taken off.

I confirm yes that we are double parsing and stringifying.

Fixing it might mean, no backward compatibility.

cc @GillesC

@JeffBerman
Copy link
Author

Hi, it is still an issue. :)

For us at least, a lack of backward compatibility isn't an issue, as we only use the browser platform during app development and the issue only occurs on that platform.

Thanks!

@alokrajiv
Copy link
Collaborator

Understood. Fix look easy and I will add it to wip branch.

@GillesC suggest though whether we merge to a minor or major release?

Unless someone uses browser platform for production this might not be an issue..

@JeffBerman
Copy link
Author

Thank you, Alok!

@J3m5
Copy link

J3m5 commented Sep 4, 2019

Hi, I'm using it on the browser platform and I was was wondering if this is the reason why the values get registered with "\" at the beginning and \"" at the end?

@alokrajiv
Copy link
Collaborator

@J3m5 you are spot on! So, long and we haven't fixed it. I'm sorry.

Would you be able to give a PR?

@J3m5
Copy link

J3m5 commented Sep 9, 2019

I'll take a look, do you have any idea why the values are parsed and stringified twice ? I quickly went through the source code but I didn't see anything obvious.

@Thul999
Copy link

Thul999 commented Jun 8, 2020

Are there any news about this issue?

@J3m5
Copy link

J3m5 commented Jun 8, 2020

TBH, I switched to Capacitor since then, there is an official plugin for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants