Comments (10)
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.
Thanks. To be clear, if you remove that uae_navigate does it still panic?
from leptos.
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.
The use_navigate()
does not panic, but calling the fn
it returns does.
from leptos.
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.
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.
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.
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.
@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.
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)
- Inconsistent Action::pending() state
- [0.7-alpha] `<Route ... view=Component/>` fails if `Component` has an optional prop HOT 1
- Trigger source won't cause a Resource to refetch HOT 1
- Static site sub-routes missing interactivity/not playing well with hydration HOT 2
- Add "scroll" prop to <A> HOT 1
- Router base has no effect HOT 2
- Failed to decode downloaded font HOT 1
- Implement Trait IntoStyle for Style HOT 1
- server_fn depedency on gloo_net 0.5 causing duplicate inclusion of http library with different versions. HOT 5
- Portal strange behavior with reactive children HOT 2
- leptos_config::get_configuration doesn't support workspace metadata in Cargo.toml for multiple projects
- Improve the Documentation on Custom Elements HOT 2
- Multiple ErrorBoundaries break HOT 7
- Add a "create_server_resource" wrapper for server function HOT 1
- Can't pass `Callback` as an event handler
- `memo!` macro similar to `slice!` macro
- Title HOT 1
- 0.7-beta Resource isnt updated with source signal HOT 3
- LocalResource spawn_local called from outside of a task::LocalSet HOT 2
- `0.7-beta` Router `A` component missing `class` & `active_class` props HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leptos.