framesurge / perseus

A state-driven web development framework for Rust with full support for server-side rendering and static generation.

Home Page:https://framesurge.sh/perseus/en-US

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vectors do not work in `ReactiveState`

dessalines opened this issue · comments

This issue is reporting a bug in the code of Perseus. Details of the scope will be available in issue labels.
The author described their issue as follows:

Vectors do not work with ReactiveState

The steps to reproduce this issue are as follows:

Whenever I set the state after doing an HTTP fetch, it breaks all my input binds, and gives the following error. If I don't set the state from that http fetch, even though I still do the http fetch, it works fine.

If I use a String instead of a Vector<... in the reactive state, it also works fine

An internal error has occurred: 'invalid page/widget state found'.

I have the following state:

#[derive(Serialize, Deserialize, Clone, ReactiveState)]
#[rx(alias = "SearchPageStateRx")]
struct SearchPageState {
  search: String,
  posts: Vec<Post>
}

...

#[engine_only_fn]
async fn get_build_state(
info: StateGeneratorInfo<()>,
) -> Result<SearchPageState, BlamedError<reqwest::Error>> {
  let posts = perseus::utils::cache_fallible_res(... // The result doesn't seem to matter here
...
  Ok(SearchPageState {
    posts, // This gives an error
    posts: Vec::new(), // This doesn't give an error, even tho it still did the http fetch
    search: "".to_string(),
})

A minimum reproducible example is available at .

  • Hydration-related: false
  • The author is willing to attempt a fix: true
Tribble internal data

dHJpYmJsZS1yZXBvcnRlZCxDLWJ1ZyxhdXRob3Itd2lsbGluZy10by1pbXBs

Could you provide an MRE repo so I can test this and debug it further? This certainly sounds like a bug (possibly some client-side state validation logic cropping up on the engine-side...).

Also, where is that error appearing? Are you getting it in the build or in the browser console?

Took me a while to figure it out, because there weren't any good error messages, but this came from a deserialization issue. Turns out one of my struct fields on the server side used usize, but in deserializing, it needed to be u64.

I apologize.

Ah I see! No worries, those kinds of bugs can be very tricky to work with! I'll see if there's a way to improve the error messages though...