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)
- Derived signals can't be converted Into() Callbacks HOT 1
- Add a `Store` derive macro.
- Add ability to create an enumerated `<For />` component
- Notifying trigger in component breaks the trigger HOT 5
- Would it be useful to add a step, about installing 'Trunk' to the examples/README.md file HOT 2
- `create_resource` panics when server is compiled to wasm32-wasi HOT 8
- Using `<AnimatedRoutes/>` and `set_is_routing` in `<Router/>` together leads to Hydration Bugs HOT 3
- server functions are a bit restrictive HOT 2
- Deserialization error with multiple Suspense HOT 5
- Major drop in performance due to component nesting HOT 6
- Proposal: Better Server function redirect handling HOT 4
- Style display error when the style component specifies the ID HOT 2
- Passing the full url to `Form` omits the url entirely HOT 1
- Islands not working with workspace HOT 9
- module restructuring proposal HOT 3
- BorrowMut error when using signal immutably in `<Show/>` and mutably in `on:click`. HOT 7
- Need to pass context to server functions or use #[server] with struct methods HOT 2
- component annotation causes rust compiler to think generic has not been used HOT 8
- Compiler errors while running cargo make start on ./examples/tailwind_axum HOT 4
- Javascript no longer loads after page routing 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.