Comments (5)
Thanks very much! I've been looking for a good reproduction of this particular issue for a couple months. I imagine it has been really annoying to debug, so apologies for that — hopefully this nice minimal reproduction will help me figure it out. Much appreciated.
from leptos.
After playing a bit with my application, I found this way to make it work using
.with
This is great to hear!
That way other resources in the
<Outlet/>
are still created before it finishes loading. Does this seem good to you or would you have another suggestion?
This is totally ideal. The great thing about it is that it means that you remove a layer of waterfalls: if what's rendered in the <Outlet/>
loads some data that doesn't depend on the guard, you begin loading that in parallel with the guard, rather than only after the guard is done.
Let's keep the issue open, because it's still a bug, but I'm glad you were able to refactor to avoid it.
from leptos.
I'm glad it helps then! ;) I quickly saw the resources' output were getting and I already had a minimal example similar to my application (that you made and showed me in another bug report actually '^^) so it was very simple to modify it a little bit and reproduce the issue. Thanks again for your help!
from leptos.
Ok so in this instance, it's relatively easy to fix the example, by changing this
move || guard_data.and_then(|_| view! { <Outlet/> })
to use .with()
instead of .and_then()
move || guard_data.with(|_| view! { <Outlet/> })
The reason for this is that .map
and .and_then
on resources only run once the resource is resolved, but .with
runs and takes an Option
of the resource's current value. This means that the resources are actually created in a different order on the server and in the client, hence the mismatch in expected types.
On the server, you don't render Child
until guard_data
is loaded, so the resources are created in the order
guard_data
other_nested_data
- (once guard data resolves)
nested_data
On the client, by the time the page hydrates all resources have streamed in so the resources are created in the order
guard_data
nested_data
other_nested_data
Resources are assigned flat IDs, not scoped to anything else, which is why the types don't match: IDs 2 and 3 are reversed on client and server.
from leptos.
Thanks for the update :)
After playing a bit with my application, I found this way to make it work using .with
:
resource.with(|result| match result {
Some(Ok(_)) => {
view! { <Outlet/> }.into_view()
},
Some(Err(e)) => {
log::info!("Error: {}", e);
},
None => {
view! { <Outlet/> }.into_view()
},
})
That way other resources in the <Outlet/>
are still created before it finishes loading. Does this seem good to you or would you have another suggestion?
In my case, it was also possible to dodge the error by moving some parts of the html (a DaisyUI drawer) before the <Routes>
but using .with
seems much safer.
from leptos.
Related Issues (20)
- Leptos Axum Handle Server Fn unwrapping Context<ResponseOptions> can panic under load HOT 22
- `mount_to_body` should accept `FnOnce` closures HOT 2
- The class display is inconsistent in some cases HOT 2
- Transition fallback not shown
- Allow turbofish in `view!` macro to better support generic components HOT 4
- Use idiomatic, built-in From and Into traits instead of IntoView, IntoAttribure, etc. HOT 3
- Actix server function panics with missing `HttpContext` HOT 3
- Trying to use (unsupported) equality constraint in component makes leptos ignore the component and its errors and report success HOT 2
- Support for markdown content sites? Similar to @nuxt/content support for nuxt
- Add `read_slice!()` and `write_slice!()` macros HOT 1
- My short onboarding experience HOT 9
- `callback::NotRawCallback` is not implemented for <closure> HOT 7
- Inconstistency between debug and release on `if let Some(x)...` HOT 5
- Trouble with Events not triggering at all HOT 5
- Can you provide a case of a browser right-click pop-up menu?
- Have signals/StoredValues update/update_value functions return the callbacks return value HOT 6
- examples: add `rust-toolchain.toml` files for examples HOT 1
- Resource::loading gives a warning if disposed before it was fully initialized HOT 2
- leptos_router: Feature: Support for trailing slashes. HOT 13
- Get error about missing "tracing" dependency when trying to use #[component] macro HOT 20
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.