Skip to content

Write a value in JSX as itself, kept current by Solid - #12

Closed
zaiev wants to merge 3 commits into
mainfrom
write-a-value-in-jsx-as-itself-kept-current-by-solid
Closed

zaiev wants to merge 3 commits into
mainfrom
write-a-value-in-jsx-as-itself-kept-current-by-solid

Conversation

@zaiev

@zaiev zaiev commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Why

A value that changes was given in JSX as a thunk the caller wrote, title=(fun () -> S.get note), and a name could mean a value or, given to an optional prop, an accessor: the same value had more than one form, and fun () -> meant a thunk in JSX, so a callback that takes nothing was written fun _ ->. What JSX holds was two types, Jsx.element and Jsx.content, which Solid does not tell apart, and an accessor was its representation, so an error printed Melange's (unit -> string [@u]).

A value in JSX is now written as itself and Solid keeps it current: a literal or a name is given as it is, any other expression is read again as what it reads changes, as Solid's compiler makes an expression in JSX a getter, and a function is a function. Evaluation follows JSX's form, as the body of let%map follows its own in OCaml's reactive libraries; outside JSX a thunk is still written, fun () -> e, as Solid's own API takes () => e. Keeping the caller's thunk was weighed: it shows the deferral where it is written, but it gives a constant two forms, by name or computed, which no syntactic ppx can unify.

Continues #11, closed when its branch was renamed to this title.

Changes

  • Breaking: a thunk written in JSX is refused by its type, a function where a value belongs; title=(fun () -> S.get note) is title=(S.get note), a child (fun () -> Jsx.int (S.get count)) is (Jsx.int (S.get count)), ?hidden=(Jsx.attr (fun () -> o)) is ?hidden=(Jsx.attr o).
  • Breaking: ?title=note, which 0.10.0 took for an accessor of an option, is an option given as it is; a signal or a prop is ?title=(S.get note).
  • Breaking: what JSX holds is one type, Jsx.element, as Solid's JSX.Element is; Jsx.content is Jsx.element, and Jsx.element x and Jsx.of_content x are x. A child given by its name takes an element, let icon = <Icon /> in <button>icon "Save"</button>.
  • Breaking: Solid.accessor is abstract, so an error names it, string Solidtype.Solid.accessor; an accessor is made by S.accessor (fun () -> e).
  • Breaking: Check.nodes is Check.elements, and the children kind `nodes is `elements.
  • A function prop that takes nothing is (fun () -> ...).
  • A Switch takes a match as its child, with no thunk around it, its cases JSX or not.
  • A component's function child is typed after its props, so <Show.Some some=(S.get item)>(fun i -> ...)</Show.Some> takes i's type from some.
  • An error on a component's children points at the children and names the kinds the component takes.
  • Released as 0.11.0, with Give an optional prop one way, and a function child one way #10, so an application upgrades once: the install page names 0.11.0's plugin.

Verified

  • make test: dune's tests, the plugin's and vitest's 965, hydration and Astro's prerender among them; make lint, every generator's --check among it; make docs with no warning.
  • Every JSX value and child in the repository rewritten from MLX's parse rather than by text: 5,344 thunks, 256 conversions a child no longer needs and 72 conversion calls, then each refusal the compiler gave read and fixed by hand.
  • test/does_not_compile.t lists each position -- attribute, optional prop, component prop, data_, namespaced, as_, child, Switch case, function child -- with every form that compiles and a thunk refused in each; no error in it shows [@u] or a name of the ppx's.
  • An independent review of the diff against Hypha's rules and AGENTS.md; each finding fixed, with a test where one was missing.

A value that changes was given in JSX as a thunk the caller wrote,
title=(fun () -> S.get note), where TSX writes title={note()}: the most
written form in every component was the one furthest from Solid's, and
fun () -> meant a thunk there, so a callback that takes nothing had to
be written fun _ ->. 0.10.0 also took ?title=note for an accessor of an
option, while title=note was a value, two meanings for one form.

The ppx now reads a value as Solid's compiler reads TSX: a literal, a
name, an element and a function are given as they are, and any other
expression is a thunk the ppx writes, read again as what it reads
changes. A function is a function wherever it is given, so a thunk
written in JSX is refused by its type, and there is one form for each
meaning, required or optional, attribute or child. Outside JSX a thunk
is still written, fun () -> e, as TSX writes () => e.

Keeping the caller's thunk was weighed: it shows where a read is
deferred, but every read pays for it, and Solid's own users already
expect JSX to defer. Lowering is unchanged, so Solid's compiler sees
the same JSX it did.
A child given by its name, or a function's result given as one, met two
types for one meaning: Jsx.element and Jsx.content, which Solid does not
tell apart, and a conversion between them that inference could not
always place. What JSX holds is now one type, Jsx.element, as Solid's
JSX.Element is.

An accessor was its representation, so an error printed Melange's
(unit -> string [@U]); it is now an abstract type, named in the error.
A function child is typed after the props it reads, a function written
as a value is refused at the child with the kinds the component takes,
and a Switch case that is not JSX is a child as it is.
@zaiev zaiev closed this Nov 15, 2026
@zaiev
zaiev deleted the write-a-value-in-jsx-as-itself-kept-current-by-solid branch November 15, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant