Open ydirson opened 11 months ago
Same issue here
I just ran curl https://yew.rs/tutorial/data.json
and it returns the JSON for me. It appears you are querying the tutorial home page instead of the data.json file. The home page will of course returns HTML so it can be rendered by the browser
Same issue.
let fetched_videos: Vec<Video> = Request::get("/tutorial/data.json")
.send()
.await
.unwrap()
.json()
.await
.unwrap();
with this code, I ran trunk serve --proxy-backend=https://yew.rs/tutorial
it returns
panicked at src/main.rs:67:22:
called `Result::unwrap()` on an `Err` value: SerdeError(Error("expected value", line: 1, column: 1))
but curl returns fine.
$ curl http://127.0.0.1:8080/tutorial/data.json
[
{
"id": 1,
"title": "Building and breaking things",
"speaker": "John Doe",
"url": "https://youtu.be/PsaFVLr8t4E"
},
{
"id": 2,
"title": "The development process",
"speaker": "Jane Smith",
"url": "https://youtu.be/PsaFVLr8t4E"
},
{
"id": 3,
"title": "The Web 7.0",
"speaker": "Matt Miller",
"url": "https://youtu.be/PsaFVLr8t4E"
},
{
"id": 4,
"title": "Mouseless development",
"speaker": "Tom Jerry",
"url": "https://youtu.be/PsaFVLr8t4E"
}
]
In my case, it turns out browser issue.
chrome Console returns
127.0.0.1/:2 The
integrity
attribute is currently ignored for preload destinations that do not support subresource integrity. See https://crbug.com/981419 for more information
I don't know what that means exactly, but I guess it cannot get data.json correctly and leads 'serde error'.
Safari, Firefox, Edge work fine.
Had the same issue on mac m1 pro, Sonoma 14.3 with 5000 port, swithed to 8000 port and it started working pretty well. So the next step was turn 5000 back, so it continued working well. I think it is may be because of some cache issues because i noticed that first request was a bit longer then next.
Thank you @mDanone, changing ports helped.
The problem I had here, for Firefox at least, is that once the client gets a CORS error Firefox won't allow the request to be retried once the proxy server is up. Even shift-reload doesn't seem to reset things. Easy workaround is to just connect again in a new tab.
Is there some reason yew.rs
doesn't just have a CORS policy that allows access to the data, rather than needing a proxy server?
I'm having the exact same problem (Firefox) - the download isn't data.json
but something that starts out with this:
<!doctype html>
<html lang="en">
<head>
<link rel="modulepreload" href="/yew-app-4e192d3122da419a.js" crossorigin=anonymous integrity="sha384-l37IIPAgQSy/RE9SAaBLuMvkS3VP/bSold2x8DL7dYz+feNCiJ88OiWP/ngSL8PQ">
<link rel="preload" href="/yew-app-4e192d3122da419a_bg.wasm" crossorigin=anonymous integrity="sha384-kIu9dgrSuuD13cwfyhAd/N5XAqSmf54tKzqQpyiZ5X+ixo58PaFULW5G0dUE52gd" as="fetch" type="application/wasm"></head>
<body>
<script type="module" nonce="jr3bgc5cG3jHKCfwSjrq4w==">
import init, * as bindings from '/yew-app-4e192d3122da419a.js';
const wasm = await init('/yew-app-4e192d3122da419a_bg.wasm');
...
Yet, curl http://127.0.0.1:8080/tutorial/data.json
returns the expected JSON doc.
As per the tutorial, I'm running: trunk serve --proxy-backend=https://yew.rs/tutorial
And my fetch code is:
let fetched_videos: Vec<Video> = Request::get("/tutorial/data.json")
.send()
.await
.unwrap()
.json()
.await
.unwrap(); // <<<< PANIC IS HERE
I feel like I'm doing something obviously wrong, but I can't work out what!
Note: opening in a new tab doesn't help, neither does forced refresh, or restarting trunk
.
Interestingly, if I run trunk serve --proxy-backend=https://yew.rs/tutorial --port 8081
(changing the port to 8081), it now works. Huh?
Seems to be indeed a caching issue. Had the same issue in Firefox, first run the Request directly with the CORS issue and after running it with trunk serve --proxy-backend=https://yew.rs/tutorial
it wouldn't load the json data.
But after finding this issue I tried different browsers and a different port and it worked, but it would still not work with a different tab or fresh restart of Firefox.
After clearing all temporary cached site data in Firefox it now works with the default port 8080 as well!
Note: I think I followed the tuto right, but it may well be a user error - what really happens behind my back in
trunk serve --proxy-backend
indeed worries me.Problem In the last step of the tutorial, the
trunk serve
process does report proxying as expected:but the call to
json()
on theResponse
object fails with a parse error, caught byunwrap()
:When querying its
text()
instead I get something looking likedist/index.html
, excep:{{__TRUNK_ADDRESS__}}
expanded56dc19c1d...
hash in them, whereas the one indist
changes on every rebuildwhen my
index.html
reads:curl http://127.0.0.1:8080/tutorial/data.json
does dump me the expected JSON (and I also tried to add an intermediate tutorial step just for decoding, see repo, but I'm not pleased with how it diverges too much to be useful)Steps To Reproduce
I uploaded my steps to https://github.com/ydirson/test-yew-tutorial
Steps to reproduce the behavior:
.json().unwrap()
failDBG
to see thetext()
dumpEnvironment:
Yew version:
Rust version: 1.74.0
Target:
wasm32-unknown-unknown
Build tool, if relevant:
trunk
OS, if relevant: Linux (Debian 12, amd64)
Browser and version: Firefox 115.5.0esr
Questionnaire