data-active and aria-current are not server-rendered on plain anchors
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/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ệ
- typescript
- Lĩnh vực
- full-stack
Hướng nghiên cứu
Start in src/routers/factory.tsx at the isServer guard around setupLinkClaims, then read src/utils.ts matchLink and managedPath to see what a server-side computation would need (request path, query, base instead of document.baseURI). Reproduce with a renderToString render at a matching path and confirm the anchor lacks data-active/aria-current. Done means the server HTML contains both attributes (never data-pending), verified by an SSR test; the compiler/@solidjs/web hook is the larger follow-on, so scope the router-side change first.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
On next, the link-state attributes that plain anchors get from the router (data-active, aria-current="page") are never in the server-rendered HTML. They only appear after the client router hydrates.
setupLinkClaims only runs inside if (!isServer) in src/routers/factory.tsx, and in the server build of @solidjs/web, registerElementClaim() does nothing. That means:
- Navigation styled with
a[data-active]ora[aria-current="page"]shows no active link until hydration finishes, and the highlight then appears late. This is easy to see on slow connections or long streamed pages. - Pages that never hydrate (
noScriptsor HTML-only routes) never get active state. They also never getaria-current="page", so screen readers are not told which link is the current page.
Your Example Website or App
The minimal code is below. No hosted repro is needed because the behavior shows up in any renderToString output.
Steps to Reproduce the Bug or Issue
- Render a router app on the server at
/about, with a plain<a href="/about">About</a>in a layout. - Look at the HTML response.
- The anchor is
<a href="/about">About</a>, with nodata-activeand noaria-current.
Expected behavior
The server HTML contains <a href="/about" data-active aria-current="page">About</a>, so the first paint already matches what the client will apply. data-pending would always be absent on the server.
Platform
@solidjs/router2.0.0-next.35 (origin/nextat 7c24cf1)@solidjs/webandsolid-js2.0.0-rc.11- Not specific to any OS or browser
Additional context
The router side looks small, because matchLink in utils.ts is already a pure function shared with useLinkState. The server knows the request path, query and base, so it could compute the same active and exact result. Only the document.baseURI and window.location.origin checks in managedPath would need a server equivalent that uses the request URL.
The harder part is in the compiler. In SSR output, a static anchor is baked into the template string, so there is no runtime point where anything could add an attribute:
// generate: "ssr"
var _tmpl$ = ["<nav", "><a href=\"/about\">About</a><a", " class=\"x\">Dyn</a>", "</nav>"];
// generate: "dom"
_$claimElement(_el$2); _$claimElement(_el$3); _$claimElement(_el$4);
One possible design:
- In SSR mode, dom-expressions gives every
a[href]an attribute hole, for example_$ssrLinkClaim(href), which returns""ordata-active aria-current="page". The hole must not change hydration keys. @solidjs/webadds a server-side registration hook for that function and calls it fromssrElementfor spread anchors. With nothing registered it returns"", so apps without the router pay only one call per anchor.- The router registers a server handler for each request that calls
matchLink, and honorsexplicitLinksby checking for thelinkattribute.
Hydration should not be affected: Solid does not compare attributes during hydration, and the client claim keeps control of the attributes after the first navigation.
A smaller, router-only alternative is an inline script in the SSR output that marks matching anchors before hydration. That removes the late highlight, but it does not help pages that never load scripts, and those are where the missing aria-current matters most.
- Ngôn ngữ chính
- TypeScript
- Star
- 1.3k
- Fork
- 182
- Merge trung bình
- 15 giờ 56 phút
- Pull request đã merge (30 ngày)
- 44
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 solidjs/solid-router
-
<A> costs ~6us of server CPU per instance during SSR (20x a plain <a>), mostly mergeProps/splitPropsCó thể đã có người làm @birkskyum đã nhận 59 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
solidjs/solid-router#583 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
solidjs/solid-router#569 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
solidjs/solid-router#518 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
solidjs/solid-router#502 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
solidjs/solid-router#482 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid-router
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
answerLoops/answerLoops#345 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
siyuan-note/siyuan#20313 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
LanternOps/breeze#8254 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
gofish-graphics/gofish-graphics#1084 ·
Maintainer thường phản hồi trong vòng 1 ngày