Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

data-active and aria-current are not server-rendered on plain anchors

未关闭
#654 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
full-stack

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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] or a[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 (noScripts or HTML-only routes) never get active state. They also never get aria-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
  1. Render a router app on the server at /about, with a plain <a href="/about">About</a> in a layout.
  2. Look at the HTML response.
  3. The anchor is <a href="/about">About</a>, with no data-active and no aria-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/router 2.0.0-next.35 (origin/next at 7c24cf1)
  • @solidjs/web and solid-js 2.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:

  1. In SSR mode, dom-expressions gives every a[href] an attribute hole, for example _$ssrLinkClaim(href), which returns "" or data-active aria-current="page". The hole must not change hydration keys.
  2. @solidjs/web adds a server-side registration hook for that function and calls it from ssrElement for spread anchors. With nothing registered it returns "", so apps without the router pay only one call per anchor.
  3. The router registers a server handler for each request that calls matchLink, and honors explicitLinks by checking for the link attribute.

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.

主要语言
TypeScript
星标
1.3k
派生
182
平均合并
15 小时 56 分钟
30 天内合并 PR
44

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/solid-router 的其他 Issue

查看 solidjs/solid-router 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。