yew-router could not deserialize state string when state is () when pressing back in browser

Created on 27 Apr 2020  路  1Comment  路  Source: yewstack/yew

Problem
I'm using yew-router with a STATE = (), and when I click back in the browser history I get this error message in my console log:

yew-router/src/service.rs:115 
Could not deserialize state string

Steps To Reproduce
Happy to produce a minimal example if required.
I'm getting this problem with this version of the project I'm working on https://github.com/kellpossible/coster/tree/b3166d34cdafc88c40bfd2407be781fe991ca818

  1. It just requires wasm-pack to be installed, then it should run with cargo run.
  2. Open browser to localhost:8080
  3. Click on the New Tab button
  4. Click back in the browser
  5. Observe the error message in the log

Expected behavior
No error message

Environment:

  • Yew version master
  • Rust version 1.43.0
  • Target if relevant wasm32-unknown-unknown
  • web-sys version 0.3.37
  • OS: linux
  • Browser Chromium 81.0.4044.113 (Official Build) Arch Linux (64-bit) and Firefox 75.0 (64-bit)

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [x] I don't have time to fix this right now, but maybe later

I'm interested in fixing this, but I'd like to do it a bit later after I understand the yew-router system a bit better. There's always a chance that I'm using it in the wrong way.

bug router

Most helpful comment

This is an implementation oversight that I made and haven't gotten around to fixing. Its because serde can't deserialize a string into (). Instead, an Empty or Empty{} struct could be created to be used instead of (), which should be able to be deserialized from "{}".
There might be some edge cases for this - like if it would properly deserialize an empty string as well. The Empty struct would have to have a custom Deserialize implemented for it to handle these edge cases.

>All comments

This is an implementation oversight that I made and haven't gotten around to fixing. Its because serde can't deserialize a string into (). Instead, an Empty or Empty{} struct could be created to be used instead of (), which should be able to be deserialized from "{}".
There might be some edge cases for this - like if it would properly deserialize an empty string as well. The Empty struct would have to have a custom Deserialize implemented for it to handle these edge cases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sackery picture sackery  路  3Comments

thienpow picture thienpow  路  3Comments

jstarry picture jstarry  路  4Comments

zethra picture zethra  路  5Comments

kellytk picture kellytk  路  4Comments