Skip to content

Subscribing to all actions is causing multi-tab problem in local storage #29

Open

Description

@Luk-z

Since local storage is shared between tabs it could happens that when a previous tab is focused it reverts data in local storage, saving an outdate payload.

Example:

  • I have api1 and api2 in the store. Only api1 is redux-remembered
  • open tab1 and both are fetched with api1=x api2=y. api1=x is saved to local storage
  • open tab2, api1 is rehydrated and api2 is fetched
  • on tab2, api1 expires in the store, api1=z is fetched and saved to local storage
  • user focus on tab1 and trigger an action (for example api2 is fetched)
  • api1=x is saved to local storage -> ERROR
  • open tab3 and api1=x is rehydrated -> ERROR

Is it correct that a api1 is set in the local storage when api2 changes?

This problem happens also with slice, not only with api.

POSSIBLE SOLUTION:

  1. api1 should be updated in the local storage only if there is an action related only to api1. Isn't it? Am I missing something?
  2. consumers should implement a logic to keep local storage in sync across tabs

Activity

  1. Luk-z commented on Sep 2, 2026

    @Luk-z
    Author

    Another solution could be to hydrate also when localStorage change.

  2. zewish commented on Sep 8, 2026

    @zewish
    Owner

    Hey @Luk-z, you need a way to manually rehydrate your state without persisting it.
    Unfortunately this means a lot of possible invalid bug reports being opened because of how people will use this.

    For now there is no such unsafe force-rehydrate API call, but there's already a PR suggesting one.

    From what I've seen there's a need for such unsafe functionality, but I need to make sure it's marked explicitly unsafe.
    Stay tuned - we'll definitely have such functionality in the next major release, I just need to find some time to figure out a cleaner way to do it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions