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

Handler Id Warning #870

Closed
1 of 3 tasks
tarkah opened this issue Jan 13, 2020 · 8 comments · Fixed by #1846
Closed
1 of 3 tasks

Handler Id Warning #870

tarkah opened this issue Jan 13, 2020 · 8 comments · Fixed by #1846
Labels

Comments

@tarkah
Copy link

tarkah commented Jan 13, 2020

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

  • 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
@tarkah tarkah added the bug label Jan 13, 2020
@nurebrahimkanakan
Copy link

****

@hgzimmerman
Copy link
Member

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:

Some(None) => warn!("The Id of the handler: {}, while present in the slab, is not associated with a callback.", id.raw_id()),

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

@jstarry
Copy link
Member

jstarry commented Feb 3, 2020

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

@totorigolo
Copy link
Contributor

totorigolo commented May 3, 2020

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:

for sub in &self.subscribers {
self.link.respond(*sub, route.clone());
}

yew-router's buttons have RouteAgentDispatcher:

pub struct RouterButton<SW: Switch + Clone + 'static, STATE: RouterState = ()> {
link: ComponentLink<Self>,
router: RouteAgentDispatcher<STATE>,
props: Props<SW>,
}

That subscribe to the RouterAgent:

let dispatcher = RouteAgent::dispatcher();

yew/yew/src/agent.rs

Lines 97 to 113 in e4a609f

/// This trait allows the creation of a dispatcher to an existing agent that will not send replies when messages are sent.
pub trait Dispatched: Agent + Sized + 'static {
/// Creates a dispatcher to the agent that will not send messages back.
///
/// # Note
/// Dispatchers don't have `HandlerId`s and therefore `Agent::handle` will be supplied `None`
/// for the `id` parameter, and `connected` and `disconnected` will not be called.
///
/// # Important
/// Because the Agents using Context or Public reaches use the number of existing bridges to
/// keep track of if the agent itself should exist, creating dispatchers will not guarantee that
/// an Agent will exist to service requests sent from Dispatchers. You **must** keep at least one
/// bridge around if you wish to use a dispatcher. If you are using agents in a write-only manner,
/// then it is suggested that you create a bridge that handles no-op responses as high up in the
/// component hierarchy as possible - oftentimes the root component for simplicity's sake.
fn dispatcher() -> Dispatcher<Self>;
}

fn connected(&mut self, id: HandlerId) {
self.subscribers.insert(id);
}

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)

@joprice
Copy link

joprice commented Oct 24, 2020

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.

@joprice
Copy link

joprice commented Oct 24, 2020

Nevermind I see this in other cases now.

@lukechu10
Copy link
Contributor

So if I understood this correctly, the solution is to just to remove the warning message?

@ctron ctron mentioned this issue May 11, 2021
3 tasks
@siku2
Copy link
Member

siku2 commented May 18, 2021

This was addressed in #1846 and is also no longer relevant because of #1791

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

Successfully merging a pull request may close this issue.

8 participants