Yew: Handler Id Warning

Created on 13 Jan 2020  路  6Comments  路  Source: yewstack/yew

Problem
I'm getting the following warning when switching between different routes using yew_router. I have 5 different components that I switch between when route changes using Router::render. One of the components has a table with 100 rows, this warning returns ~100 times when I switch off that route. Whereas one route is just an index page with static text, and it returns the warning 4 times when switched off that route.

WARN:yew::agent -- The Id of the handler: 0, while present in the slab, is not associated with a callback.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Use yew_router
  2. Use Router::render to render different components, ex: below

There is nothing special about these components. IndexPage for example just renders static text in a <p> tag, yet still produces the above warning 4 times when route changes and different component is then rendered.

html! {
    <Router<AppRoute, ()>
        render = Router::render(move |switch: AppRoute| {
            match switch {
                AppRoute::Index => html!{<IndexPage />},
                AppRoute::Songs => html! {<SongsPage />},
                AppRoute::Artist(id) => html!{<ArtistPage artist_id=id />},
                AppRoute::Artists => html!{<ArtistsPage />},
                AppRoute::Queue => html!{<QueuePage />},
                AppRoute::NotFound(Permissive(None)) => html!{"Page not found"},
                AppRoute::NotFound(Permissive(Some(missed_route))) => html!{format!("Page '{}' not found", missed_route)},
                _ => html!{"Page not found"},
            }
        })
        redirect = Router::redirect(|route: Route| {
            AppRoute::NotFound(Permissive(Some(route.route)))
        })
    />
}

Environment:

  • Yew version v0.11
  • Yew-router version v0.8.1
  • Rust version 1.40.0
  • Target wasm32-unknown-unknown
  • stdweb version
  • OS: linux
  • Browser: firefox
  • Browser version 72.0.1

Questionnaire

  • [x] 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
bug

All 6 comments


Hi, as the maintainer of the Router, I have some input on this.
The Router makes use of agent Dispatchers, which are just like Bridges, but lack a callback used direct messages back to components.

The warning message you see is the result of a message being attempted to be sent back to a component from an agent, but there not existing a callback to facilitate that. What this warning message is effectively saying is "Hey you are using a dispatcher somewhere!", which I consider to be noise, and the warning designation to be a misnomer - everything is acting as expected when you see this message.

There are two options for how to handle this: Remove the logging entirely, or switch it to log::trace! instead. I'm in favor of outright removal, but I'd understand if switching it to trace/debug was thought to be more preferable.
The relevant line of code is: https://github.com/yewstack/yew/blob/99220f542fedd22f0a99fca7cb906bb69d41dea6/src/agent.rs#L321

@jstarry I'll defer to you the decision about how to handle the removal or alteration of the log line.

@hgzimmerman why is the dispatcher trying to send a message to the component?

Hi! I am currently playing with yew-router, and had the same warnings. @jstarry, here are a few links to the code to answer your question:

When the route changes, RouteAgent informs all its subscribers:
https://github.com/yewstack/yew/blob/e4a609f6a0d8448030e661aba04629606cefb065/yew-router/src/agent/mod.rs#L140-L142

yew-router's buttons have RouteAgentDispatcher:
https://github.com/yewstack/yew/blob/e4a609f6a0d8448030e661aba04629606cefb065/yew-router/src/components/router_button.rs#L15-L19

That subscribe to the RouterAgent:
https://github.com/yewstack/yew/blob/e4a609f6a0d8448030e661aba04629606cefb065/yew-router/src/agent/dispatcher.rs#L22
https://github.com/yewstack/yew/blob/e4a609f6a0d8448030e661aba04629606cefb065/yew/src/agent.rs#L97-L113
https://github.com/yewstack/yew/blob/e4a609f6a0d8448030e661aba04629606cefb065/yew-router/src/agent/mod.rs#L115-L117

I guess that's parts of the how. It's late, the why will have to wait ^^
_(I hope GitHub will show previews for the links)_

Might be unrelated, but I saw this when I defined routes out of order, where an earlier definition was a prefix of the later one. This specific case is mentioned in the docs, but maybe the warning could mention it or link to the docs, or mention an error code.

Nevermind I see this in other cases now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alun picture alun  路  4Comments

DenisKolodin picture DenisKolodin  路  5Comments

kellytk picture kellytk  路  4Comments

sanpii picture sanpii  路  3Comments

agausmann picture agausmann  路  3Comments