Skip to content

Conversation

@marc2332
Copy link
Owner

Based off #44
Closes #45

@niclashoyer
Copy link

@marc2332 just had a go with this, but the use_server_query somehow never returns (just keeps blocking while page loading).

@marc2332
Copy link
Owner Author

@marc2332 just had a go with this, but the use_server_query somehow never returns (just keeps blocking while page loading).

So, in other words the suspense does not get "resolved" in the server side? Can you share how you call use_server_query?

@niclashoyer
Copy link

niclashoyer commented Jul 26, 2025

I don't have a minimal example (yet), but I call it something like this:

#[component]
fn Foobar(id: ReadOnlySignal<Uuid>) -> Element {
    let foobar_query = use_server_query(Query::new(id(), GetFoobar())).suspend()?;
    // …
}

#[derive(Clone, PartialEq, Hash, Eq)]
struct GetFoobar();

impl QueryCapability for GetFoobar {
    type Ok = String;
    type Err = String;
    type Keys = Uuid;

    async fn run(&self, id: &Self::Keys) -> Result<Self::Ok, Self::Err> {
        let foobar = load_foobar(id).await; // this calls the server function

        Ok(foobar)
    }
}

@marc2332
Copy link
Owner Author

I don't have a minimal example (yet), but I call it something like this:

#[component]
fn Foobar(id: ReadOnlySignal<Uuid>) -> Element {
    let foobar_query = use_server_query(Query::new(id(), GetFoobar())).suspend()?;
    // …
}

#[derive(Clone, PartialEq, Hash, Eq)]
struct GetFoobar();

impl QueryCapability for GetFoobar {
    type Ok = String;
    type Err = String;
    type Keys = Uuid;

    async fn run(&self, id: &Self::Keys) -> Result<Self::Ok, Self::Err> {
        let foobar = load_foobar(id).await; // this calls the server function

        Ok(foobar)
    }
}

Can you try with the last commit I pushed?

@marc2332 marc2332 requested a review from Copilot July 26, 2025 22:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces experimental dioxus fullstack support to the query library, enabling server-side query caching and serialization between client and server. It adds new features for web and server environments that allow queries to be executed and cached on the server, then serialized and sent to the client.

  • Adds optional fullstack dependencies and feature flags for web/server builds
  • Implements server-side query storage and serialization using dioxus-fullstack-protocol
  • Introduces use_server_query hook for fullstack query execution

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/query.rs Adds fullstack query functionality with server-side caching and new use_server_query hook
Cargo.toml Adds optional fullstack dependencies and feature flags
rust-toolchain.toml Pins Rust version to 1.88.0
.vscode/settings.json Configures VS Code to use both server and web features
Comments suppressed due to low confidence (4)

src/query.rs:260

  • [nitpick] The method name insert_or_get_server_query is ambiguous about what makes it different from the existing insert_or_get_query method. Consider renaming to insert_or_get_fullstack_query or insert_or_get_serializable_query to better reflect its purpose.
    fn insert_or_get_server_query(&mut self, query: Query<Q>) -> QueryData<Q>

src/query.rs:504

  • [nitpick] The method name run_server_queries is inconsistent with the existing run_queries method and doesn't clearly indicate the difference. Consider renaming to run_fullstack_queries or run_serializable_queries to match the naming pattern.
    async fn run_server_queries(queries: &[(&Query<Q>, &QueryData<Q>)])

src/query.rs:895

  • [nitpick] The function name use_server_query suggests it only works on the server, but it's actually for fullstack usage (both web and server). Consider renaming to use_fullstack_query to better reflect its purpose.
pub fn use_server_query<Q: QueryCapability>(query: Query<Q>) -> UseQuery<Q>

rust-toolchain.toml:2

  • Rust version 1.88.0 does not exist. The latest stable Rust version as of my knowledge cutoff was 1.83. Please verify and use a valid Rust version.
channel = "1.88.0"


// Cache the data if on the server
#[cfg(feature = "server")]
if let Some(storage_entry) = query_data.storage_entry.borrow_mut().take() {
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The take() operation removes the storage entry permanently, which means subsequent query runs won't be able to cache data. Consider using as_ref() or cloning the entry instead of taking ownership.

Suggested change
if let Some(storage_entry) = query_data.storage_entry.borrow_mut().take() {
if let Some(storage_entry) = query_data.storage_entry.borrow().as_ref() {

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, its fine to take it as this will only run once, plus I need the owned version in order to call the insert thingy

@niclashoyer
Copy link

niclashoyer commented Jul 26, 2025

@marc2332 behaviour did not change for ssr, it seems to not resolve at all. While I don't really need ssr, fullstack is just so convenient,

@Distortedlogic
Copy link

id like to see server functions n hydration supported :(

Base automatically changed from feat/dioxus-0.7 to main December 6, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants