Replies: 3 comments 16 replies
-
Thanks for taking the time to create this writeup! Some of these issues are fixed in the git version of dioxus, some could be fixed with better documentation, and some are more fundamental to the liveview approach. Unfortunately, Liveview is the only platform that handles events asynchronously which forces the API for communicating with the browser (through eval, onmounted, and event handlers) to be async. It also performs poorly with SEO and can be more resource intensive. Because of those limitations, we have been deprioritizing liveview as a platform and may drop support in the future. If we do drop support, some migration path for liveview-like apps will be available in fullstack like signals driven through websockets
I think that should be fixed in #3341
You can use the
This is part of the reason dioxus in general is moving away from liveview. You can add elements to the head with the
You can use the navigator with the router to change to a different page: https://dioxuslabs.com/learn/0.6/router/reference/navigation/programmatic |
Beta Was this translation helpful? Give feedback.
-
I find that there seems to be some confusion with life times I don't understand. e.g. (cut down code) pub fn PhoneCallListView(props: Props) -> Element {
let mut edit_contact = use_signal(|| None);
let mut new_phone_calls_signal: Signal<Vec<PhoneCallDetails>> = use_signal(std::vec::Vec::new);
rsx! {
for phone_call in new_phone_calls_signal.iter() {
PhoneCallComponent {
key: phone_call.id,
show_actions: true,
phone_call: phone_call.clone(),
on_edit_contact: move |_contact_id| {
edit_contact.set(Some(phone_call.contact_id));
}
}
}
}
} generates the error:
But If I remove the reference to LATER: Oh, I see, I think there might be some sort of implied attempt of the rsx! macro (or maybe it is the nested component I think I have to lookup the id value outside the rsx! macro like: pub fn PhoneCallListView(props: Props) -> Element {
let mut edit_contact = use_signal(|| None);
let mut new_phone_calls_signal: Signal<Vec<PhoneCallDetails>> = use_signal(std::vec::Vec::new);
rsx! {
for phone_call in new_phone_calls_signal.iter() {
{
let id = phone_call.id;
rsx! {
PhoneCallComponent {
key: phone_call.id,
show_actions: true,
phone_call: phone_call.clone(),
on_edit_contact: move |_contact_id| {
edit_contact.set(Some(id));
}
}
}
}
}
}
} This isn't as elegant, but at least it works. EVEN LATER: I have a But will post this regardless, it is a good example of the life time issue I experienced. |
Beta Was this translation helpful? Give feedback.
-
Does Dioxus full stack currently have any support for pushing data from the server to the client, e.g. via websockets? I thought I saw something, but now I can't find it. |
Beta Was this translation helpful? Give feedback.
-
I thought I would share my experiences I have had with live views here. As somebody with experiences writing personal projects with Phoenix Live views, but now prefers a type safe language such as Rust over Elixir.
Code is at https://github.com/brianmay/phone_db_rust/tree/23ffda33ed86a2def8d62e4c90bf72134e5e69ac - but note it is in a state of flux. I have pointed to the exact version of my project which is likely to become old quickly.
I have looked only at the 0.6.0 release. I have no idea if these solutions are good or correct, but they "work for me". It is possible some of these have already changed.
References to bug reports of known related issues appreciated.
Paths must start with a
/
This was my first error. Turns out there is a problem with line here:
https://github.com/DioxusLabs/dioxus/blob/v0.6.0/packages/liveview/src/adapters/axum_adapter.rs#L48
It will only work when the path is
/
otherwise it will generate an incorrect path.I think multiple calls to
with_virtual_dom
are, for every component. So we end up with a websocket for every top level component. I think this is different from phoenix live views which is able to share a single websocket amongst multiple top level components.This enabled phoenix to do rapid changes between top level components.
I note the master version is a bit different so this may already be resolved.
trait defined for router without state
https://github.com/DioxusLabs/dioxus/blob/v0.6.0/packages/liveview/src/adapters/axum_adapter.rs#L36
This makes it impossible to use on a
Router
that has calledwith_state()
.Tested fix:
Actually this probably should be a generic.
HTML Template code hard coded
https://github.com/DioxusLabs/dioxus/blob/v0.6.0/packages/liveview/src/adapters/axum_adapter.rs#L51-L62
This may not always be suitable. e.g. it may be desirable to have my head elements. I have meta viewport.
I tried to generate this myself using rsx macros. This didn't work out though, I couldn't generate the
head
element from rsx, but also (perhaps not surprisingly) I couldn't convert the dom tree to a string for rendering. So I stack to a string based template as above.https://github.com/brianmay/phone_db_rust/blob/23ffda33ed86a2def8d62e4c90bf72134e5e69ac/backend/src/lib.rs#L86-L103
App State and Path parameters
My App needs access to the State and Path parameters. I could not see how to do this with the existing code. So I ended up replacing the
with_virtual_dom
with my own function.https://github.com/brianmay/phone_db_rust/blob/23ffda33ed86a2def8d62e4c90bf72134e5e69ac/backend/src/lib.rs#L124-L181
This currently has hard-coded values for
AppState
, this could be changed to a generic parameter.I have not attempted to deal with Query parameters, I think this would be next on my list.
With my changes, I can do do:
where the
ContactDetailView
is defined like:And this will listen on
/contacts/:id
and/contacts/:id/ws
respectively and the html path will pass the required information to the websocket path.In hindsight, wondering if this is the best approach. Might be better to pass the raw information to the component and handle the parsing in the component. Or something like that.
I note the master version is a bit different, but I think it doesn't yet solve the issue.
Websocket disruption
If websocket connection goes down, the website becomes non-responsive with no feedback to the user, and does not appear to try to connect again. This is not particularly good user experience.
Redirection
I have an object detail page that has a delete operation. But this of course means the page will turn into an error because the object doesn't exist anymore.
Need to be able to redirect to a different page from the component, but I can't work out how.
Infinite scrolling
Something I suspect is not currently possible without access to live scroll position and window size position information. Maybe this might help #2128
I think not even wasm front end code provides the required access yet though, although presumably I could fall back to JavaScript here (I thought I saw an issue on this but can't find it right now).
Conclusion
While live views work and seem to work well, I think there are currently some limitations. As described above.
Wondering if I should keep going with the live view approach, which is "good enough" for the limited audience my project (me) for now. Or if I should change to the wasm based front end, which I suspect might be more future proof.
I think the live views may require more changes to keep up with dioxus developments.
But before I even considered changing to wasm, I just wanted to document my experiences to this point. Which I have done here.
Beta Was this translation helpful? Give feedback.
All reactions