Search code examples
rustrust-wasmleptos

Leptos router gives a warning which I do not unterstand


I stared to experiment with https://github.com/gbj/leptos/ using the current main branch from Git. Following the router example I get the following warning in my console in the browser:

WARNING: You are providing a context of a type (leptos_reactive::memo::Memo<leptos_router::components::routes::RouterState>)that's already been provided higher in the context tree. If this is unintentional, there's a chance it will cause bugs, because the value of the context is now 'shadowed' in the lower parts of the tree.

I understand the message, but I have no idea what I'm doing wrong. My router component looks like this:

#[component]
pub fn Playground(
  cx: Scope,
) -> impl IntoView {

  view! { cx,
      <Router>                                                                                                                                 
          <nav>                                                                                                                                
              <A exact=true href="/">"Simple"</A>                                                                                              
              <A href="demo1">"Demo 1"</A>                                                                                                     
              <A href="demo2">"Demo 2"</A>                                                                                                     
          </nav>                                                                                                                               
          <main>                                                                                                                               
              <Routes>                                                                                                                         
                  <Route                                                                                                                       
                      path="/"                                                                                                                 
                      view=move |cx| view! { cx, <SimpleComponent/> } />                                                                       
                  <Route                                                                                                                       
                      path="demo1"                                                                                                             
                      view=move |cx| view! { cx, <Demo1 /> } />                                                                                
                  <Route                                                                                                                       
                      path="demo2"                                                                                                             
                      view=move |cx| view! { cx, <Demo2 /> } />
              </Routes>
          </main>
      </Router>
  }
}

Solution

  • If I recall correctly you found your way to our Discord. Basically this is an over-zealous warning I added a couple days ago in our main branch but probably need to revert.

    In general I’d probably discourage asking questions that are so specific to particular libraries on Stack Overflow, especially when it’s a smallish and new library.