[BUG] Node server ungracefully crashes when given unparsable json for the state (e.g. http://localhost:3000/__rsc?state=invalid{state)
Describe the bug
When a server request contains a query param which contains a single double quote ("), the server will crash with a JSON parse error.
Edit: As mentioned in https://github.com/Shopify/hydrogen/issues/1863#issuecomment-1201993074 any invalid state given to the __rsc endpoint will cause the node server to ungracefully crash.
To Reproduce Clone and run the following repo: https://github.com/nattyg93/hydrogen-bug-search-param-quote
- Run the server
- Load the homepage
- Click the "Bug Out - step 1" button
- If the server hasn't already crashed at this point - click "Bug Out - step 2" (And then click "Bug Out - step 1" again, but it will have crashed by now)
Additional context
- Hydrogen version: 1.1.0
- Node version: 16.14.0
I've tested with Hydrogen 1.2.0 and this issue is still present.
We're keen to upgrade Hydrogen to benefit from #1830, which is currently doubling the load time of navigating between some of our routes.
@frandiox This looks like it was introduced in #1780
Further to this, any invalid json in the state param will cause the node server to ungracefully crash. For example, if you visit http://localhost:3000/__rsc?state=invalid{state the node server will crash.