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

[localStorage] SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data #424

Closed
CatchABus opened this issue Dec 10, 2022 · 2 comments · Fixed by #425
Assignees
Labels
bug Something isn't working

Comments

@CatchABus
Copy link
Contributor

CatchABus commented Dec 10, 2022

Describe the bug

In firefox, there are times when my local storage hits the limit.
This results in DOMException: The quota has been exceeded. error which is caught by cache-interceptor plugin.

When it's caught, plugin tries to free some space:

.map((item) => [item[0], JSON.parse(item[1]) as StorageValue]);

The issue here is I might have other values stored in localStorage and cache-interceptor will attempt to meddle with them at the location I mentioned above.
If I store a value like localStorage.set("mytheme", "dark");, plugin will attempt to call JSON.parse with "dark" as an argument.
This results in SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.

This may not occur if I set a prefix for my storage.
My suggestion to avoiding this is to perhaps add a default prefix value to plugin.

- export function buildWebStorage(storage: Storage, prefix = '')
+ export function buildWebStorage(storage: Storage, prefix = 'axios-cache')

To Reproduce

Make sure localStorage gets full.

Expected behavior

Should not throw errors.

@CatchABus CatchABus added the bug Something isn't working label Dec 10, 2022
@arthurfiorette
Copy link
Owner

Shure, I let this without prefixes to avoid breaking changes.

But we've been working on v1.0 and it totally fits. Would you mind doing a PR?

@CatchABus
Copy link
Contributor Author

Shure, I let this without prefixes to avoid breaking changes.

But we've been working on v1.0 and it totally fits. Would you mind doing a PR?

I did #425 which refers to this. Let me know if there is anything I can do from my side. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants