Skip to content

use_query Doesn't Seem To Resume After Being Re-Rendered With New Input #99

Open
@jsievenpiper

Description

@jsievenpiper

I think this may be similar to #78 but I'm not entirely sure... sorry in advance if it is.

I have a simple reproducible scenario where I call a component that is designed to be frequently re-rendered with new props. Those props get fed into a query which goes off and does it's thing. On initial render, the component works great. If I completely unmount the component (via some intermediate state or something), and then render it again with new props, it also works great. But if I try to directly transition it from one state to another, it gets stuck in suspension.

I thought this might originally be an issue following the rules of hooks, but even this simple test scenario seems to break (I've also included a simple use of stylist here to highlight a typical component setup I'd be using, if it gives any more context, but just a plain use of use_query seems to break). A stripped-down example component looks like this:

use bounce::query::use_query;
use stylist::yew::{styled_component, use_style};
use uuid::Uuid;
use yew::prelude::*;

#[derive(Debug, PartialEq)
struct Response {
  value: String
}

#[derive(Properties, PartialEq)]
pub struct Props {
  pub id: Uuid
}

#[styled_component(Item)]
pub fn item(props: &Props) -> HtmlResult {
  let style = use_style!(r#"
    display: block;
  "#);

  let data = use_query::<Response>(props.id.clone().into())?;
  let value: AttrValue = data.value.clone().into();

  Ok(
    let data = data.as_ref().ok().unwrap();
    html! { <div class={style}>{value}</div> }
  )
}

For whatever it's worth:

  • use_query_value works perfectly with a component that is otherwise exactly the same (e.g. just changing HtmlResult to Html and doing the bare minimum changes to call sites impacted inside).
  • The hook seems to be invoked, but the query function itself doesn't seem to be invoked.

Thanks in advance for this amazing (set) of libraries -- if there is anything I can do to help patch this or look deeper, happy to lend a hand! Actually, if I find I'm using this appropriately (or am taught how to!), I'd be more than happy to write up some documentation for the book 👍🏾

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions