Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Japanese text misrenders in JSON without charset on Safari/WebKit #3865

Open
s7tya opened this issue Jan 29, 2025 · 3 comments
Open

Japanese text misrenders in JSON without charset on Safari/WebKit #3865

s7tya opened this issue Jan 29, 2025 · 3 comments
Labels

Comments

@s7tya
Copy link

s7tya commented Jan 29, 2025

What version of Hono are you using?

4.6.19

What runtime/platform is your app running on? (with version if possible)

deno 2.1.7

What steps can reproduce the bug?

Because the charset parameter was removed in #3743, the Japanese text in the JSON response no longer displays correctly in Safari.

import { Hono } from "jsr:@hono/[email protected]";

const app = new Hono();

app.get("/", (c) => {
  return c.json({ "message": "日本語テキスト" });
});

Deno.serve(app.fetch);

If you revert the version from 4.6.19 to 4.6.13, which isn’t affected by that change, the text displays correctly.

What is the expected behavior?

Image

What do you see instead?

Image

Additional information

This issue is caused by the known WebKit bug described here:
https://bugs.webkit.org/show_bug.cgi?id=197369
It has existed since 2019 and still hasn’t been fixed.

@s7tya s7tya added the triage label Jan 29, 2025
@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jan 29, 2025

Thanks for the report.
This is a webkit's bug and there is nothing we can do about it! (for web standards)

But, we do have a solution (or workaround).

import { Hono } from 'hono'

const app = new Hono()

app.use(async (c, next) => {
  await next();
  if (c.finalized && c.res.headers.get("Content-Type") === "application/json") {
    c.res.headers.set("Content-Type", "application/json; charset=utf-8")
  }
})
  
app.get('/hello', (c) => {
  const name = c.req.query('name')
  return c.json(`${name} いず くーる!`)
})

export default app

@s7tya
Copy link
Author

s7tya commented Jan 29, 2025

That workaround worked successfully. Thank you very much. I understand that this bug is in WebKit, but I believe it could be problematic if simply updating the patch version of hono ends up breaking the display for many users.

@yusukebe yusukebe added not bug and removed triage labels Jan 31, 2025
@yusukebe
Copy link
Member

Hi @s7tya

Thank you for the issue. I didn't realize that problem. But as you said, this is not a Hono-side bug.

but I believe it could be problematic if simply updating the patch version of hono ends up breaking the display for many users.

Indeed. But now, I can't decide whether we should revert #3743 or not. For now, I label this as not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants