DioxusLabs / sdk

A library to provide abstractions to access common utilities when developing Dioxus applications.
Apache License 2.0
84 stars 13 forks source link

Regression: use_window_resize() does not update or panics on resize #48

Closed bcorey closed 4 months ago

bcorey commented 4 months ago

if several components use the use_window_size() hook, they no panic or don't update when the window is resized.

paste the below into the 'dx new' default project to test.

// none of the values update on resize
dioxus-sdk = { git = "https://github.com/DioxusLabs/sdk", features = ["window_size"] }

#[component]
fn App() -> Element {

    rsx! {
        WindowSizeRenderer {}
        WindowSizeRenderer {}
        WindowSizeRenderer {}
        WindowSizeRenderer {}
    }
}

#[component]
fn WindowSizeRenderer() -> Element {
    let window = use_window_size();
    let width = window().width;
    rsx! {
        div {
            style: "width: 100px; height: 30px; text-align: center;",
            "{width}"
        }
    }
}
bcorey commented 4 months ago

this does not occur on my local copy of the repo before commit 2fbad1bfffa1007756b8ecfa3901ecdd0ec1890d

DogeDark commented 4 months ago

I am not able to reproduce this issue on either Web or Desktop. What platform are you targeting and what operating system do you use? Also, to confirm, are you testing it by resizing the window width and not the window height?

It's odd as 2fbad1b was meant to fix a similar issue. Originally, use_window_size() could only be used once.

bcorey commented 4 months ago

I'm on macos targeting web and I'm seeing the issue in firefox, brave, and safari. resizing in either direction causes it.

bcorey commented 4 months ago

this is odd: it's now working for me accessing the git repo directly but the cloned up to date copy fails to update any of the values on resize.

# up to date with origin/master after git fetch -ft git pull
# none of the values update
dioxus-sdk = { path = "../sdk/sdk", features = ["window_size"]}

# BUT using this instead now works
dioxus-sdk = { git = "https://github.com/DioxusLabs/sdk", features = ["window_size"]}
bcorey commented 4 months ago

after running cargo clean & dx serve the local version of the repo works as well

bcorey commented 4 months ago

closing since it seems like this was due to build artifacts from switching repo versions