Skip to content

Synced local storage on web goes out of sync when second window writes to the signalΒ #77

@m-col

Description

@m-col

Hi there, I think I've found a bug. with this minimal example, built for the web platform:

use dioxus::prelude::*;
use dioxus_sdk::storage::*;

fn main() {
    dioxus::launch(App);
}

#[component]
fn App() -> Element {
    let mut state = use_synced_storage::<LocalStorage, bool>("state".to_string(), || false);

    rsx! {
        div {
            button {
                onclick: move |_| {
                    state.set(!state());
                },
                "Toggle"
            }
            if state() {
                div {
                    "State is true"
                }
            } else {
                div {
                    "State is false"
                }
            }
        }
    }
}

The issue:

  1. load this page in 2 browser windows
  2. click the button in one of them repeatedly, see the state change in both reliably and in sync
  3. click the button in the other window a few times, see the state quickly go out of sync
  4. clicking the button in the first window doesn't sync them up again

I expected both windows to be able to read and write from the local storage entry and see them update in sync. Is this a bug? Should these remain in sync?

Version 0.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions