messense / leptos_sse

Leptos server signals synced through Server-Sent-Events (SSE)
Other
29 stars 9 forks source link

Patch error when sending Enum-Values #2

Open hirschenberger opened 1 year ago

hirschenberger commented 1 year ago

Hey, an my app I want to use one SSE endpoint to send different signals to my GUI. I use a serializable enum as event-payload.

#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)]
pub enum SseSignal {
    #[default]
    Nop,
    UpdateImage(String),
    AcquisitionProgress {
        sequence: (usize, usize),
        frame: (usize, usize),
    },
}

But when I send different enum values through the same stream, I get a panic from here with the error PatchError.

My assumption is, that this error happens if json_patch tries to patch totally unrelated data. Can we maybe handle the error case and return the new data instead of patching the old?

EDIT: My assumption seems to be true, if I wrap my enum in a struct, it works.

EDIT2: After some investigation, it seems as if the patch fails, because the value of doc is still SseSignal::Nop (the default value) but the patch that should be applied is:

Patch([
  Add(AddOperation { path: "/AcquisitionProgress", value: Object {"frame": Array [Number(1), Number(100)], "sequence": Array [Number(0), Number(2)]} }), 
  Remove(RemoveOperation { path: "/UpdateImage" })
])

So it seems to be a synchronisation error between the two signals.