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

use_effect() doesn't trigger when rendered via history::push() #2848

Closed
1 of 3 tasks
simbleau opened this issue Aug 26, 2022 · 7 comments
Closed
1 of 3 tasks

use_effect() doesn't trigger when rendered via history::push() #2848

simbleau opened this issue Aug 26, 2022 · 7 comments
Labels

Comments

@simbleau
Copy link
Contributor

Problem

Steps To Reproduce

let history = use_history().unwrap();

html!{
    <button
        onclick={
            let history = history.clone();
            Callback::from(move |_| {
                history.push(_MY_ROUTE_);
            })
        }
     ></button>
}

Expected behavior
use_effect() should be triggered when I navigate to a page via history::push() through yew_router

Screenshots
If applicable, add screenshots to help explain your problem.
Expected:
image
Actual:
image

Environment:

  • Yew version: 19.3
  • Rust version: 1.63.1
  • Target, if relevant: wasm32-unknown-emscripten
  • Build tool, if relevant: trunk
  • OS, if relevant: Ubuntu
  • Browser and version, if relevant: Firefox

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@simbleau simbleau added the bug label Aug 26, 2022
@WorldSEnder
Copy link
Member

Is there a branch on https://github.com/simbleau/website where I can see this live? I'm not certain which component contains the use_effect here and why you expect it to re-render.

@ranile
Copy link
Member

ranile commented Aug 28, 2022

Can you confirm that this bug still persists with on master? A lot of changes to hooks and router have been made.

@simbleau
Copy link
Contributor Author

simbleau commented Aug 28, 2022

It's not from my website , it's on a private repo. I invited you as a collaborator @WorldSEnder ) - trunk serve and go to http://localhost:8080/whoami/3 and advance to the next slide (http://localhost:8080/terminal).

It is irregular, though. When switching from http://localhost:8080/ to the next slide (http://localhost:8080/terminal) the effect is triggered appropriately.

@hamza1311 Right now stylist isn't up to date for Yew 0.20 and this unfortunately causes 60+ errors on my side I'm not too keen on fixing. I've invited you as a collaborator to the repo, same as @WorldSEnder

@futursolo
Copy link
Member

futursolo commented Aug 28, 2022

This is expected as history represents a setter and does not subscribe to changes. If you want to listen to location changes, you need to use the use_location hook.

This is better represented in master as history is wrapped in the navigator type and no longer exposed directly. Navigator does not allow reading location information from it.

@simbleau
Copy link
Contributor Author

Thanks @futursolo

Is the appropriate fix then to use_location, or to upgrade to master?

@futursolo
Copy link
Member

futursolo commented Aug 28, 2022

Is the appropriate fix then to use_location, or to upgrade to master?

Yes. use_history / use_navigator does not listen to changes so users can produce a components that only sets the location without it being re-rendered upon location changes (Link / Redirect).

@simbleau
Copy link
Contributor Author

simbleau commented Aug 28, 2022

Going to close this, I have fixed the issue on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants