Git Product home page Git Product logo

Comments (10)

jquesada2016 avatar jquesada2016 commented on May 8, 2024

Hee it is @gbj

use leptos::*;
use leptos_router::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn start() {
  console_error_panic_hook::set_once();

  mount_to_body(view_fn);
}

fn view_fn(cx: Scope) -> impl Mountable {
  provide_context(cx, RouterIntegrationContext::new(BrowserIntegration {}));

  view! { cx,
    <span>
      <Router>
        <span>  // <-- won't compile whithout these
          <Routes>
            <Route path="/" element=|cx| view! { cx, <Home /> } />
            <Route path="/found-another" element=|cx| view! { cx, <h1>"bug!"</h1> } />
          </Routes>
        </span> // <-- won't compile whithout these
      </Router>
    </span>
  }
}

#[component]
fn Home(cx: Scope) -> Element {
  use_navigate(cx)("/found-another", Default::default()).unwrap();

  view! { cx,
    <h1>"/"</h1>
  }
}

from leptos.

gbj avatar gbj commented on May 8, 2024

Thanks. To be clear, if you remove that uae_navigate does it still panic?

from leptos.

jquesada2016 avatar jquesada2016 commented on May 8, 2024

The workaround I am currently using is to just schedule the navigation in the next microtask using wasm_bindgen_futures::spawn_local, which runs after whatever was borrowed releases the lock.

from leptos.

jquesada2016 avatar jquesada2016 commented on May 8, 2024

The use_navigate() does not panic, but calling the fn it returns does.

from leptos.

gbj avatar gbj commented on May 8, 2024

Thanks. This is the kind of thing the reactive system doesn't like: rendering the app requires reactively reading the current route, which synchronously renders the component, which updates the current route... such that you're mutating the value of the route signal within an effect that depends on the route signal.

I've basically moved your solution into the library, here, using queue_microtask rather than spawn_local for any navigation.

from leptos.

jquesada2016 avatar jquesada2016 commented on May 8, 2024

Is this something that should potentially have a disclaimer for authors creating primitive utilities using leptos_reactive? Or is this a situation that the average user might find themselves in while using signals and effects?

I personally ran into it out of trying to create a Redirect component which redirects the user elsewhere if the component renders, which currently does not exist in the leptos_router crate. All other uses of signals and effects I've used haven't triggered this panic yet.

from leptos.

gbj avatar gbj commented on May 8, 2024

Yeah you know it's actually going to take a more general solution: I actually ran into the same thing in the TodoMVC example this morning. It's pretty easy to accidentally create these loops. I'll try to solve it without the user land/library land hack.

from leptos.

nguiard avatar nguiard commented on May 8, 2024

Hi, I just ran into this today, on 0.3.1. Is it supposed to be fixed or is a solution still in the works?

from leptos.

gbj avatar gbj commented on May 8, 2024

@nguiard The reactive system has been almost completely rewritten since this issue. I'm quite sure the panic in your case was caused by something completely different from this old issue. Could you please open a new issue with a reproduction? Otherwise it won't be possible to help you.

EDIT: Sorry, I may have misunderstood for a second. Did you run into the same issue with use_navigate?

from leptos.

nguiard avatar nguiard commented on May 8, 2024

I wasn't specific enough, my bad. You are correct, the issue was caused by something completely different. I'll open an issue to describe it a bit and try to make a minimal reproduction. Thanks.

from leptos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.