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

fix: SafeLocalStorage handle undefined value #3478

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

combab0
Copy link
Contributor

@combab0 combab0 commented Dec 17, 2024

Description

If localStorage.setItem('item', undefined) is executed, the string 'undefined' is stored as the value for 'item', which is a bug. SafeLocalStorage should avoid setting values in localStorage when the value is undefined to ensure safer behavior.

This patch also resolves the following currently occurring error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at AppKit.syncAccount (client.js:1069:1)
    at AppKit.syncExistingConnection (client.js:1213:1)
    at async AppKit.initialize (client.js:201:1)
syncAccount @ client.js:1069
syncExistingConnection @ client.js:1213
await in syncExistingConnection
initialize @ client.js:201
await in initialize
AppKit @ client.js:184
createAppKit @ react.js:16

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

None

Showcase (Optional)

None

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections
  • I have tested my changes on the preview link
  • Approver of this PR confirms that the changes are tested on the preview link

Copy link

changeset-bot bot commented Dec 17, 2024

⚠️ No Changeset found

Latest commit: bf84d05

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 17, 2024

@combab0 is attempting to deploy a commit to the Reown Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@arein arein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@combab0 can you add a test pls?

@@ -37,7 +37,7 @@ export const SafeLocalStorage = {
key: Key,
value: SafeLocalStorageItems[Key]
): void {
if (isSafe()) {
if (isSafe() && value !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isSafe() && value !== undefined) {
if (value && isSafe()) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not happen as they are strings but this might result in a weird behavior if value is false

@tomiir tomiir merged commit 86e7da0 into reown-com:main Dec 18, 2024
0 of 5 checks passed
@tomiir
Copy link
Collaborator

tomiir commented Dec 18, 2024

@arein adding a test in a PR now 🙏

Edit: #3502

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

Successfully merging this pull request may close these issues.

4 participants