JSON-LD script ends up twice in the page after a hydration error
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
Hướng nghiên cứu
Start with clearHostContainer and compare its script handling with React's clearContainerSparingly. Reproduce the hydration mismatch using the issue's example, then inspect tests/hydration-recovery-structured-data.test.tsx. Done when recovery leaves one application/ld+json script while preserving other scripts.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
(react issue - redact also concerned. I'm not sure sure if react realted issues should be published here, if not feel free to close it )
Google Search Console started flagging pages of our site with "Review has multiple aggregate ratings". The HTML we send has a single JSON-LD block. The second one only appears once redact runs in the browser, which is the version Google indexes.
Our language switcher shows locale names with Intl.DisplayNames. The server runs on Bun (but same on Node), whose ICU data doesn't format them like Chrome does: "Русский" on the server, "русский" in the browser. That's enough for hydration to fail. The switcher lives in the root shell, outside any Suspense boundary, so redact recovers by client-rendering the whole document.
To do that, clearHostContainer empties <head> and <body> but keeps every <script>. The client render then inserts the JSON-LD script again, and the page ends up with two identical application/ld+json blocks. Google merges them (same @id) and sees two aggregateRatings.
Note that React does exactly the same here, since clearHostContainer mirrors React's clearContainerSparingly. I've reported it there with a fix, so this issue is about keeping redact in line with it:
- React repo issue: https://github.com/react/react/issues/38491
- React repo PR: https://github.com/react/react/pull/38492
Repro
const structuredData = '{"@type":"SoftwareApplication","@id":"https://example.com/#app","aggregateRating":{"ratingValue":"4.9","ratingCount":64}}'
const App = ({ label }: { label: string }) => (
<html>
<head>
<title>app</title>
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: structuredData }} />
</head>
<body>
<a href="/ru">{label}</a>
</body>
</html>
)
// server HTML: same tree with label "Русский"
hydrateRoot(document, <App label="русский" />)
document.querySelectorAll('script[type="application/ld+json"]').length
// redact: 2 (React 19.3.1: 2 as well, until the PR above lands)
// expected: 1
Cause
Scripts are kept during the cleanup so a script that's still being streamed (opened but not closed yet) isn't lost before it runs. JSON-LD never runs, and the client render puts it back right after, so keeping it only creates a duplicate.
Fix: https://github.com/aymericzip/redact/commit/c6624f9
It removes application/ld+json scripts in clearHostContainer and keeps every other script, <style> and stylesheet <link> as before. It comes with a test in tests/hydration-recovery-structured-data.test.tsx, which fails on main and passes with the fix.
- Ngôn ngữ chính
- TypeScript
- Star
- 640
- Fork
- 32
- Merge trung bình
- 1 giờ 15 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/redact
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
TanStack/redact#195 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TanStack/redact#142 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/redact
Issue tương tự
-
bug data-types
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: middleware enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
agent/quality testing
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
Maintainer thường phản hồi trong vòng 1 ngày
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
juspay/agent-distro#203 ·
Maintainer thường phản hồi trong vòng 1 ngày