`@effect/ui` (Effect-TS/ui): `HtmlServer` writes no attribute for `.prop("hidden", true)` and other reflected properties, so hidden content shows until hydration

オープン
#11,046 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@effect-bot がすでに取り組んでいます。

2026年11月28日 から。

  • #629 @effect-bot による — オープン

評価

この 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) reaches HtmlLocator role queries on TestHost and scene trees, through a separate cause in the testing helpers.
  • Effect-TS/ui#277: the server already treats the href, src, action, formAction and data properties 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 elementAttributes writes the controlled value, checked, selected and open and, for any other property, only removes a blocked URL's attribute, leaving the rest to the client's adoption.
  • Hydration's setProp records a property's served attribute as name.toLowerCase() (classname, htmlfor) and skips a property whose getter already equals the value (a div's tabIndex is -1). When it finishes the element, it removes the served attributes it didn't record, class and for among 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, scrollTop or event handler properties like onclick, 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 of prop would 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。