Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resp.headers.get("content-type")
can returnapplication/json; charset=utf-8
which fails the check.Please see esphome/issues#2183
This could fix: esphome/issues#2183 , esphome/issues#2193
The problem is here,
ports
is not a array but plain text.dashboard/src/api/serial-ports.ts
Line 12 in ed3eed0
Then fetchApi doesn't appear to return a javascript array but regular text.
Which is wierd because this is checked here:
dashboard/src/api/index.ts
Lines 13 to 15 in ed3eed0
This is not a browser cache problem.
/serial-ports
does indeed return a json text, and thecontent-type: application/json; charset=utf-8
header.And that's where it goes wrong.
In my testing,
resp.headers.get("content-type")
returned:application/json; charset=utf-8
which is not the same asapplication/json
.I'm not quite sure where the
charset=utf-8
comes from, but this PR fixes the issue quite easly.Another posibility is to force
resp.json()
wrapped in a try / catch.