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

Aperta
#11,046 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@effect-bot ci sta già lavorando.

Dal 28/11/2026.

  • #629 di @effect-bot — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

[!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.

Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
21h 22m
PR unite (30g)
486

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.