`@effect/ui` (Effect-TS/ui): `HtmlServer` writes no attribute for `.prop("hidden", true)` and other reflected properties, so hidden content shows until hydration
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
[!NOTE]
Please note that Claude Opus 5.5 at high effort assisted the author in preparing this content.
What version of Effect is running?
| Package | Version | Commit |
|---|---|---|
@effect/ui (Effect-TS/ui) |
0.0.0 (unreleased) | dec1ca9 |
effect |
4.1.6 |
What steps can reproduce the bug?
TL;DR: HtmlServer writes no attribute for a property such as .prop("hidden", true) on a built-in element, and hydration drops some reflected attributes too, so one table of the HTML standard's reflected properties, shared by the server and hydration, should make both produce what the browser host builds.
The browser host writes .prop(name, value) as element[name] = value, and for most properties of built-in elements the browser reflects that into a content attribute, so a mounted page has hidden, inert, title, tabindex or class. The server writes only value, checked, selected and open. Content hidden with .prop("hidden", true) therefore shows from first paint until hydration, and for good if the script never runs, while .attr("hidden", "").prop("hidden", false) does the reverse and serves hidden content the client shows. Controls disabled or made read-only through .prop are served enabled and editable, and crawlers and readers without JavaScript get a different page. After hydration, className, htmlFor and tabIndex: -1 also leave the element without the attribute a fresh mount has. Related work in the repository includes:
- Effect-TS/effect#11040: the same
.prop("hidden", true)reachesHtmlLocatorrole queries onTestHostand scene trees, through a separate cause in the testing helpers. - Effect-TS/ui#277: the server already treats the
href,src,action,formActionanddataproperties as reflected, removing their attribute for a blocked URL, but writes nothing for any other value.
Save this as packages/ui/test/html/ServerProperty.test.ts in Effect-TS/ui and run pnpm vitest run packages/ui/test/html/ServerProperty.test.ts --silent=false:
// @vitest-environment happy-dom
import { Html, HtmlHydrate, HtmlServer } from "@effect/ui/html"
import * as BrowserHost from "@effect/ui/html/BrowserHost"
import { it } from "@effect/vitest"
import { Effect, Schema } from "effect"
const views = {
hidden: (h: Html.Tags<never>) => h.div.prop("hidden", true).children("Secret"),
shown: (h: Html.Tags<never>) => h.div.attr("hidden", "").prop("hidden", false).children("Shown"),
title: (h: Html.Tags<never>) => h.div.prop("title", "Tip"),
tabIndex: (h: Html.Tags<never>) => h.div.prop("tabIndex", -1),
className: (h: Html.Tags<never>) => h.div.prop("className", "note")
}
const attributes = (app: Element) =>
app.firstElementChild!.getAttributeNames()
.map((name) => `${name}="${app.firstElementChild!.getAttribute(name)}"`).join(" ")
const container = (html: string) =>
Effect.acquireRelease(
Effect.sync(() => {
const app = document.body.appendChild(document.createElement("div"))
app.innerHTML = html
return app
}),
(app) => Effect.sync(() => app.remove())
)
it.effect("server, hydrated and mounted attributes", () =>
Effect.gen(function*() {
for (const [label, view] of Object.entries(views)) {
const page = Html.component({ name: "Page", model: Schema.Null, message: Schema.Never })
.make({ init: () => null, update: ($) => $.model, view })
const { html, state } = yield* HtmlServer.renderToHtml(page, {})
const served = yield* container(html)
const server = attributes(served)
yield* HtmlHydrate.hydrateEffect(page, {}, served, state)
const mounted = yield* container("")
yield* BrowserHost.mountEffect(page, {}, mounted, { key: "mounted" })
console.log(
`${label}: server [${server}], hydrated [${attributes(served)}], ` +
`mounted [${attributes(mounted)}]`
)
}
}).pipe(Effect.scoped))
What is the expected behavior?
The server's HTML, and the element after hydration, have the attributes of the browser host's own mount:
hidden: server [hidden=""], hydrated [hidden=""], mounted [hidden=""]
shown: server [], hydrated [], mounted []
title: server [title="Tip"], hydrated [title="Tip"], mounted [title="Tip"]
tabIndex: server [tabindex="-1"], hydrated [tabindex="-1"], mounted [tabindex="-1"]
className: server [class="note"], hydrated [class="note"], mounted [class="note"]
The HTML standard reflects these IDL attributes into content attributes, so setting the property sets the attribute. The hidden setter removes the attribute for false, "", null, 0 and NaN, writes hidden="until-found" for "until-found", and hidden="" for any other value.
What do you see instead?
hidden: server [], hydrated [hidden=""], mounted [hidden=""]
shown: server [hidden=""], hydrated [], mounted []
title: server [], hydrated [title="Tip"], mounted [title="Tip"]
tabIndex: server [], hydrated [], mounted [tabindex="-1"]
className: server [], hydrated [], mounted [class="note"]
The server leaves out each property's attribute and keeps the hidden attribute the property removes. After hydration, tabIndex and className have no attribute at all, and neither does htmlFor on a label, unlike a fresh mount. inert, disabled and readOnly behave like hidden and title.
Additional information
Root cause. The HTML renderer has no mapping from a property of a built-in element to the content attribute it reflects, while the browser host writes the property and lets the browser reflect it:
- The server's
elementAttributeswrites the controlledvalue,checked,selectedandopenand, for any other property, only removes a blocked URL's attribute, leaving the rest to the client's adoption. - Hydration's
setProprecords a property's served attribute asname.toLowerCase()(classname,htmlfor) and skips a property whose getter already equals the value (adiv'stabIndexis-1). When it finishes the element, it removes the served attributes it didn't record,classandforamong them, although the property has just written them.
Proposed resolution. Give the HTML renderer one table of the properties of built-in elements that reflect a content attribute, following the HTML standard's reflection rules: for each property, its attribute name (tabIndex → tabindex, className → class, htmlFor → for, readOnly → readonly) and its kind (boolean, string, integer, enumerated, URL, or the hidden setter's own rule). The server writes each property in the table as the attribute its setter sets, after the element's attributes so that the property wins, as it does in the browser, where attributes are written first; URL properties keep the blocked-URL check. Hydration records the table's attribute name and compares the served attribute rather than the property, so it keeps and writes what a fresh mount has. Both sides need the table: with the server alone, hydration would still remove a served class written from className.
- Server HTML matches the browser host's DOM for reflected properties, so content hidden with
.prop("hidden", true)is hidden from first paint and without JavaScript. The public API doesn't change. - Properties without a content attribute, such as
indeterminate,scrollTopor event handler properties likeonclick, stay client-only, as a modal dialog and an open popover already are. The table is an allow-list, so no such value is ever serialized. The docs ofpropwould say which properties the server renders. - Server HTML and hydration snapshots change for elements with such properties.
Nothing needs to be settled before the fix; when and how it lands is for the maintainers to decide.
- 主要言語
- TypeScript
- スター
- 16.7k
- フォーク
- 808
- 平均マージ
- 21時間 22分
- マージ済み PR(30日)
- 486
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Effect-TS/effect のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
`@effect/ui-native` (Effect-TS/ui): `kit/VirtualList` `list` part widens `R` to `any`, poisoning enclosing components対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#11097 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`@effect/ui-native` (Effect-TS/ui): Controlled `input` rejected-edit restore never calls `host.commit()`対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#11096 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
Effect-TS/effect の issue をすべて見る
似ている issue
-
check:failed streams:edit
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
iptv-org/iptv#60585 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: Critical path skips a child span that ends exactly when the next one starts対応中かも @Piyush4801 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jaegertracing/jaeger-ui#4865 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
anthropics/claude-code#112972 ·
-
Type: Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信