Skip to content

fix(useStorageValue): properly handle storage-event removal - #1715

Open
ranneyd wants to merge 1 commit into
react-hookz:masterfrom
ranneyd:use-local-storage-remove-fix
Open

fix(useStorageValue): properly handle storage-event removal#1715
ranneyd wants to merge 1 commit into
react-hookz:masterfrom
ranneyd:use-local-storage-remove-fix

Conversation

@ranneyd

@ranneyd ranneyd commented Sep 4, 2026

Copy link
Copy Markdown

What is the current behavior, and the steps to reproduce the issue?

When you have two tabs, and one of them removes an item in local storage, the second one will ignore that update. Setting the value works, just not removing it.

What is the expected behavior?

Any operation to a local storage key in one tab is synchronized with the other tab.

How does this PR fix the problem?

This synchronization happens via the window's storage event. When a value is removed, newValue is set to null. The handler for that event ignores events where the value is null. This simply removes that check.

I don't think this behavior is intentional. That check was added in #960, which was a large refactor. The check wasn't there before, so I think this fell through the cracks.

Checklist

  • Have you read contribution guideline?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Is there an existing issue for this PR?
    • link issue here
  • Have the files been linted and formatted?
  • [N/A] Have the docs been updated to match the changes in the PR?
  • Have the tests been updated to match the changes in the PR?
  • Have you run the tests locally to confirm they pass?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant